Skip to content

Commit b8f7194

Browse files
committed
Merge pull request #53 from dreadatour/master
Cleanup (PEP8)
2 parents 0991ecb + 86af9e7 commit b8f7194

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 = "[email protected]",
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="[email protected]",
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)

0 commit comments

Comments
 (0)