<s> """<STR_LIT>""" <EOL> import imp , marshal , os , sys <EOL> from coverage . backward import exec_code_object , open_source <EOL> from coverage . misc import ExceptionDuringRun , NoCode , NoSource <EOL> try : <EOL> BUILTINS = sys . modules [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> BUILTINS = sys . modules [ '<STR_LIT>' ] <EOL> def rsplit1 ( s , sep ) : <EOL> """<STR_LIT>""" <EOL> parts = s . split ( sep ) <EOL> return sep . join ( parts [ : - <NUM_LIT:1> ] ) , parts [ - <NUM_LIT:1> ] <EOL> def run_python_module ( modulename , args ) : <EOL> """<STR_LIT>""" <EOL> openfile = None <EOL> glo , loc = globals ( ) , locals ( ) <EOL> try : <EOL> try : <EOL> if '<STR_LIT:.>' in modulename : <EOL> packagename , name = rsplit1 ( modulename , '<STR_LIT:.>' ) <EOL> package = __import__ ( packagename , glo , loc , [ '<STR_LIT>' ] ) <EOL> searchpath = package . __path__ <EOL> else : <EOL> packagename , name = None , modulename <EOL> searchpath = None <EOL> openfile , pathname , _ = imp . find_module ( name , searchpath ) <EOL> if openfile is None and pathname is None : <EOL> raise NoSource ( <EOL> "<STR_LIT>" % modulename <EOL> ) <EOL> if openfile is None : <EOL> packagename = modulename <EOL> name = '<STR_LIT:__main__>' <EOL> package = __import__ ( packagename , glo , loc , [ '<STR_LIT>' ] ) <EOL> searchpath = package . __path__ <EOL> openfile , pathname , _ = imp . find_module ( name , searchpath ) <EOL> except ImportError : <EOL> _ , err , _ = sys . exc_info ( ) <EOL> raise NoSource ( str ( err ) ) <EOL> finally : <EOL> if openfile : <EOL> openfile . close ( ) <EOL> pathname = os . path . abspath ( pathname ) <EOL> args [ <NUM_LIT:0> ] = pathname <EOL> run_python_file ( pathname , args , package = packagename ) <EOL> def run_python_file ( filename , args , package = None ) : <EOL> """<STR_LIT>""" <EOL> old_main_mod = sys . modules [ '<STR_LIT:__main__>' ] <EOL> main_mod = imp . new_module ( '<STR_LIT:__main__>' ) <EOL> sys . modules [ '<STR_LIT:__main__>' ] = main_mod <EOL> main_mod . __file__ = filename <EOL> if package : <EOL> main_mod . __package__ = package <EOL> main_mod . __builtins__ = BUILTINS <EOL> old_argv = sys . argv <EOL> sys . argv = args <EOL> try : <EOL> if filename . endswith ( "<STR_LIT>" ) or filename . endswith ( "<STR_LIT>" ) : <EOL> code = make_code_from_pyc ( filename ) <EOL> else : <EOL> code = make_code_from_py ( filename ) <EOL> try : <EOL> exec_code_object ( code , main_mod . __dict__ ) <EOL> except SystemExit : <EOL> raise <EOL> except : <EOL> typ , err , tb = sys . exc_info ( ) <EOL> raise ExceptionDuringRun ( typ , err , tb . tb_next . tb_next ) <EOL> finally : <EOL> sys . modules [ '<STR_LIT:__main__>' ] = old_main_mod <EOL> sys . argv = old_argv <EOL> def make_code_from_py ( filename ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> source_file = open_source ( filename ) <EOL> except IOError : <EOL> raise NoSource ( "<STR_LIT>" % filename ) <EOL> try : <EOL> source = source_file . read ( ) <EOL> finally : <EOL> source_file . close ( ) <EOL> if not source or source [ - <NUM_LIT:1> ] != '<STR_LIT:\n>' : <EOL> source += '<STR_LIT:\n>' <EOL> code = compile ( source , filename , "<STR_LIT>" ) <EOL> return code <EOL> def make_code_from_pyc ( filename ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> fpyc = open ( filename , "<STR_LIT:rb>" ) <EOL> except IOError : <EOL> raise NoCode ( "<STR_LIT>" % filename ) <EOL> try : <EOL> magic = fpyc . read ( <NUM_LIT:4> ) <EOL> if magic != imp . get_magic ( ) : <EOL> raise NoCode ( "<STR_LIT>" ) <EOL> fpyc . read ( <NUM_LIT:4> ) <EOL> if sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:3> ) : <EOL> fpyc . read ( <NUM_LIT:4> ) <EOL> code = marshal . load ( fpyc ) <EOL> finally : <EOL> fpyc . close ( ) <EOL> return code </s>
