Use bytes for I/O, and encode any text.

This commit is contained in:
2014-03-29 00:17:22 +00:00
parent c03dba92e5
commit 25da143c18
2 changed files with 7 additions and 7 deletions

View File

@@ -104,9 +104,9 @@ class TS3Proto():
self._timeout = timeout self._timeout = timeout
self._connected = False self._connected = False
data = self._telnet.read_until("\n\r", self._timeout) data = self._telnet.read_until(b"\n\r", self._timeout)
if data.endswith("TS3\n\r"): if data.endswith(b"TS3\n\r"):
self._connected = True self._connected = True
return self._connected return self._connected
@@ -126,15 +126,15 @@ class TS3Proto():
self.logger.debug("send_command - %s" % commandstr) self.logger.debug("send_command - %s" % commandstr)
with self.io_lock: with self.io_lock:
self._telnet.write("%s\n\r" % commandstr) self._telnet.write(b"%s\n\r" % commandstr.encode('utf-8'))
data = "" data = ''
response = self._telnet.read_until("\n\r", self._timeout) response = self._telnet.read_until(b"\n\r", self._timeout)
if not response.startswith("error"): if not response.startswith("error"):
# what we just got was extra data # what we just got was extra data
data = response data = response
response = self._telnet.read_until("\n\r", self._timeout) response = self._telnet.read_until(b"\n\r", self._timeout)
return TS3Response(response, data) return TS3Response(response, data)

View File

@@ -84,7 +84,7 @@ def dummy_ts3(event, sock):
event.set() event.set()
try: try:
conn, addr = sock.accept() conn, addr = sock.accept()
conn.send('TS3\n\r') conn.send(b"TS3\n\r")
except socket.timeout: except socket.timeout:
pass pass
finally: finally: