Skip to content

Commit

Permalink
Allow configuration of the encoding used in deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejlach committed Jan 12, 2016
1 parent 567b3ac commit b32911b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions qpython/qconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class QConnection(object):
strings are encoded as q strings instead of chars, **Default**: ``False``
'''

def __init__(self, host, port, username = None, password = None, timeout = None, **options):
def __init__(self, host, port, username = None, password = None, timeout = None, encoding = 'latin-1', **options):
self.host = host
self.port = port
self.username = username
Expand All @@ -85,6 +85,8 @@ def __init__(self, host, port, username = None, password = None, timeout = None,

self.timeout = timeout

self._encoding = encoding

self._options = MetaData(**CONVERSION_OPTIONS.union_dict(**options))


Expand Down Expand Up @@ -160,7 +162,7 @@ def is_connected(self):
def _initialize(self):
'''Performs a IPC protocol handshake.'''
credentials = (self.username if self.username else '') + ':' + (self.password if self.password else '')
credentials = credentials.encode('latin-1')
credentials = credentials.encode(self._encoding)
self._connection.send(credentials + b'\3\0')
response = self._connection.recv(1)

Expand Down
5 changes: 3 additions & 2 deletions qpython/qreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def __new__(cls, *args, **kwargs):
return super(QReader, cls).__new__(cls)


def __init__(self, stream):
def __init__(self, stream, encoding = 'latin-1'):
self._stream = stream
self._buffer = QReader.BytesBuffer()
self._encoding = encoding


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

@parse(QCHAR)
def _read_char(self, qtype = QCHAR):
return chr(self._read_atom(QCHAR)).encode('latin-1')
return chr(self._read_atom(QCHAR)).encode(self._encoding)


@parse(QGUID)
Expand Down

0 comments on commit b32911b

Please sign in to comment.