Skip to content

Commit e1e0ccb

Browse files
committed
enable encoding arg
1 parent 9829957 commit e1e0ccb

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

telnetserver/telnetserver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ def __init__(self, socket, address, buffer, lastcheck):
7777
# list of newly-added occurences
7878
_new_events = []
7979

80-
def __init__(self):
80+
def __init__(self, encoding="utf-8"):
8181
"""Constructs the TelnetServer object and starts listening for
8282
new clients.
8383
"""
84-
84+
self.encoding=encoding
8585
self._clients = {}
8686
self._nextid = 0
8787
self._events = []
@@ -196,12 +196,12 @@ def shutdown(self):
196196
def _attempt_send(self, clid, data):
197197
# python 2/3 compatability fix - convert non-unicode string to unicode
198198
if sys.version < '3' and type(data) != unicode:
199-
data = unicode(data, "latin1")
199+
data = unicode(data, self.encoding)
200200
try:
201201
# look up the client in the client map and use 'sendall' to send
202202
# the message string on the socket. 'sendall' ensures that all of
203203
# the data is sent in one go
204-
self._clients[clid].socket.sendall(bytearray(data, "latin1"))
204+
self._clients[clid].socket.sendall(bytearray(data, self.encoding))
205205
# KeyError will be raised if there is no client with the given id in
206206
# the map
207207
except KeyError:
@@ -285,7 +285,7 @@ def _check_for_messages(self):
285285

286286
try:
287287
# read data from the socket, using a max length of 4096
288-
data = cl.socket.recv(4096).decode("latin1")
288+
data = cl.socket.recv(4096).decode(self.encoding)
289289

290290
# process the data, stripping out any special Telnet messages
291291
message = self._process_sent_data(cl, data)

0 commit comments

Comments
 (0)