mirror of
https://github.com/nikdoof/python-ts3.git
synced 2025-12-17 11:59:27 +00:00
Use bytes for I/O, and encode any text.
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user