1212import msgpack
1313
1414import base64
15- from const import IPROTO_GREETING_SIZE
1615
1716try :
1817 from ctypes import c_ssize_t
5352from tarantool .schema import Schema
5453from tarantool .utils import check_key
5554
56- class Connection (object ):
5755
58- '''\
56+ class Connection (object ):
57+ '''
5958 Represents connection to the Tarantool server.
6059
6160 This class is responsible for connection and network exchange with
@@ -81,7 +80,7 @@ def __init__(self, host, port,
8180 reconnect_max_attempts = RECONNECT_MAX_ATTEMPTS ,
8281 reconnect_delay = RECONNECT_DELAY ,
8382 connect_now = True ):
84- '''\
83+ '''
8584 Initialize a connection to the server.
8685
8786 :param str host: Server hostname or IP-address
@@ -104,16 +103,15 @@ def __init__(self, host, port,
104103 if connect_now :
105104 self .connect ()
106105
107-
108106 def close (self ):
109- '''\
107+ '''
110108 Close connection to the server
111109 '''
112110 self ._socket .close ()
113111 self ._socket = None
114112
115113 def connect_basic (self ):
116- '''\
114+ '''
117115 Create connection to the host and port specified in __init__().
118116 :raise: `NetworkError`
119117 '''
@@ -136,7 +134,7 @@ def handshake(self):
136134 self .authenticate (self .user , self .password )
137135
138136 def connect (self ):
139- '''\
137+ '''
140138 Create connection to the host and port specified in __init__().
141139 Usually there is no need to call this method directly,
142140 since it is called when you create an `Connection` instance.
@@ -161,7 +159,7 @@ def _recv(self, to_read):
161159 tmp = self ._socket .recv (to_read )
162160 if not tmp :
163161 raise NetworkError (socket .error (errno .ECONNRESET ,
164- "Lost connection to server during query" ))
162+ "Lost connection to server during query" ))
165163 to_read -= len (tmp )
166164 buf += tmp
167165 return buf
@@ -179,7 +177,7 @@ def _read_response(self):
179177 return self ._recv (length )
180178
181179 def _send_request_wo_reconnect (self , request ):
182- '''\
180+ '''
183181 :rtype: `Response` instance
184182
185183 :raise: NetworkError
@@ -200,7 +198,7 @@ def _send_request_wo_reconnect(self, request):
200198 raise DatabaseError (response .return_code , response .return_message )
201199
202200 def _opt_reconnect (self ):
203- '''\
201+ '''
204202 Check that connection is alive using low-level recv from libc(ctypes)
205203 **Due to bug in python - timeout is internal python construction.
206204 '''
@@ -210,7 +208,7 @@ def _opt_reconnect(self):
210208 def check (): # Check that connection is alive
211209 buf = ctypes .create_string_buffer (2 )
212210 self ._sys_recv (self ._socket .fileno (), buf , 1 ,
213- socket .MSG_DONTWAIT | socket .MSG_PEEK )
211+ socket .MSG_DONTWAIT | socket .MSG_PEEK )
214212 if ctypes .get_errno () == errno .EAGAIN :
215213 ctypes .set_errno (0 )
216214 return errno .EAGAIN
@@ -234,7 +232,8 @@ def check(): # Check that connection is alive
234232 warn ("Reconnect attempt %d of %d" %
235233 (attempt , self .reconnect_max_attempts ), NetworkWarning )
236234 if attempt == self .reconnect_max_attempts :
237- raise NetworkError (socket .error (last_errno , errno .errorcode [last_errno ]))
235+ raise NetworkError (
236+ socket .error (last_errno , errno .errorcode [last_errno ]))
238237 attempt += 1
239238
240239 self .handshake ()
@@ -245,7 +244,7 @@ def check(): # Check that connection is alive
245244 self ._socket .settimeout (self .socket_timeout )
246245
247246 def _send_request (self , request ):
248- '''\
247+ '''
249248 Send the request to the server through the socket.
250249 Return an instance of `Response` class.
251250
@@ -266,7 +265,7 @@ def flush_schema(self):
266265 self .schema .flush ()
267266
268267 def call (self , func_name , * args ):
269- '''\
268+ '''
270269 Execute CALL request. Call stored Lua function.
271270
272271 :param func_name: stored Lua function name
@@ -287,7 +286,7 @@ def call(self, func_name, *args):
287286 return response
288287
289288 def eval (self , expr , * args ):
290- '''\
289+ '''
291290 Execute EVAL request. Eval Lua expression.
292291
293292 :param expr: Lua expression
@@ -307,7 +306,6 @@ def eval(self, expr, *args):
307306 response = self ._send_request (request )
308307 return response
309308
310-
311309 def replace (self , space_name , values ):
312310 '''
313311 Execute REPLACE request.
@@ -327,12 +325,12 @@ def replace(self, space_name, values):
327325 return self ._send_request (request )
328326
329327 def authenticate (self , user , password ):
330- self .user = user ;
328+ self .user = user
331329 self .password = password
332330 if not self ._socket :
333331 return self ._opt_reconnect ()
334332
335- request = RequestAuthenticate (self , self ._salt , self .user , \
333+ request = RequestAuthenticate (self , self ._salt , self .user ,
336334 self .password )
337335 return self ._send_request_wo_reconnect (request )
338336
@@ -341,21 +339,21 @@ def join(self, server_uuid):
341339 resp = self ._send_request (request )
342340 while True :
343341 yield resp
344- if resp .code == REQUEST_TYPE_OK or \
345- resp .code >= REQUEST_TYPE_ERROR :
342+ if resp .code == REQUEST_TYPE_OK or resp .code >= REQUEST_TYPE_ERROR :
346343 return
347344 resp = Response (self , self ._read_response ())
348- self .close () # close connection after JOIN
345+ self .close () # close connection after JOIN
349346
350- def subscribe (self , cluster_uuid , server_uuid , vclock = {}):
347+ def subscribe (self , cluster_uuid , server_uuid , vclock = {}):
348+ # FIXME rudnyh: ^ 'vclock={}'? really? sure?
351349 request = RequestSubscribe (self , cluster_uuid , server_uuid , vclock )
352350 resp = self ._send_request (request )
353351 while True :
354352 yield resp
355353 if resp .code >= REQUEST_TYPE_ERROR :
356354 return
357355 resp = Response (self , self ._read_response ())
358- self .close () # close connection after SUBSCRIBE
356+ self .close () # close connection after SUBSCRIBE
359357
360358 def insert (self , space_name , values ):
361359 '''
@@ -376,7 +374,7 @@ def insert(self, space_name, values):
376374 return self ._send_request (request )
377375
378376 def delete (self , space_name , key , ** kwargs ):
379- '''\
377+ '''
380378 Execute DELETE request.
381379 Delete single record identified by `key` (using primary index).
382380
@@ -398,7 +396,7 @@ def delete(self, space_name, key, **kwargs):
398396 return self ._send_request (request )
399397
400398 def update (self , space_name , key , op_list , ** kwargs ):
401- '''\
399+ '''
402400 Execute UPDATE request.
403401 Update single record identified by `key` (using primary index).
404402
@@ -428,7 +426,7 @@ def update(self, space_name, key, op_list, **kwargs):
428426 return self ._send_request (request )
429427
430428 def ping (self , notime = False ):
431- '''\
429+ '''
432430 Execute PING request.
433431 Send empty request and receive empty response from server.
434432
@@ -438,15 +436,15 @@ def ping(self, notime=False):
438436
439437 request = RequestPing (self )
440438 t0 = time .time ()
441- response = self ._send_request (request )
439+ self ._send_request (request )
442440 t1 = time .time ()
443441
444442 if notime :
445443 return "Success"
446444 return t1 - t0
447445
448446 def select (self , space_name , key = None , ** kwargs ):
449- '''\
447+ '''
450448 Execute SELECT request.
451449 Select and retrieve data from the database.
452450
@@ -500,13 +498,13 @@ def select(self, space_name, key=None, **kwargs):
500498 space_name = self .schema .get_space (space_name ).sid
501499 if isinstance (index_name , basestring ):
502500 index_name = self .schema .get_index (space_name , index_name ).iid
503- request = RequestSelect (
504- self , space_name , index_name , key , offset , limit , iterator_type )
501+ request = RequestSelect (self , space_name , index_name , key , offset ,
502+ limit , iterator_type )
505503 response = self ._send_request (request )
506504 return response
507505
508506 def space (self , space_name ):
509- '''\
507+ '''
510508 Create `Space` instance for particular space
511509
512510 `Space` instance encapsulates the identifier of the space and provides
0 commit comments