<s> import itertools <EOL> import time <EOL> class TimeoutException ( Exception ) : <EOL> pass <EOL> class CashDrawerException ( Exception ) : <EOL> pass <EOL> class TimeoutHelper ( object ) : <EOL> def __init__ ( self , timeout = <NUM_LIT:1> ) : <EOL> self . timeout = <NUM_LIT:1> <EOL> self . set ( ) <EOL> def set ( self ) : <EOL> self . _mark = time . time ( ) <EOL> def check ( self ) : <EOL> if self . timeout > <NUM_LIT:0> : <EOL> if time . time ( ) - self . _mark > self . timeout : <EOL> raise TimeoutException ( '<STR_LIT>' % self . timeout ) <EOL> return False <EOL> def chunks ( iterable , size ) : <EOL> def chunk_factory ( iterable , size ) : <EOL> args = [ iter ( iterable ) ] * size <EOL> return itertools . izip_longest ( * args , fillvalue = None ) <EOL> for chunk in chunk_factory ( iterable , size ) : <EOL> yield '<STR_LIT>' . join ( [ e for e in chunk if e is not None ] ) <EOL> raise StopIteration ( ) <EOL> def hexdump ( data ) : <EOL> def _cut ( sequence , size ) : <EOL> for i in xrange ( <NUM_LIT:0> , len ( sequence ) , size ) : <EOL> yield sequence [ i : i + size ] <EOL> _hex = lambda seq : [ '<STR_LIT>' . format ( b ) for b in seq ] <EOL> _chr = lambda seq : [ chr ( b ) if <NUM_LIT:32> <= b <= <NUM_LIT> else '<STR_LIT:.>' for b in seq ] <EOL> raw_data = map ( ord , data ) <EOL> hexpanel = [ '<STR_LIT:U+0020>' . join ( line ) for line in _cut ( _hex ( raw_data ) , <NUM_LIT:16> ) ] <EOL> chrpanel = [ '<STR_LIT>' . join ( line ) for line in _cut ( _chr ( raw_data ) , <NUM_LIT:16> ) ] <EOL> hexpanel [ - <NUM_LIT:1> ] = hexpanel [ - <NUM_LIT:1> ] + ( chr ( <NUM_LIT:32> ) * ( <NUM_LIT> - len ( hexpanel [ - <NUM_LIT:1> ] ) ) ) <EOL> chrpanel [ - <NUM_LIT:1> ] = chrpanel [ - <NUM_LIT:1> ] + ( chr ( <NUM_LIT:32> ) * ( <NUM_LIT:16> - len ( chrpanel [ - <NUM_LIT:1> ] ) ) ) <EOL> return '<STR_LIT:\n>' . join ( '<STR_LIT>' % ( h , c ) for h , c in zip ( hexpanel , chrpanel ) ) <EOL> def is_value_in ( constants_group , value ) : <EOL> """<STR_LIT>""" <EOL> for const_value , label in constants_group : <EOL> if const_value == value : <EOL> return True <EOL> return False </s>
