<s> import sys <EOL> import traceback <EOL> import logging <EOL> def import_class ( import_str ) : <EOL> """<STR_LIT>""" <EOL> mod_str , _ , class_str = import_str . rpartition ( '<STR_LIT:.>' ) <EOL> logging . debug ( "<STR_LIT>" , mod_str ) <EOL> try : <EOL> __import__ ( mod_str ) <EOL> logging . debug ( "<STR_LIT>" , class_str ) <EOL> return getattr ( sys . modules [ mod_str ] , class_str ) <EOL> except AttributeError : <EOL> raise ImportError ( "<STR_LIT>" % ( class_str , mod_str ) ) <EOL> except ValueError as e : <EOL> logging . debug ( "<STR_LIT>" , e ) <EOL> raise ImportError ( '<STR_LIT>' % <EOL> ( class_str , <EOL> traceback . format_exception ( * sys . exc_info ( ) ) ) ) <EOL> except Exception as e : <EOL> logging . debug ( <EOL> "<STR_LIT>" , import_str , e ) <EOL> raise <EOL> def import_object ( import_str , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return import_class ( import_str ) ( * args , ** kwargs ) <EOL> def synchronized ( method ) : <EOL> def synchronized_method ( self , * arg , ** kws ) : <EOL> with self . lock : <EOL> return method ( self , * arg , ** kws ) <EOL> return synchronized_method <EOL> def enum ( * sequential , ** named ) : <EOL> enums = dict ( zip ( sequential , range ( len ( sequential ) ) ) , ** named ) <EOL> reverse = dict ( ( value , key ) for key , value in enums . iteritems ( ) ) <EOL> enums [ '<STR_LIT>' ] = reverse <EOL> return type ( '<STR_LIT>' , ( ) , enums ) <EOL> def getBoolean ( string ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( string , bool ) : <EOL> return string <EOL> assert ( isinstance ( string , str ) ) <EOL> return ( string . lower ( ) in [ "<STR_LIT:true>" , "<STR_LIT:yes>" , "<STR_LIT>" , "<STR_LIT:1>" ] ) <EOL> def plural ( x ) : <EOL> if len ( x ) > <NUM_LIT:1> : <EOL> return "<STR_LIT:s>" <EOL> else : <EOL> return "<STR_LIT>" </s>
