@@ -135,7 +135,8 @@ def data(self):
135
135
if not self .raw_data :
136
136
return None
137
137
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
139
140
return self ._decoded_data
140
141
141
142
def __str__ (self ):
@@ -177,16 +178,17 @@ class Tube(object):
177
178
def __init__ (self , queue , name , ** kwargs ):
178
179
self .queue = queue
179
180
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
+ }
186
187
self .opt .update (kwargs )
187
188
self ._serialize = None
188
189
self ._deserialize = None
189
- #----------------
190
+
191
+ # ----------------
190
192
@property
191
193
def serialize (self ):
192
194
"""
@@ -195,13 +197,15 @@ def serialize(self):
195
197
if self ._serialize is None :
196
198
return self .queue .serialize
197
199
return self ._serialize
200
+
198
201
@serialize .setter
199
202
def serialize (self , func ):
200
203
if not (hasattr (func , '__call__' ) or func is None ):
201
204
raise TypeError ("func must be Callable "
202
- "or None, but not " + str (type (func )))
205
+ "or None, but not " + str (type (func )))
203
206
self ._serialize = func
204
- #----------------
207
+
208
+ # ----------------
205
209
@property
206
210
def deserialize (self ):
207
211
"""
@@ -210,13 +214,15 @@ def deserialize(self):
210
214
if self ._deserialize is None :
211
215
return self .queue .deserialize
212
216
return self ._deserialize
217
+
213
218
@deserialize .setter
214
219
def deserialize (self , func ):
215
220
if not (hasattr (func , '__call__' ) or func is None ):
216
221
raise TypeError ("func must be Callable "
217
- "or None, but not " + str (type (func )))
222
+ "or None, but not " + str (type (func )))
218
223
self ._deserialize = func
219
- #----------------
224
+
225
+ # ----------------
220
226
def update_options (self , ** kwargs ):
221
227
"""
222
228
Update options for current tube (such as ttl, ttr, pri and delay)
@@ -231,7 +237,8 @@ def put(self, data, **kwargs):
231
237
232
238
:param data: Data for pushing into queue
233
239
: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)
235
242
:param ttl: new time to live (Not necessary, Default of Tube object)
236
243
:param ttr: time to release (Not necessary, Default of Tube object)
237
244
:param tube: name of Tube (Not necessary, Default of Tube object)
@@ -264,7 +271,8 @@ def put(self, data, **kwargs):
264
271
265
272
def urgent (self , data = None , ** kwargs ):
266
273
"""
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.
268
276
"""
269
277
kwargs ['urgent' ] = True
270
278
return self .put (data , ** dict (self .opt , ** kwargs ))
@@ -296,10 +304,12 @@ def kick(self, count=None):
296
304
297
305
def statistics (self ):
298
306
"""
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.
300
309
"""
301
310
return self .queue .statistics (tube = self .opt ['tube' ])
302
311
312
+
303
313
class Queue (object ):
304
314
"""
305
315
Tarantool queue wrapper. Surely pinned to space. May create tubes.
@@ -349,7 +359,7 @@ def basic_serialize(data):
349
359
def basic_deserialize (data ):
350
360
return msgpack .unpackb (data )
351
361
352
- def __init__ (self , host = "localhost" , port = 33013 , space = 0 , schema = None ):
362
+ def __init__ (self , host = "localhost" , port = 33013 , space = 0 , schema = None ):
353
363
if not (host and port ):
354
364
raise Queue .BadConfigException ("host and port params "
355
365
"must be not empty" )
@@ -368,7 +378,7 @@ def __init__(self, host="localhost", port=33013, space=0, schema=None):
368
378
self ._serialize = self .basic_serialize
369
379
self ._deserialize = self .basic_deserialize
370
380
371
- # ----------------
381
+ # ----------------
372
382
@property
373
383
def serialize (self ):
374
384
"""
@@ -378,16 +388,19 @@ def serialize(self):
378
388
if not hasattr (self , '_serialize' ):
379
389
self .serialize = self .basic_serialize
380
390
return self ._serialize
391
+
381
392
@serialize .setter
382
393
def serialize (self , func ):
383
394
if not (hasattr (func , '__call__' ) or func is None ):
384
395
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
+
387
399
@serialize .deleter
388
400
def serialize (self ):
389
401
self ._serialize = self .basic_serialize
390
- #----------------
402
+
403
+ # ----------------
391
404
@property
392
405
def deserialize (self ):
393
406
"""
@@ -397,16 +410,21 @@ def deserialize(self):
397
410
if not hasattr (self , '_deserialize' ):
398
411
self ._deserialize = self .basic_deserialize
399
412
return self ._deserialize
413
+
400
414
@deserialize .setter
401
415
def deserialize (self , func ):
402
416
if not (hasattr (func , '__call__' ) or func is None ):
403
417
raise TypeError ("func must be Callable "
404
418
"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
+
406
423
@deserialize .deleter
407
424
def deserialize (self ):
408
425
self ._deserialize = self .basic_deserialize
409
- #----------------
426
+
427
+ # ----------------
410
428
@property
411
429
def tarantool_connection (self ):
412
430
"""
@@ -417,43 +435,50 @@ def tarantool_connection(self):
417
435
if not hasattr (self , '_conclass' ):
418
436
self ._conclass = tarantool .Connection
419
437
return self ._conclass
438
+
420
439
@tarantool_connection .setter
421
440
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
426
446
if hasattr (self , '_tnt' ):
427
447
self .__dict__ .pop ('_tnt' )
448
+
428
449
@tarantool_connection .deleter
429
450
def tarantool_connection (self ):
430
451
if hasattr (self , '_conclass' ):
431
452
self .__dict__ .pop ('_conclass' )
432
453
if hasattr (self , '_tnt' ):
433
454
self .__dict__ .pop ('_tnt' )
434
- #----------------
455
+
456
+ # ----------------
435
457
@property
436
458
def tarantool_lock (self ):
437
459
"""
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.
441
463
"""
442
464
if not hasattr (self , '_lockinst' ):
443
465
self ._lockinst = threading .Lock ()
444
466
return self ._lockinst
467
+
445
468
@tarantool_lock .setter
446
469
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
+
451
476
@tarantool_lock .deleter
452
477
def tarantool_lock (self ):
453
478
if hasattr (self , '_lockinst' ):
454
479
self .__dict__ .pop ('_lockinst' )
455
- #----------------
456
480
481
+ # ----------------
457
482
@property
458
483
def tnt (self ):
459
484
if not hasattr (self , '_tnt' ):
@@ -592,12 +617,14 @@ def statistics(self, tube=None):
592
617
ans = {}
593
618
if stat .rowcount > 0 :
594
619
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
+ )
596
623
if int (k_t [0 ]) != self .space :
597
624
continue
598
625
if k_t [1 ].endswith ('.tasks' ):
599
626
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 :
601
628
ans [k_t [1 ]] = {'tasks' : {}}
602
629
if len (k_t ) == 4 :
603
630
ans [k_t [1 ]]['tasks' ][k_t [- 1 ]] = v
0 commit comments