Skip to content

Commit 86af9e7

Browse files
author
Vladimir Rudnyh
committedMar 12, 2015
Cleanup (PEP8)
1 parent 04f3760 commit 86af9e7

File tree

9 files changed

+219
-201
lines changed

9 files changed

+219
-201
lines changed
 

‎setup.py

+35-26
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
import codecs
4+
import os
5+
import re
36

47
try:
58
from setuptools import setup
69
except ImportError:
710
from distutils.core import setup
811

9-
import os
10-
11-
os.chdir(os.path.abspath(os.path.dirname(__file__)))
12-
13-
# Read package version without importing it
14-
for line in open(os.path.join("tarantool", "__init__.py")):
15-
if line.startswith("__version__"):
16-
exec line
17-
break
18-
1912
# Extra commands for documentation management
2013
cmdclass = {}
2114
command_options = {}
@@ -37,7 +30,7 @@
3730
from sphinx_pypi_upload import UploadDoc
3831
cmdclass["upload_sphinx"] = UploadDoc
3932
command_options["upload_sphinx"] = {
40-
'upload_dir': ('setup.py', os.path.join("build", "sphinx", "html"))
33+
'upload_dir': ('setup.py', os.path.join("build", "sphinx", "html"))
4134
}
4235
except ImportError:
4336
pass
@@ -51,28 +44,44 @@
5144
except ImportError:
5245
pass
5346

47+
48+
def read(*parts):
49+
filename = os.path.join(os.path.dirname(__file__), *parts)
50+
with codecs.open(filename, encoding='utf-8') as fp:
51+
return fp.read()
52+
53+
54+
def find_version(*file_paths):
55+
version_file = read(*file_paths)
56+
version_match = re.search(r"""^__version__\s*=\s*(['"])(.+)\1""",
57+
version_file, re.M)
58+
if version_match:
59+
return version_match.group(2)
60+
raise RuntimeError("Unable to find version string.")
61+
62+
5463
setup(
55-
name = "tarantool",
56-
packages = ["tarantool"],
57-
package_dir = {"tarantool": os.path.join("tarantool")},
58-
version = __version__,
59-
platforms = ["all"],
60-
author = "Konstantin Cherkasoff",
61-
author_email = "k.cherkasoff@gmail.com",
62-
url = "https://github.com/coxx/tarantool-python",
63-
license = "BSD",
64-
description = "Python client library for Tarantool Database",
65-
long_description = open("README.rst").read(),
66-
classifiers = [
64+
name="tarantool",
65+
packages=["tarantool"],
66+
package_dir={"tarantool": os.path.join("tarantool")},
67+
version=find_version('tarantool', '__init__.py'),
68+
platforms=["all"],
69+
author="Konstantin Cherkasoff",
70+
author_email="k.cherkasoff@gmail.com",
71+
url="https://github.com/tarantool/tarantool-python",
72+
license="BSD",
73+
description="Python client library for Tarantool Database",
74+
long_description=read('README.rst'),
75+
classifiers=[
6776
"Intended Audience :: Developers",
6877
"License :: OSI Approved :: BSD License",
6978
"Operating System :: OS Independent",
7079
"Programming Language :: Python",
7180
"Topic :: Database :: Front-Ends"
7281
],
73-
cmdclass = cmdclass,
74-
command_options = command_options,
75-
install_requires = [
82+
cmdclass=cmdclass,
83+
command_options=command_options,
84+
install_requires=[
7685
'msgpack-python>=0.4',
7786
]
7887
)

‎tarantool/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
)
2020

2121
from tarantool.schema import (
22-
Schema,
23-
SchemaError
22+
Schema,
23+
SchemaError
2424
)
2525

2626

‎tarantool/connection.py

+30-32
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import msgpack
1313

1414
import base64
15-
from const import IPROTO_GREETING_SIZE
1615

1716
try:
1817
from ctypes import c_ssize_t
@@ -53,9 +52,9 @@
5352
from tarantool.schema import Schema
5453
from 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

‎tarantool/const.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@
3636
REQUEST_TYPE_ERROR = 1 << 15
3737

3838

39-
SPACE_SCHEMA = 272
40-
SPACE_SPACE = 280
41-
SPACE_INDEX = 288
42-
SPACE_FUNC = 296
43-
SPACE_USER = 304
44-
SPACE_PRIV = 312
39+
SPACE_SCHEMA = 272
40+
SPACE_SPACE = 280
41+
SPACE_INDEX = 288
42+
SPACE_FUNC = 296
43+
SPACE_USER = 304
44+
SPACE_PRIV = 312
4545
SPACE_CLUSTER = 320
4646

4747
INDEX_SPACE_PRIMARY = 0
48-
INDEX_SPACE_NAME = 2
48+
INDEX_SPACE_NAME = 2
4949
INDEX_INDEX_PRIMARY = 0
50-
INDEX_INDEX_NAME = 2
50+
INDEX_INDEX_NAME = 2
5151

52-
ITERATOR_EQ = 0
52+
ITERATOR_EQ = 0
5353
ITERATOR_REQ = 1
5454
ITERATOR_ALL = 2
55-
ITERATOR_LT = 3
56-
ITERATOR_LE = 4
57-
ITERATOR_GE = 5
58-
ITERATOR_GT = 6
59-
ITERATOR_BITSET_ALL_SET = 7
60-
ITERATOR_BITSET_ANY_SET = 8
55+
ITERATOR_LT = 3
56+
ITERATOR_LE = 4
57+
ITERATOR_GE = 5
58+
ITERATOR_GT = 6
59+
ITERATOR_BITSET_ALL_SET = 7
60+
ITERATOR_BITSET_ANY_SET = 8
6161
ITERATOR_BITSET_ALL_NOT_SET = 9
6262

6363
# Default value for socket timeout (seconds)

‎tarantool/error.py

+48-44
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DatabaseError(Error):
3737

3838
class InterfaceError(Error):
3939

40-
'''\
40+
'''
4141
Error related to the database interface rather than the database itself
4242
'''
4343

@@ -90,7 +90,7 @@ class InterfaceError(Error):
9090
os_strerror_orig = os.strerror
9191

9292
def os_strerror_patched(code):
93-
'''\
93+
'''
9494
Return cross-platform message about socket-related errors
9595
9696
This function exists because under Windows os.strerror returns
@@ -144,7 +144,7 @@ class NetworkWarning(UserWarning):
144144

145145
class RetryWarning(UserWarning):
146146

147-
'''\
147+
'''
148148
Warning is emited in case of server return completion_status == 1
149149
(try again)
150150
'''
@@ -157,7 +157,7 @@ class RetryWarning(UserWarning):
157157

158158

159159
def warn(message, warning_class):
160-
'''\
160+
'''
161161
Emit warinig message.
162162
Just like standard warnings.warn() but don't output full filename.
163163
'''
@@ -167,68 +167,72 @@ def warn(message, warning_class):
167167
warnings.warn_explicit(message, warning_class, module_name, line_no)
168168

169169
_strerror = {
170-
0: ("ER_OK", "OK"),
171-
1: ("ER_ILLEGAL_PARAMS", "Illegal parameters, %s"),
172-
2: ("ER_MEMORY_ISSUE", "Failed to allocate %u bytes in %s for %s"),
173-
3: ("ER_TUPLE_FOUND", "Duplicate key exists in unique index %u"),
174-
4: ("ER_TUPLE_NOT_FOUND", "Tuple doesn't exist in index %u"),
175-
5: ("ER_UNSUPPORTED", "%s does not support %s"),
176-
6: ("ER_NONMASTER", "Can't modify data on a replication slave. My \
177-
master is: %s"),
178-
7: ("ER_SECONDARY", "Can't modify data upon a request on the \
179-
secondary port."),
180-
8: ("ER_INJECTION", "Error injection '%s'"),
181-
9: ("ER_CREATE_SPACE", "Failed to create space %u: %s"),
170+
0: ("ER_OK", "OK"),
171+
1: ("ER_ILLEGAL_PARAMS", "Illegal parameters, %s"),
172+
2: ("ER_MEMORY_ISSUE", "Failed to allocate %u bytes in %s for %s"),
173+
3: ("ER_TUPLE_FOUND", "Duplicate key exists in unique index %u"),
174+
4: ("ER_TUPLE_NOT_FOUND", "Tuple doesn't exist in index %u"),
175+
5: ("ER_UNSUPPORTED", "%s does not support %s"),
176+
6: ("ER_NONMASTER",
177+
"Can't modify data on a replication slave. My master is: %s"),
178+
7: ("ER_SECONDARY",
179+
"Can't modify data upon a request on the secondary port."),
180+
8: ("ER_INJECTION", "Error injection '%s'"),
181+
9: ("ER_CREATE_SPACE", "Failed to create space %u: %s"),
182182
10: ("ER_SPACE_EXISTS", "Space %u already exists"),
183183
11: ("ER_DROP_SPACE", "Can't drop space %u: %s"),
184184
12: ("ER_ALTER_SPACE", "Can't modify space %u: %s"),
185-
13: ("ER_INDEX_TYPE", "Unsupported index type supplied for index %u \
186-
in space %u"),
187-
14: ("ER_MODIFY_INDEX", "Can't create or modify index %u in space \
188-
%u: %s"),
189-
15: ("ER_LAST_DROP", "Can't drop the primary key in a system space, \
190-
space id %u"),
185+
13: ("ER_INDEX_TYPE",
186+
"Unsupported index type supplied for index %u in space %u"),
187+
14: ("ER_MODIFY_INDEX",
188+
"Can't create or modify index %u in space %u: %s"),
189+
15: ("ER_LAST_DROP",
190+
"Can't drop the primary key in a system space, space id %u"),
191191
16: ("ER_TUPLE_FORMAT_LIMIT", "Tuple format limit reached: %u"),
192-
17: ("ER_DROP_PRIMARY_KEY", "Can't drop primary key in space %u \
193-
while secondary keys exist"),
194-
18: ("ER_KEY_FIELD_TYPE", "Supplied key type of part %u does not \
195-
match index part type: expected %s"),
196-
19: ("ER_EXACT_MATCH", "Invalid key part count in an exact match \
197-
(expected %u, got %u)"),
192+
17: ("ER_DROP_PRIMARY_KEY",
193+
"Can't drop primary key in space %u while secondary keys exist"),
194+
18: ("ER_KEY_FIELD_TYPE",
195+
("Supplied key type of part %u does not match index part type:"
196+
" expected %s")),
197+
19: ("ER_EXACT_MATCH",
198+
"Invalid key part count in an exact match (expected %u, got %u)"),
198199
20: ("ER_INVALID_MSGPACK", "Invalid MsgPack - %s"),
199200
21: ("ER_PROC_RET", "msgpack.encode: can not encode Lua type '%s'"),
200201
22: ("ER_TUPLE_NOT_ARRAY", "Tuple/Key must be MsgPack array"),
201-
23: ("ER_FIELD_TYPE", "Tuple field %u type does not match one \
202-
required by operation: expected %s"),
203-
24: ("ER_FIELD_TYPE_MISMATCH", "Ambiguous field type in index %u, \
204-
key part %u. Requested type is %s but the field has \
205-
previously been defined as %s"),
202+
23: ("ER_FIELD_TYPE",
203+
("Tuple field %u type does not match one required by operation:"
204+
" expected %s")),
205+
24: ("ER_FIELD_TYPE_MISMATCH",
206+
("Ambiguous field type in index %u, key part %u. Requested type"
207+
" is %s but the field has previously been defined as %s")),
206208
25: ("ER_SPLICE", "Field SPLICE error: %s"),
207-
26: ("ER_ARG_TYPE", "Argument type in operation on field %u does \
208-
not match field type: expected a %s"),
209+
26: ("ER_ARG_TYPE",
210+
("Argument type in operation on field %u does not match field type:"
211+
" expected a %s")),
209212
27: ("ER_TUPLE_IS_TOO_LONG", "Tuple is too long %u"),
210213
28: ("ER_UNKNOWN_UPDATE_OP", "Unknown UPDATE operation"),
211214
29: ("ER_UPDATE_FIELD", "Field %u UPDATE error: %s"),
212-
30: ("ER_FIBER_STACK", "Can not create a new fiber: recursion \
213-
limit reached"),
214-
31: ("ER_KEY_PART_COUNT", "Invalid key part count (expected \
215-
[0..%u], got %u)"),
215+
30: ("ER_FIBER_STACK",
216+
"Can not create a new fiber: recursion limit reached"),
217+
31: ("ER_KEY_PART_COUNT",
218+
"Invalid key part count (expected [0..%u], got %u)"),
216219
32: ("ER_PROC_LUA", "%s"),
217220
33: ("ER_NO_SUCH_PROC", "Procedure '%.*s' is not defined"),
218221
34: ("ER_NO_SUCH_TRIGGER", "Trigger is not found"),
219222
35: ("ER_NO_SUCH_INDEX", "No index #%u is defined in space %u"),
220223
36: ("ER_NO_SUCH_SPACE", "Space %u does not exist"),
221224
37: ("ER_NO_SUCH_FIELD", "Field %u was not found in the tuple"),
222-
38: ("ER_SPACE_ARITY", "Tuple field count %u does not match space \
223-
%u arity %u"),
224-
39: ("ER_INDEX_ARITY", "Tuple field count %u is less than required \
225-
by a defined index (expected %u)"),
225+
38: ("ER_SPACE_ARITY",
226+
"Tuple field count %u does not match space %u arity %u"),
227+
39: ("ER_INDEX_ARITY",
228+
("Tuple field count %u is less than required by a defined index"
229+
" (expected %u)")),
226230
40: ("ER_WAL_IO", "Failed to write to disk"),
227231
41: ("ER_MORE_THAN_ONE_TUPLE", "More than one tuple found"),
228232
}
229233

234+
230235
def tnt_strerror(num):
231236
if num in _strerror:
232237
return _strerror[num]
233238
return "UNDEFINED"
234-

‎tarantool/request.py

+48-50
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838

3939

4040
class Request(object):
41-
42-
'''\
41+
'''
4342
Represents a single request to the server in compliance with the
4443
Tarantool protocol.
4544
Responsible for data encapsulation and builds binary packet
@@ -60,73 +59,77 @@ def __bytes__(self):
6059

6160
@classmethod
6261
def header(cls, length):
63-
header = msgpack.dumps({ IPROTO_CODE : cls.request_type,
64-
IPROTO_SYNC : 0})
62+
header = msgpack.dumps({IPROTO_CODE: cls.request_type,
63+
IPROTO_SYNC: 0})
6564
return msgpack.dumps(length + len(header)) + header
6665

67-
class RequestInsert(Request):
6866

69-
'''\
67+
class RequestInsert(Request):
68+
'''
7069
Represents INSERT request
7170
'''
7271
request_type = REQUEST_TYPE_INSERT
7372

7473
# pylint: disable=W0231
7574
def __init__(self, conn, space_no, values):
76-
'''\
75+
'''
7776
'''
7877
super(RequestInsert, self).__init__(conn)
7978
assert isinstance(values, (tuple, list))
8079

81-
request_body = msgpack.dumps({ IPROTO_SPACE_ID: space_no, \
82-
IPROTO_TUPLE: values })
80+
request_body = msgpack.dumps({IPROTO_SPACE_ID: space_no,
81+
IPROTO_TUPLE: values})
8382

8483
self._bytes = self.header(len(request_body)) + request_body
8584

86-
class RequestAuthenticate(Request):
8785

86+
class RequestAuthenticate(Request):
87+
'''
88+
Represents AUTHENTICATE request
89+
'''
8890
request_type = REQUEST_TYPE_AUTHENTICATE
8991

90-
9192
def __init__(self, conn, salt, user, password):
9293
super(RequestAuthenticate, self).__init__(conn)
94+
9395
def sha1(values):
9496
sha1 = hashlib.sha1()
9597
for i in values:
9698
sha1.update(i)
9799
return sha1.digest()
100+
98101
def strxor(rhs, lhs):
99102
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(rhs, lhs))
103+
100104
hash1 = sha1((password,))
101105
hash2 = sha1((hash1,))
102106
scramble = sha1((salt, hash2))
103107
scramble = strxor(hash1, scramble)
104-
request_body = msgpack.dumps({IPROTO_USER_NAME: user, \
108+
request_body = msgpack.dumps({IPROTO_USER_NAME: user,
105109
IPROTO_TUPLE: ("chap-sha1", scramble)})
106110
self._bytes = self.header(len(request_body)) + request_body
107111

108-
class RequestReplace(Request):
109112

110-
'''\
113+
class RequestReplace(Request):
114+
'''
111115
Represents REPLACE request
112116
'''
113117
request_type = REQUEST_TYPE_REPLACE
114118

115119
# pylint: disable=W0231
116120
def __init__(self, conn, space_no, values):
117-
'''\
121+
'''
118122
'''
119123
super(RequestReplace, self).__init__(conn)
120124
assert isinstance(values, (tuple, list))
121125

122-
request_body = msgpack.dumps({ IPROTO_SPACE_ID: space_no, \
123-
IPROTO_TUPLE: values })
126+
request_body = msgpack.dumps({IPROTO_SPACE_ID: space_no,
127+
IPROTO_TUPLE: values})
124128

125129
self._bytes = self.header(len(request_body)) + request_body
126130

127131

128132
class RequestDelete(Request):
129-
130133
'''
131134
Represents DELETE request
132135
'''
@@ -138,37 +141,35 @@ def __init__(self, conn, space_no, index_no, key):
138141
'''
139142
super(RequestDelete, self).__init__(conn)
140143

141-
request_body = msgpack.dumps({ IPROTO_SPACE_ID: space_no, \
142-
IPROTO_INDEX_ID: index_no, \
143-
IPROTO_KEY: key})
144+
request_body = msgpack.dumps({IPROTO_SPACE_ID: space_no,
145+
IPROTO_INDEX_ID: index_no,
146+
IPROTO_KEY: key})
144147

145148
self._bytes = self.header(len(request_body)) + request_body
146149

147150

148151
class RequestSelect(Request):
149-
150-
'''\
152+
'''
151153
Represents SELECT request
152154
'''
153155
request_type = REQUEST_TYPE_SELECT
154156

155157
# pylint: disable=W0231
156158
def __init__(self, conn, space_no, index_no, key, offset, limit, iterator):
157159
super(RequestSelect, self).__init__(conn)
158-
request_body = msgpack.dumps({ IPROTO_SPACE_ID: space_no, \
159-
IPROTO_INDEX_ID: index_no, \
160-
IPROTO_OFFSET: offset, \
161-
IPROTO_LIMIT: limit, \
162-
IPROTO_ITERATOR: iterator, \
163-
IPROTO_KEY: key})
160+
request_body = msgpack.dumps({IPROTO_SPACE_ID: space_no,
161+
IPROTO_INDEX_ID: index_no,
162+
IPROTO_OFFSET: offset,
163+
IPROTO_LIMIT: limit,
164+
IPROTO_ITERATOR: iterator,
165+
IPROTO_KEY: key})
164166

165167
self._bytes = self.header(len(request_body)) + request_body
166168

167169

168170
class RequestUpdate(Request):
169-
170-
'''\
171-
Represents UPDATE request
171+
'''
172+
Represents UPDATE request
172173
'''
173174

174175
request_type = REQUEST_TYPE_UPDATE
@@ -177,18 +178,17 @@ class RequestUpdate(Request):
177178
def __init__(self, conn, space_no, index_no, key, op_list):
178179
super(RequestUpdate, self).__init__(conn)
179180

180-
request_body = msgpack.dumps({ IPROTO_SPACE_ID: space_no, \
181-
IPROTO_INDEX_ID: index_no, \
182-
IPROTO_KEY: key, \
183-
IPROTO_TUPLE: op_list })
181+
request_body = msgpack.dumps({IPROTO_SPACE_ID: space_no,
182+
IPROTO_INDEX_ID: index_no,
183+
IPROTO_KEY: key,
184+
IPROTO_TUPLE: op_list})
184185

185186
self._bytes = self.header(len(request_body)) + request_body
186187

187188

188189
class RequestCall(Request):
189-
190190
'''
191-
Represents CALL request
191+
Represents CALL request
192192
'''
193193
request_type = REQUEST_TYPE_CALL
194194

@@ -197,16 +197,15 @@ def __init__(self, conn, name, args):
197197
super(RequestCall, self).__init__(conn)
198198
assert isinstance(args, (list, tuple))
199199

200-
request_body = msgpack.dumps({ IPROTO_FUNCTION_NAME: name, \
201-
IPROTO_TUPLE: args })
200+
request_body = msgpack.dumps({IPROTO_FUNCTION_NAME: name,
201+
IPROTO_TUPLE: args})
202202

203203
self._bytes = self.header(len(request_body)) + request_body
204204

205205

206206
class RequestEval(Request):
207-
208207
'''
209-
Represents EVAL request
208+
Represents EVAL request
210209
'''
211210
request_type = REQUEST_TYPE_EVAL
212211

@@ -215,14 +214,13 @@ def __init__(self, conn, name, args):
215214
super(RequestEval, self).__init__(conn)
216215
assert isinstance(args, (list, tuple))
217216

218-
request_body = msgpack.dumps({ IPROTO_EXPR: name, \
219-
IPROTO_TUPLE: args })
217+
request_body = msgpack.dumps({IPROTO_EXPR: name,
218+
IPROTO_TUPLE: args})
220219

221220
self._bytes = self.header(len(request_body)) + request_body
222221

223222

224223
class RequestPing(Request):
225-
226224
'''
227225
Ping body is empty, so body_length == 0 and there's no body
228226
'''
@@ -232,23 +230,23 @@ def __init__(self, conn):
232230
super(RequestPing, self).__init__(conn)
233231
self._bytes = self.header(0)
234232

235-
class RequestJoin(Request):
236233

234+
class RequestJoin(Request):
237235
'''
238-
Represents JOIN request
236+
Represents JOIN request
239237
'''
240238
request_type = REQUEST_TYPE_JOIN
241239

242240
# pylint: disable=W0231
243241
def __init__(self, conn, server_uuid):
244242
super(RequestJoin, self).__init__(conn)
245-
request_body = msgpack.dumps({ IPROTO_SERVER_UUID: server_uuid })
243+
request_body = msgpack.dumps({IPROTO_SERVER_UUID: server_uuid})
246244
self._bytes = self.header(len(request_body)) + request_body
247245

248-
class RequestSubscribe(Request):
249246

247+
class RequestSubscribe(Request):
250248
'''
251-
Represents SUBSCRIBE request
249+
Represents SUBSCRIBE request
252250
'''
253251
request_type = REQUEST_TYPE_SUBSCRIBE
254252

‎tarantool/response.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@
1010
IPROTO_DATA,
1111
IPROTO_ERROR,
1212
IPROTO_SYNC,
13-
REQUEST_TYPE_OK,
1413
REQUEST_TYPE_ERROR
1514
)
1615
from tarantool.error import DatabaseError, tnt_strerror
1716

1817
if sys.version_info < (2, 6):
1918
bytes = str # pylint: disable=W0622
2019

21-
class Response(list):
2220

23-
'''\
21+
class Response(list):
22+
'''
2423
Represents a single response from the server in compliance with the
2524
Tarantool protocol.
2625
Responsible for data encapsulation (i.e. received list of tuples)
2726
and parses binary packet received from the server.
2827
'''
2928

3029
def __init__(self, conn, response):
31-
'''\
30+
'''
3231
Create an instance of `Response` using data received from the server.
3332
3433
__init__() itself reads data from the socket, parses response body and
@@ -42,7 +41,7 @@ def __init__(self, conn, response):
4241
# created in the __new__(). But let it be.
4342
super(Response, self).__init__()
4443

45-
unpacker = msgpack.Unpacker(use_list = True)
44+
unpacker = msgpack.Unpacker(use_list=True)
4645
unpacker.feed(response)
4746
header = unpacker.unpack()
4847

@@ -56,7 +55,7 @@ def __init__(self, conn, response):
5655
pass
5756

5857
if self._code < REQUEST_TYPE_ERROR:
59-
self._return_code = 0;
58+
self._return_code = 0
6059
self._completion_status = 0
6160
self._data = self._body.get(IPROTO_DATA, None)
6261
# Backward-compatibility
@@ -75,7 +74,7 @@ def __init__(self, conn, response):
7574

7675
@property
7776
def completion_status(self):
78-
'''\
77+
'''
7978
:type: int
8079
8180
Request completion status.
@@ -92,7 +91,7 @@ def completion_status(self):
9291

9392
@property
9493
def rowcount(self):
95-
'''\
94+
'''
9695
:type: int
9796
9897
Number of rows affected or returned by a query.
@@ -101,7 +100,7 @@ def rowcount(self):
101100

102101
@property
103102
def body(self):
104-
'''\
103+
'''
105104
:type: dict
106105
107106
Required field in the server response.
@@ -111,7 +110,7 @@ def body(self):
111110

112111
@property
113112
def code(self):
114-
'''\
113+
'''
115114
:type: int
116115
117116
Required field in the server response.
@@ -121,7 +120,7 @@ def code(self):
121120

122121
@property
123122
def return_code(self):
124-
'''\
123+
'''
125124
:type: int
126125
127126
Required field in the server response.
@@ -134,7 +133,7 @@ def return_code(self):
134133

135134
@property
136135
def data(self):
137-
'''\
136+
'''
138137
:type: object
139138
140139
Required field in the server response.
@@ -145,16 +144,17 @@ def data(self):
145144

146145
@property
147146
def strerror(self):
148-
'''\
147+
'''
149148
:type: str
150149
151-
It may be ER_OK if request was successful, or contain error code string.
150+
It may be ER_OK if request was successful,
151+
or contain error code string.
152152
'''
153153
return tnt_strerror(self._return_code)
154154

155155
@property
156156
def return_message(self):
157-
'''\
157+
'''
158158
:type: str
159159
160160
The error message returned by the server in case
@@ -163,14 +163,14 @@ def return_message(self):
163163
return self._return_message
164164

165165
def __str__(self):
166-
'''\
166+
'''
167167
Return user friendy string representation of the object.
168168
Useful for the interactive sessions and debuging.
169169
170170
:rtype: str or None
171171
'''
172172
if self.completion_status:
173-
return yaml.dump({ 'error': {
173+
return yaml.dump({'error': {
174174
'code': self.strerror[0],
175175
'reason': self.return_message
176176
}})

‎tarantool/schema.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tarantool.error import SchemaError
99
import tarantool.const as const
1010

11+
1112
class SchemaIndex(object):
1213
def __init__(self, array, space):
1314
self.iid = array[1]
@@ -16,7 +17,7 @@ def __init__(self, array, space):
1617
self.unique = array[4]
1718
self.parts = []
1819
for i in xrange(array[5]):
19-
self.parts.append((array[5+1+i*2], array[5+2+i*2]))
20+
self.parts.append((array[5 + 1 + i * 2], array[5 + 2 + i * 2]))
2021
self.space = space
2122
self.space.indexes[self.iid] = self
2223
if self.name:
@@ -27,6 +28,7 @@ def flush(self):
2728
if self.name:
2829
del self.space.indexes[self.name]
2930

31+
3032
class SchemaSpace(object):
3133
def __init__(self, array, schema):
3234
self.sid = array[0]
@@ -43,6 +45,7 @@ def flush(self):
4345
if self.name:
4446
del self.schema[self.name]
4547

48+
4649
class Schema(object):
4750
def __init__(self, con):
4851
self.schema = {}
@@ -53,15 +56,17 @@ def get_space(self, space):
5356
return self.schema[space]
5457
except KeyError:
5558
pass
56-
_index = (const.INDEX_SPACE_NAME if isinstance(space, basestring) else const.INDEX_SPACE_PRIMARY)
59+
_index = (const.INDEX_SPACE_NAME
60+
if isinstance(space, basestring)
61+
else const.INDEX_SPACE_PRIMARY)
5762

5863
array = self.con.select(const.SPACE_SPACE, space, index=_index)
5964
if len(array) > 1:
60-
raise SchemaError('Some strange output from server: \n'+array)
65+
raise SchemaError('Some strange output from server: \n' + array)
6166
elif len(array) == 0 or not len(array[0]):
6267
temp_name = ('name' if isinstance(space, basestring) else 'id')
63-
raise SchemaError('There\'s no space with {1} \'{0}\''.format(space,
64-
temp_name))
68+
raise SchemaError(
69+
"There's no space with {1} '{0}'".format(space, temp_name))
6570
array = array[0]
6671
return SchemaSpace(array, self.schema)
6772

@@ -71,15 +76,19 @@ def get_index(self, space, index):
7176
return _space.indexes[index]
7277
except KeyError:
7378
pass
74-
_index = (const.INDEX_INDEX_NAME if isinstance(index, basestring) else const.INDEX_INDEX_PRIMARY)
79+
_index = (const.INDEX_INDEX_NAME
80+
if isinstance(index, basestring)
81+
else const.INDEX_INDEX_PRIMARY)
7582

76-
array = self.con.select(const.SPACE_INDEX, [_space.sid, index], index=_index)
83+
array = self.con.select(const.SPACE_INDEX, [_space.sid, index],
84+
index=_index)
7785
if len(array) > 1:
78-
raise SchemaError('Some strange output from server: \n'+array)
86+
raise SchemaError('Some strange output from server: \n' + array)
7987
elif len(array) == 0 or not len(array[0]):
8088
temp_name = ('name' if isinstance(index, basestring) else 'id')
81-
raise SchemaError('There\'s no index with {2} \'{0}\' '
82-
'in space \'{1}\''.format(index, _space.name, temp_name))
89+
raise SchemaError(
90+
"There's no index with {2} '{0}' in space '{1}'".format(
91+
index, _space.name, temp_name))
8392
array = array[0]
8493
return SchemaIndex(array, _space)
8594

‎tarantool/space.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
It is an object-oriented wrapper for request over Tarantool space.
66
'''
77

8-
class Space(object):
98

10-
'''\
9+
class Space(object):
10+
'''
1111
Object-oriented wrapper for accessing a particular space.
1212
Encapsulates the identifier of the space and provides more convenient
1313
syntax for database operations.
1414
'''
1515

1616
def __init__(self, connection, space_name):
17-
'''\
17+
'''
1818
Create Space instance.
1919
2020
:param connection: Object representing connection to the server
@@ -75,7 +75,7 @@ def update(self, key, op_list):
7575
return self.connection.update(self.space_no, key, op_list)
7676

7777
def select(self, values, **kwargs):
78-
'''\
78+
'''
7979
Execute SELECT request.
8080
Select and retrieve data from the database.
8181
@@ -102,7 +102,7 @@ def select(self, values, **kwargs):
102102
self.space_no, values, index=index, offset=offset, limit=limit)
103103

104104
def call(self, func_name, *args, **kwargs):
105-
'''\
105+
'''
106106
Execute CALL request. Call stored Lua function.
107107
108108
:param func_name: stored Lua function name

0 commit comments

Comments
 (0)
Please sign in to comment.