<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> class ExtensionImporter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , module_choices , wrapper_module ) : <EOL> self . module_choices = module_choices <EOL> self . wrapper_module = wrapper_module <EOL> self . prefix = wrapper_module + '<STR_LIT:.>' <EOL> self . prefix_cutoff = wrapper_module . count ( '<STR_LIT:.>' ) + <NUM_LIT:1> <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ . __module__ == other . __class__ . __module__ and self . __class__ . __name__ == other . __class__ . __name__ and self . wrapper_module == other . wrapper_module and self . module_choices == other . module_choices <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def install ( self ) : <EOL> sys . meta_path [ : ] = [ x for x in sys . meta_path if self != x ] + [ self ] <EOL> def find_module ( self , fullname , path = None ) : <EOL> if fullname . startswith ( self . prefix ) : <EOL> return self <EOL> def load_module ( self , fullname ) : <EOL> if fullname in sys . modules : <EOL> return sys . modules [ fullname ] <EOL> modname = fullname . split ( '<STR_LIT:.>' , self . prefix_cutoff ) [ self . prefix_cutoff ] <EOL> for path in self . module_choices : <EOL> realname = path % modname <EOL> try : <EOL> __import__ ( realname ) <EOL> except ImportError : <EOL> exc_type , exc_value , tb = sys . exc_info ( ) <EOL> sys . modules . pop ( fullname , None ) <EOL> if self . is_important_traceback ( realname , tb ) : <EOL> raise exc_type , exc_value , tb . tb_next <EOL> continue <EOL> module = sys . modules [ fullname ] = sys . modules [ realname ] <EOL> if '<STR_LIT:.>' not in modname : <EOL> setattr ( sys . modules [ self . wrapper_module ] , modname , module ) <EOL> return module <EOL> raise ImportError ( '<STR_LIT>' % fullname ) <EOL> def is_important_traceback ( self , important_module , tb ) : <EOL> """<STR_LIT>""" <EOL> while tb is not None : <EOL> if self . is_important_frame ( important_module , tb ) : <EOL> return True <EOL> tb = tb . tb_next <EOL> return False <EOL> def is_important_frame ( self , important_module , tb ) : <EOL> """<STR_LIT>""" <EOL> g = tb . tb_frame . f_globals <EOL> if '<STR_LIT>' not in g : <EOL> return False <EOL> module_name = g [ '<STR_LIT>' ] <EOL> if module_name == important_module : <EOL> return True <EOL> filename = os . path . abspath ( tb . tb_frame . f_code . co_filename ) <EOL> test_string = os . path . sep + important_module . replace ( '<STR_LIT:.>' , os . path . sep ) <EOL> return test_string + '<STR_LIT>' in filename or test_string + os . path . sep + '<STR_LIT>' in filename </s>
