<s> """<STR_LIT>""" <EOL> def eval_import ( s ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT::>' not in s : <EOL> return simple_import ( s ) <EOL> module_name , expr = s . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> module = import_module ( module_name ) <EOL> obj = eval ( expr , module . __dict__ ) <EOL> return obj <EOL> def simple_import ( s ) : <EOL> """<STR_LIT>""" <EOL> parts = s . split ( '<STR_LIT:.>' ) <EOL> module = import_module ( parts [ <NUM_LIT:0> ] ) <EOL> name = parts [ <NUM_LIT:0> ] <EOL> parts = parts [ <NUM_LIT:1> : ] <EOL> last_import_error = None <EOL> while parts : <EOL> name += '<STR_LIT:.>' + parts [ <NUM_LIT:0> ] <EOL> try : <EOL> module = import_module ( name ) <EOL> parts = parts [ <NUM_LIT:1> : ] <EOL> except ImportError as e : <EOL> last_import_error = e <EOL> break <EOL> obj = module <EOL> while parts : <EOL> try : <EOL> obj = getattr ( module , parts [ <NUM_LIT:0> ] ) <EOL> except AttributeError : <EOL> raise ImportError ( <EOL> "<STR_LIT>" % ( parts [ <NUM_LIT:0> ] , module , last_import_error ) ) <EOL> parts = parts [ <NUM_LIT:1> : ] <EOL> return obj <EOL> def import_module ( s ) : <EOL> """<STR_LIT>""" <EOL> mod = __import__ ( s ) <EOL> parts = s . split ( '<STR_LIT:.>' ) <EOL> for part in parts [ <NUM_LIT:1> : ] : <EOL> mod = getattr ( mod , part ) <EOL> return mod <EOL> def try_import_module ( module_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return import_module ( module_name ) <EOL> except ImportError as e : <EOL> if not getattr ( e , '<STR_LIT:args>' , None ) : <EOL> raise <EOL> desc = e . args [ <NUM_LIT:0> ] <EOL> if not desc . startswith ( '<STR_LIT>' ) : <EOL> raise <EOL> desc = desc [ len ( '<STR_LIT>' ) : ] <EOL> parts = module_name . split ( '<STR_LIT:.>' ) <EOL> for i in range ( len ( parts ) ) : <EOL> if desc == '<STR_LIT:.>' . join ( parts [ i : ] ) : <EOL> return None <EOL> raise </s>
