<s> """<STR_LIT>""" <EOL> from inspect import ismethod <EOL> from traceback import format_tb <EOL> class EventType ( type ) : <EOL> __cache__ = { } <EOL> def __new__ ( cls , name , bases , ns ) : <EOL> key = ( cls , name , bases ) <EOL> try : <EOL> return cls . __cache__ [ key ] <EOL> except KeyError : <EOL> cls = type . __new__ ( cls , name , bases , ns ) <EOL> setattr ( cls , "<STR_LIT:name>" , ns . get ( "<STR_LIT:name>" , cls . __name__ ) ) <EOL> return cls <EOL> class Event ( object ) : <EOL> __metaclass__ = EventType <EOL> channels = ( ) <EOL> "<STR_LIT>" <EOL> parent = None <EOL> notify = False <EOL> success = False <EOL> failure = False <EOL> complete = False <EOL> alert_done = False <EOL> waitingHandlers = <NUM_LIT:0> <EOL> @ classmethod <EOL> def create ( cls , _name , * args , ** kwargs ) : <EOL> return type ( cls ) ( _name , ( cls , ) , { } ) ( * args , ** kwargs ) <EOL> def child ( self , name , * args , ** kwargs ) : <EOL> e = Event . create ( <EOL> "<STR_LIT>" . format ( self . name , name ) , * args , ** kwargs <EOL> ) <EOL> e . parent = self <EOL> return e <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . args = list ( args ) <EOL> self . kwargs = kwargs <EOL> self . uid = None <EOL> self . value = None <EOL> self . handler = None <EOL> self . stopped = False <EOL> self . cancelled = False <EOL> if not hasattr ( self , '<STR_LIT:name>' ) : <EOL> self . name = self . __class__ . __name__ <EOL> def __getstate__ ( self ) : <EOL> odict = self . __dict__ . copy ( ) <EOL> del odict [ "<STR_LIT>" ] <EOL> return odict <EOL> def __setstate__ ( self , dict ) : <EOL> self . __dict__ . update ( dict ) <EOL> def __le__ ( self , other ) : <EOL> return False <EOL> def __gt__ ( self , other ) : <EOL> return False <EOL> def __repr__ ( self ) : <EOL> "<STR_LIT>" <EOL> if len ( self . channels ) > <NUM_LIT:1> : <EOL> channels = repr ( self . channels ) <EOL> elif len ( self . channels ) == <NUM_LIT:1> : <EOL> channels = str ( self . channels [ <NUM_LIT:0> ] ) <EOL> else : <EOL> channels = "<STR_LIT>" <EOL> data = "<STR_LIT>" % ( <EOL> "<STR_LIT:U+002CU+0020>" . join ( repr ( arg ) for arg in self . args ) , <EOL> "<STR_LIT:U+002CU+0020>" . join ( "<STR_LIT>" % ( k , repr ( v ) ) for k , v in self . kwargs . items ( ) ) <EOL> ) <EOL> return "<STR_LIT>" % ( self . name , channels , data ) <EOL> def __getitem__ ( self , x ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( x , int ) : <EOL> return self . args [ x ] <EOL> elif isinstance ( x , str ) : <EOL> return self . kwargs [ x ] <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % type ( x ) ) <EOL> def __setitem__ ( self , i , y ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( i , int ) : <EOL> self . args [ i ] = y <EOL> elif isinstance ( i , str ) : <EOL> self . kwargs [ i ] = y <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % type ( i ) ) <EOL> def cancel ( self ) : <EOL> """<STR_LIT>""" <EOL> self . cancelled = True <EOL> def stop ( self ) : <EOL> """<STR_LIT>""" <EOL> self . stopped = True <EOL> class exception ( Event ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , type , value , traceback , handler = None , fevent = None ) : <EOL> super ( exception , self ) . __init__ ( type , value , <EOL> self . format_traceback ( traceback ) , <EOL> handler = handler , fevent = fevent ) <EOL> def format_traceback ( self , traceback ) : <EOL> return format_tb ( traceback ) <EOL> class started ( Event ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , manager ) : <EOL> super ( started , self ) . __init__ ( manager ) <EOL> class stopped ( Event ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , manager ) : <EOL> super ( stopped , self ) . __init__ ( manager ) <EOL> class signal ( Event ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , signo , stack ) : <EOL> super ( signal , self ) . __init__ ( signo , stack ) <EOL> class registered ( Event ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , component , manager ) : <EOL> super ( registered , self ) . __init__ ( component , manager ) <EOL> class unregistered ( Event ) : <EOL> """<STR_LIT>""" <EOL> class generate_events ( Event ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , lock , max_wait ) : <EOL> super ( generate_events , self ) . __init__ ( ) <EOL> self . _time_left = max_wait <EOL> self . _lock = lock <EOL> @ property <EOL> def time_left ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _time_left <EOL> def reduce_time_left ( self , time_left ) : <EOL> """<STR_LIT>""" <EOL> with self . _lock : <EOL> if time_left >= <NUM_LIT:0> and ( self . _time_left < <NUM_LIT:0> <EOL> or self . _time_left > time_left ) : <EOL> self . _time_left = time_left <EOL> if self . _time_left == <NUM_LIT:0> and self . handler is not None : <EOL> m = getattr ( <EOL> getattr ( <EOL> self . handler , "<STR_LIT>" , getattr ( <EOL> self . handler , "<STR_LIT>" <EOL> ) <EOL> ) , <EOL> "<STR_LIT>" , None <EOL> ) <EOL> if m is not None and ismethod ( m ) : <EOL> m ( ) <EOL> @ property <EOL> def lock ( self ) : <EOL> return self . _lock </s>
