Skip to content

Commit f2f5903

Browse files
author
Vladimir Rudnyh
committed
Cleanup (PEP8)
1 parent 9560d67 commit f2f5903

File tree

3 files changed

+169
-113
lines changed

3 files changed

+169
-113
lines changed

setup.py

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,72 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
13
import codecs
24
import os
35
import re
4-
from setuptools import setup
5-
import sys
6-
7-
cmdclass = {}
86

97
try:
108
from setuptools import setup
119
except ImportError:
1210
from distutils.core import setup
1311

12+
cmdclass = {}
13+
1414
try:
1515
from sphinx.setup_command import BuildDoc
1616
cmdclass["build_sphinx"] = BuildDoc
1717
except ImportError:
1818
pass
1919

20+
2021
def read(*parts):
2122
filename = os.path.join(os.path.dirname(__file__), *parts)
2223
with codecs.open(filename, encoding='utf-8') as fp:
2324
return fp.read()
2425

26+
2527
def find_version(*file_paths):
2628
version_file = read(*file_paths)
27-
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
29+
version_match = re.search(r"""^__version__\s*=\s*(['"])(.+)\1""",
2830
version_file, re.M)
2931
if version_match:
30-
return version_match.group(1)
32+
return version_match.group(2)
3133
raise RuntimeError("Unable to find version string.")
3234

33-
setup(name='tarantool-queue',
34-
version=find_version('tarantool_queue', '__init__.py'),
35-
description='Python bindings for Tarantool queue script (http://github.com/tarantool/queue)',
36-
long_description=read('README.rst'),
37-
author='Eugine Blikh',
38-
author_email='[email protected]',
39-
maintainer='Eugine Blikh',
40-
maintainer_email='[email protected]',
41-
license='MIT',
42-
packages=['tarantool_queue'],
43-
platforms = ["all"],
44-
install_requires=[
45-
'msgpack-python',
46-
'tarantool<0.4'
47-
],
48-
url='http://github.com/tarantool/tarantool-queue-python',
49-
test_suite='tests.test_queue',
50-
tests_require=[
51-
'msgpack-python',
52-
'tarantool'
53-
],
54-
classifiers=[
55-
'Development Status :: 4 - Beta',
56-
'Operating System :: OS Independent',
57-
'Intended Audience :: Developers',
58-
'License :: OSI Approved :: MIT License',
59-
'Programming Language :: Python :: 2.6',
60-
'Programming Language :: Python :: 2.7',
61-
'Topic :: Database :: Front-Ends',
62-
'Environment :: Console'
63-
],
64-
cmdclass = cmdclass
35+
36+
setup(
37+
name='tarantool-queue',
38+
version=find_version('tarantool_queue', '__init__.py'),
39+
description=(
40+
'Python bindings for Tarantool queue script'
41+
' (http://github.com/tarantool/queue)'
42+
),
43+
long_description=read('README.rst'),
44+
author='Eugine Blikh',
45+
author_email='[email protected]',
46+
maintainer='Eugine Blikh',
47+
maintainer_email='[email protected]',
48+
license='MIT',
49+
packages=['tarantool_queue'],
50+
platforms=["all"],
51+
install_requires=[
52+
'msgpack-python',
53+
'tarantool<0.4'
54+
],
55+
url='http://github.com/tarantool/tarantool-queue-python',
56+
test_suite='tests.test_queue',
57+
tests_require=[
58+
'msgpack-python',
59+
'tarantool'
60+
],
61+
classifiers=[
62+
'Development Status :: 4 - Beta',
63+
'Operating System :: OS Independent',
64+
'Intended Audience :: Developers',
65+
'License :: OSI Approved :: MIT License',
66+
'Programming Language :: Python :: 2.6',
67+
'Programming Language :: Python :: 2.7',
68+
'Topic :: Database :: Front-Ends',
69+
'Environment :: Console'
70+
],
71+
cmdclass=cmdclass
6572
)

tarantool_queue/tarantool_queue.py

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def data(self):
135135
if not self.raw_data:
136136
return None
137137
if not hasattr(self, '_decoded_data'):
138-
self._decoded_data = self.queue.tube(self.tube).deserialize(self.raw_data)
138+
data = self.queue.tube(self.tube).deserialize(self.raw_data)
139+
self._decoded_data = data
139140
return self._decoded_data
140141

141142
def __str__(self):
@@ -177,16 +178,17 @@ class Tube(object):
177178
def __init__(self, queue, name, **kwargs):
178179
self.queue = queue
179180
self.opt = {
180-
'delay' : 0,
181-
'ttl' : 0,
182-
'ttr' : 0,
183-
'pri' : 0,
184-
'tube' : name
185-
}
181+
'delay': 0,
182+
'ttl': 0,
183+
'ttr': 0,
184+
'pri': 0,
185+
'tube': name
186+
}
186187
self.opt.update(kwargs)
187188
self._serialize = None
188189
self._deserialize = None
189-
#----------------
190+
191+
# ----------------
190192
@property
191193
def serialize(self):
192194
"""
@@ -195,13 +197,15 @@ def serialize(self):
195197
if self._serialize is None:
196198
return self.queue.serialize
197199
return self._serialize
200+
198201
@serialize.setter
199202
def serialize(self, func):
200203
if not (hasattr(func, '__call__') or func is None):
201204
raise TypeError("func must be Callable "
202-
"or None, but not "+str(type(func)))
205+
"or None, but not " + str(type(func)))
203206
self._serialize = func
204-
#----------------
207+
208+
# ----------------
205209
@property
206210
def deserialize(self):
207211
"""
@@ -210,13 +214,15 @@ def deserialize(self):
210214
if self._deserialize is None:
211215
return self.queue.deserialize
212216
return self._deserialize
217+
213218
@deserialize.setter
214219
def deserialize(self, func):
215220
if not (hasattr(func, '__call__') or func is None):
216221
raise TypeError("func must be Callable "
217-
"or None, but not "+str(type(func)))
222+
"or None, but not " + str(type(func)))
218223
self._deserialize = func
219-
#----------------
224+
225+
# ----------------
220226
def update_options(self, **kwargs):
221227
"""
222228
Update options for current tube (such as ttl, ttr, pri and delay)
@@ -231,7 +237,8 @@ def put(self, data, **kwargs):
231237
232238
:param data: Data for pushing into queue
233239
:param urgent: make task urgent (Not necessary, False by default)
234-
:param delay: new delay for task (Not necessary, Default of Tube object)
240+
:param delay: new delay for task
241+
(Not necessary, Default of Tube object)
235242
:param ttl: new time to live (Not necessary, Default of Tube object)
236243
:param ttr: time to release (Not necessary, Default of Tube object)
237244
:param tube: name of Tube (Not necessary, Default of Tube object)
@@ -264,7 +271,8 @@ def put(self, data, **kwargs):
264271

265272
def urgent(self, data=None, **kwargs):
266273
"""
267-
Same as :meth:`Tube.put() <tarantool_queue.Tube.put>` put, but set highest priority for this task.
274+
Same as :meth:`Tube.put() <tarantool_queue.Tube.put>` put,
275+
but set highest priority for this task.
268276
"""
269277
kwargs['urgent'] = True
270278
return self.put(data, **dict(self.opt, **kwargs))
@@ -296,10 +304,12 @@ def kick(self, count=None):
296304

297305
def statistics(self):
298306
"""
299-
See :meth:`Queue.statistics() <tarantool_queue.Queue.statistics>` for more information.
307+
See :meth:`Queue.statistics() <tarantool_queue.Queue.statistics>`
308+
for more information.
300309
"""
301310
return self.queue.statistics(tube=self.opt['tube'])
302311

312+
303313
class Queue(object):
304314
"""
305315
Tarantool queue wrapper. Surely pinned to space. May create tubes.
@@ -349,7 +359,7 @@ def basic_serialize(data):
349359
def basic_deserialize(data):
350360
return msgpack.unpackb(data)
351361

352-
def __init__(self, host="localhost", port=33013, space=0, schema=None):
362+
def __init__(self, host="localhost", port=33013, space=0, schema=None):
353363
if not(host and port):
354364
raise Queue.BadConfigException("host and port params "
355365
"must be not empty")
@@ -368,7 +378,7 @@ def __init__(self, host="localhost", port=33013, space=0, schema=None):
368378
self._serialize = self.basic_serialize
369379
self._deserialize = self.basic_deserialize
370380

371-
#----------------
381+
# ----------------
372382
@property
373383
def serialize(self):
374384
"""
@@ -378,16 +388,19 @@ def serialize(self):
378388
if not hasattr(self, '_serialize'):
379389
self.serialize = self.basic_serialize
380390
return self._serialize
391+
381392
@serialize.setter
382393
def serialize(self, func):
383394
if not (hasattr(func, '__call__') or func is None):
384395
raise TypeError("func must be Callable "
385-
"or None, but not "+str(type(func)))
386-
self._serialize = func if not (func is None) else self.basic_serialize
396+
"or None, but not " + str(type(func)))
397+
self._serialize = func if func is not None else self.basic_serialize
398+
387399
@serialize.deleter
388400
def serialize(self):
389401
self._serialize = self.basic_serialize
390-
#----------------
402+
403+
# ----------------
391404
@property
392405
def deserialize(self):
393406
"""
@@ -397,16 +410,21 @@ def deserialize(self):
397410
if not hasattr(self, '_deserialize'):
398411
self._deserialize = self.basic_deserialize
399412
return self._deserialize
413+
400414
@deserialize.setter
401415
def deserialize(self, func):
402416
if not (hasattr(func, '__call__') or func is None):
403417
raise TypeError("func must be Callable "
404418
"or None, but not " + str(type(func)))
405-
self._deserialize = func if not (func is None) else self.basic_deserialize
419+
self._deserialize = (func
420+
if func is not None
421+
else self.basic_deserialize)
422+
406423
@deserialize.deleter
407424
def deserialize(self):
408425
self._deserialize = self.basic_deserialize
409-
#----------------
426+
427+
# ----------------
410428
@property
411429
def tarantool_connection(self):
412430
"""
@@ -417,43 +435,50 @@ def tarantool_connection(self):
417435
if not hasattr(self, '_conclass'):
418436
self._conclass = tarantool.Connection
419437
return self._conclass
438+
420439
@tarantool_connection.setter
421440
def tarantool_connection(self, cls):
422-
if not('call' in dir(cls) and '__init__' in dir(cls)) and not (cls is None):
423-
raise TypeError("Connection class must have"
424-
" connect and call methods or be None")
425-
self._conclass = cls if not (cls is None) else tarantool.Connection
441+
if 'call' not in dir(cls) or '__init__' not in dir(cls):
442+
if cls is not None:
443+
raise TypeError("Connection class must have"
444+
" connect and call methods or be None")
445+
self._conclass = cls if cls is not None else tarantool.Connection
426446
if hasattr(self, '_tnt'):
427447
self.__dict__.pop('_tnt')
448+
428449
@tarantool_connection.deleter
429450
def tarantool_connection(self):
430451
if hasattr(self, '_conclass'):
431452
self.__dict__.pop('_conclass')
432453
if hasattr(self, '_tnt'):
433454
self.__dict__.pop('_tnt')
434-
#----------------
455+
456+
# ----------------
435457
@property
436458
def tarantool_lock(self):
437459
"""
438-
Locking class: must be locking instance with methods __enter__ and __exit__. If
439-
it sets to None or delete - it will use default threading.Lock() instance
440-
for locking in the connecting.
460+
Locking class: must be locking instance with methods __enter__
461+
and __exit__. If it sets to None or delete - it will use default
462+
threading.Lock() instance for locking in the connecting.
441463
"""
442464
if not hasattr(self, '_lockinst'):
443465
self._lockinst = threading.Lock()
444466
return self._lockinst
467+
445468
@tarantool_lock.setter
446469
def tarantool_lock(self, lock):
447-
if not('__enter__' in dir(lock) and '__exit__' in dir(lock)) and not (lock is None):
448-
raise TypeError("Lock class must have"
449-
" `__enter__` and `__exit__` methods or be None")
450-
self._lockinst = lock if not (lock is None) else threading.Lock()
470+
if '__enter__' not in dir(lock) or '__exit__' not in dir(lock):
471+
if lock is not None:
472+
raise TypeError("Lock class must have `__enter__`"
473+
" and `__exit__` methods or be None")
474+
self._lockinst = lock if lock is not None else threading.Lock()
475+
451476
@tarantool_lock.deleter
452477
def tarantool_lock(self):
453478
if hasattr(self, '_lockinst'):
454479
self.__dict__.pop('_lockinst')
455-
#----------------
456480

481+
# ----------------
457482
@property
458483
def tnt(self):
459484
if not hasattr(self, '_tnt'):
@@ -592,12 +617,14 @@ def statistics(self, tube=None):
592617
ans = {}
593618
if stat.rowcount > 0:
594619
for k, v in dict(zip(stat[0][0::2], stat[0][1::2])).iteritems():
595-
k_t = list(re.match(r'space([^.]*)\.(.*)\.([^.]*)', k).groups())
620+
k_t = list(
621+
re.match(r'space([^.]*)\.(.*)\.([^.]*)', k).groups()
622+
)
596623
if int(k_t[0]) != self.space:
597624
continue
598625
if k_t[1].endswith('.tasks'):
599626
k_t = k_t[0:1] + k_t[1].split('.') + k_t[2:3]
600-
if not (k_t[1] in ans):
627+
if k_t[1] not in ans:
601628
ans[k_t[1]] = {'tasks': {}}
602629
if len(k_t) == 4:
603630
ans[k_t[1]]['tasks'][k_t[-1]] = v

0 commit comments

Comments
 (0)