<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , unicode_literals <EOL> from collections import deque <EOL> from kombu . five import python_2_unicode_compatible <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> @ python_2_unicode_compatible <EOL> class LaxBoundedSemaphore ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , value ) : <EOL> self . initial_value = self . value = value <EOL> self . _waiting = deque ( ) <EOL> self . _add_waiter = self . _waiting . append <EOL> self . _pop_waiter = self . _waiting . popleft <EOL> def acquire ( self , callback , * partial_args , ** partial_kwargs ) : <EOL> """<STR_LIT>""" <EOL> value = self . value <EOL> if value <= <NUM_LIT:0> : <EOL> self . _add_waiter ( ( callback , partial_args , partial_kwargs ) ) <EOL> return False <EOL> else : <EOL> self . value = max ( value - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> callback ( * partial_args , ** partial_kwargs ) <EOL> return True <EOL> def release ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> waiter , args , kwargs = self . _pop_waiter ( ) <EOL> except IndexError : <EOL> self . value = min ( self . value + <NUM_LIT:1> , self . initial_value ) <EOL> else : <EOL> waiter ( * args , ** kwargs ) <EOL> def grow ( self , n = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . initial_value += n <EOL> self . value += n <EOL> [ self . release ( ) for _ in range ( n ) ] <EOL> def shrink ( self , n = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . initial_value = max ( self . initial_value - n , <NUM_LIT:0> ) <EOL> self . value = max ( self . value - n , <NUM_LIT:0> ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _waiting . clear ( ) <EOL> self . value = self . initial_value <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> self . __class__ . __name__ , id ( self ) , self . value , len ( self . _waiting ) , <EOL> ) <EOL> class DummyLock ( object ) : <EOL> """<STR_LIT>""" <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , * exc_info ) : <EOL> pass </s>
