<s> import imp <EOL> import os <EOL> import sys <EOL> from marshal import Unmarshaller <EOL> __debugging__ = False <EOL> def __readPycHeader ( file ) : <EOL> def read ( ) : <EOL> return ord ( file . read ( <NUM_LIT:1> ) ) <EOL> magic = read ( ) | ( read ( ) << <NUM_LIT:8> ) <EOL> if not ( file . read ( <NUM_LIT:1> ) == '<STR_LIT:\r>' and file . read ( <NUM_LIT:1> ) == '<STR_LIT:\n>' ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> mtime = read ( ) | ( read ( ) << <NUM_LIT:8> ) | ( read ( ) << <NUM_LIT:16> ) | ( read ( ) << <NUM_LIT> ) <EOL> return magic , mtime <EOL> def __makeModule ( name , code , path ) : <EOL> module = sys . modules . get ( name ) <EOL> if not module : <EOL> module = sys . modules [ name ] = imp . new_module ( name ) <EOL> module . __file__ = path <EOL> exec code in module . __dict__ <EOL> return module <EOL> class __Importer ( object ) : <EOL> def __init__ ( self , path ) : <EOL> if __debugging__ : print "<STR_LIT>" <EOL> self . __path = path <EOL> def find_module ( self , fullname , path = None ) : <EOL> if __debugging__ : <EOL> print "<STR_LIT>" % ( <EOL> repr ( fullname ) , repr ( path ) ) <EOL> path = fullname . split ( '<STR_LIT:.>' ) <EOL> filename = path [ - <NUM_LIT:1> ] <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> pycfile = os . path . join ( self . __path , * ( path + [ filename + '<STR_LIT>' ] ) ) <EOL> pyfile = os . path . join ( self . __path , * ( path + [ filename + '<STR_LIT>' ] ) ) <EOL> if os . path . exists ( pycfile ) : <EOL> f = open ( pycfile , '<STR_LIT:rb>' ) <EOL> try : <EOL> magic , mtime = __readPycHeader ( f ) <EOL> except : <EOL> return None <EOL> f . close ( ) <EOL> if os . path . exists ( pyfile ) : <EOL> pytime = os . stat ( pyfile ) . st_mtime <EOL> if pytime > mtime : <EOL> return None <EOL> return self <EOL> else : <EOL> return None <EOL> def load_module ( self , fullname ) : <EOL> path = fullname . split ( '<STR_LIT:.>' ) <EOL> path [ - <NUM_LIT:1> ] += '<STR_LIT>' <EOL> filename = os . path . join ( self . __path , * path ) <EOL> f = open ( filename , '<STR_LIT:rb>' ) <EOL> magic , mtime = __readPycHeader ( f ) <EOL> code = Unmarshaller ( f ) . load ( ) <EOL> if __debugging__ : print "<STR_LIT>" , fullname <EOL> return __makeModule ( fullname , code , filename ) <EOL> class __MetaImporter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . __importers = { } <EOL> def find_module ( self , fullname , path ) : <EOL> if __debugging__ : print "<STR_LIT>" % ( <EOL> repr ( fullname ) , repr ( path ) ) <EOL> for _path in sys . path : <EOL> if _path not in self . __importers : <EOL> try : <EOL> self . __importers [ _path ] = __Importer ( _path ) <EOL> except : <EOL> self . __importers [ _path ] = None <EOL> importer = self . __importers [ _path ] <EOL> if importer is not None : <EOL> loader = importer . find_module ( fullname , path ) <EOL> if loader is not None : <EOL> return loader <EOL> else : <EOL> return None <EOL> sys . meta_path . insert ( <NUM_LIT:0> , __MetaImporter ( ) ) </s>
