aboutsummaryrefslogtreecommitdiffstats
path: root/wpaspy/wpaspy.py
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2019-02-02 10:49:23 (GMT)
committerJouni Malinen <j@w1.fi>2019-02-04 10:26:33 (GMT)
commit3a833d95b320861f9f6fc42e4003c7e2aa802d87 (patch)
tree7d23e42f463c5ff75c977b8ced6cfce7b7bb44ed /wpaspy/wpaspy.py
parent04fa9fc7fdc9df7704c775d2ba24a5ba167a1812 (diff)
downloadhostap-3a833d95b320861f9f6fc42e4003c7e2aa802d87.zip
hostap-3a833d95b320861f9f6fc42e4003c7e2aa802d87.tar.gz
hostap-3a833d95b320861f9f6fc42e4003c7e2aa802d87.tar.bz2
wpaspy: Convert to/from str to bytes as needed for python3
The control interface commands use mostly ASCII or UTF-8 strings, so convert input/output to strings/bytes as needed for the socket operations with python3. Signed-off-by: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wpaspy/wpaspy.py')
-rw-r--r--wpaspy/wpaspy.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/wpaspy/wpaspy.py b/wpaspy/wpaspy.py
index 99b565a..89e973b 100644
--- a/wpaspy/wpaspy.py
+++ b/wpaspy/wpaspy.py
@@ -52,7 +52,7 @@ class Ctrl:
break
self.s = socket.socket(af, socktype)
self.s.settimeout(5)
- self.s.sendto("GET_COOKIE", sockaddr)
+ self.s.sendto(b"GET_COOKIE", sockaddr)
reply, server = self.s.recvfrom(4096)
self.cookie = reply
self.port = port
@@ -81,13 +81,24 @@ class Ctrl:
self.started = False
def request(self, cmd, timeout=10):
+ if type(cmd) == str:
+ try:
+ cmd2 = cmd.encode()
+ cmd = cmd2
+ except UnicodeDecodeError as e:
+ pass
if self.udp:
self.s.sendto(self.cookie + cmd, self.sockaddr)
else:
self.s.send(cmd)
[r, w, e] = select.select([self.s], [], [], timeout)
if r:
- return self.s.recv(4096)
+ res = self.s.recv(4096).decode()
+ try:
+ r = str(res)
+ except UnicodeDecodeError as e:
+ r = res
+ return r
raise Exception("Timeout on waiting response")
def attach(self):
@@ -127,5 +138,9 @@ class Ctrl:
return False
def recv(self):
- res = self.s.recv(4096)
- return res
+ res = self.s.recv(4096).decode()
+ try:
+ r = str(res)
+ except UnicodeDecodeError as e:
+ r = res
+ return r