<s> """<STR_LIT>""" <EOL> import sys <EOL> import threading <EOL> import ctypes . util <EOL> def ctypes_find_library ( name , default ) : <EOL> """<STR_LIT>""" <EOL> module_path = None <EOL> try : <EOL> module_path = ctypes . util . find_library ( name ) <EOL> except ( OSError , IOError ) : <EOL> module_path = default <EOL> return module_path <EOL> def has_attribute ( ob , attribute ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( ob , attribute , None ) is not None <EOL> class DaemonThread ( threading . Thread ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> threading . Thread . __init__ ( self ) <EOL> if has_attribute ( self , '<STR_LIT>' ) : <EOL> self . daemon = True <EOL> else : <EOL> self . setDaemon ( True ) <EOL> self . _stopped_event = threading . Event ( ) <EOL> if not has_attribute ( self . _stopped_event , '<STR_LIT>' ) : <EOL> self . _stopped_event . is_set = self . _stopped_event . isSet <EOL> @ property <EOL> def stopped_event ( self ) : <EOL> return self . _stopped_event <EOL> def should_stop ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _stopped_event . is_set ( ) <EOL> def should_keep_running ( self ) : <EOL> """<STR_LIT>""" <EOL> return not self . _stopped_event . is_set ( ) <EOL> def on_thread_exit ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def stop ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _stopped_event . set ( ) <EOL> self . on_thread_exit ( ) <EOL> if not has_attribute ( DaemonThread , '<STR_LIT>' ) : <EOL> DaemonThread . is_alive = DaemonThread . isAlive <EOL> def load_module ( module_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> __import__ ( module_name ) <EOL> except ImportError : <EOL> raise ImportError ( '<STR_LIT>' % module_name ) <EOL> return sys . modules [ module_name ] <EOL> def load_class ( dotted_path ) : <EOL> """<STR_LIT>""" <EOL> dotted_path_split = dotted_path . split ( '<STR_LIT:.>' ) <EOL> if len ( dotted_path_split ) > <NUM_LIT:1> : <EOL> klass_name = dotted_path_split [ - <NUM_LIT:1> ] <EOL> module_name = '<STR_LIT:.>' . join ( dotted_path_split [ : - <NUM_LIT:1> ] ) <EOL> module = load_module ( module_name ) <EOL> if has_attribute ( module , klass_name ) : <EOL> klass = getattr ( module , klass_name ) <EOL> return klass <EOL> else : <EOL> raise AttributeError ( '<STR_LIT>' % ( <EOL> module_name , klass_name ) ) <EOL> else : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % dotted_path ) <EOL> def read_text_file ( file_path , mode = '<STR_LIT:rb>' ) : <EOL> """<STR_LIT>""" <EOL> return open ( file_path , mode ) . read ( ) </s>
