Skip to content

Commit b32911b

Browse files
committed
Allow configuration of the encoding used in deserialization
1 parent 567b3ac commit b32911b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

qpython/qconnection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class QConnection(object):
7474
strings are encoded as q strings instead of chars, **Default**: ``False``
7575
'''
7676

77-
def __init__(self, host, port, username = None, password = None, timeout = None, **options):
77+
def __init__(self, host, port, username = None, password = None, timeout = None, encoding = 'latin-1', **options):
7878
self.host = host
7979
self.port = port
8080
self.username = username
@@ -85,6 +85,8 @@ def __init__(self, host, port, username = None, password = None, timeout = None,
8585

8686
self.timeout = timeout
8787

88+
self._encoding = encoding
89+
8890
self._options = MetaData(**CONVERSION_OPTIONS.union_dict(**options))
8991

9092

@@ -160,7 +162,7 @@ def is_connected(self):
160162
def _initialize(self):
161163
'''Performs a IPC protocol handshake.'''
162164
credentials = (self.username if self.username else '') + ':' + (self.password if self.password else '')
163-
credentials = credentials.encode('latin-1')
165+
credentials = credentials.encode(self._encoding)
164166
self._connection.send(credentials + b'\3\0')
165167
response = self._connection.recv(1)
166168

qpython/qreader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ def __new__(cls, *args, **kwargs):
117117
return super(QReader, cls).__new__(cls)
118118

119119

120-
def __init__(self, stream):
120+
def __init__(self, stream, encoding = 'latin-1'):
121121
self._stream = stream
122122
self._buffer = QReader.BytesBuffer()
123+
self._encoding = encoding
123124

124125

125126
def read(self, source = None, **options):
@@ -256,7 +257,7 @@ def _read_symbol(self, qtype = QSYMBOL):
256257

257258
@parse(QCHAR)
258259
def _read_char(self, qtype = QCHAR):
259-
return chr(self._read_atom(QCHAR)).encode('latin-1')
260+
return chr(self._read_atom(QCHAR)).encode(self._encoding)
260261

261262

262263
@parse(QGUID)

0 commit comments

Comments
 (0)