@@ -62,6 +62,9 @@ class QConnection(object):
6262 - `username` (`string` or `None`) - username for q authentication/authorization
6363 - `password` (`string` or `None`) - password for q authentication/authorization
6464 - `timeout` (`nonnegative float` or `None`) - set a timeout on blocking socket operations
65+ - `encoding` (`string`) - string encoding for data deserialization
66+ - `reader_class` (subclass of `QReader`) - data deserializer
67+ - `writer_class` (subclass of `QWriter`) - data serializer
6568 :Options:
6669 - `raw` (`boolean`) - if ``True`` returns raw data chunk instead of parsed
6770 data, **Default**: ``False``
@@ -74,7 +77,8 @@ class QConnection(object):
7477 strings are encoded as q strings instead of chars, **Default**: ``False``
7578 '''
7679
77- def __init__ (self , host , port , username = None , password = None , timeout = None , encoding = 'latin-1' , ** options ):
80+
81+ def __init__ (self , host , port , username = None , password = None , timeout = None , encoding = 'latin-1' , reader_class = None , writer_class = None , ** options ):
7882 self .host = host
7983 self .port = port
8084 self .username = username
@@ -89,6 +93,20 @@ def __init__(self, host, port, username = None, password = None, timeout = None,
8993
9094 self ._options = MetaData (** CONVERSION_OPTIONS .union_dict (** options ))
9195
96+ try :
97+ from qpython ._pandas import PandasQReader , PandasQWriter
98+ self ._reader_class = PandasQReader
99+ self ._writer_class = PandasQWriter
100+ except ImportError :
101+ self ._reader_class = QReader
102+ self ._writer_class = QWriter
103+
104+ if reader_class :
105+ self ._reader_class = reader_class
106+
107+ if writer_class :
108+ self ._writer_class = writer_class
109+
92110
93111 def __enter__ (self ):
94112 self .open ()
@@ -124,8 +142,8 @@ def open(self):
124142 self ._init_socket ()
125143 self ._initialize ()
126144
127- self ._writer = QWriter (self ._connection , protocol_version = self ._protocol_version )
128- self ._reader = QReader (self ._connection .makefile ('b' ))
145+ self ._writer = self . _writer_class (self ._connection , protocol_version = self ._protocol_version )
146+ self ._reader = self . _reader_class (self ._connection .makefile ('b' ))
129147
130148
131149 def _init_socket (self ):
0 commit comments