<s> """<STR_LIT>""" <EOL> import imp <EOL> import os . path <EOL> import sys <EOL> BUILTINS = sys . modules [ '<STR_LIT>' ] <EOL> class ExceptionDuringRun ( Exception ) : <EOL> pass <EOL> class NoSource ( Exception ) : <EOL> pass <EOL> def run_python_file ( filename , args , package = None , collector = 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__ = sys . modules [ '<STR_LIT>' ] <EOL> old_argv = sys . argv <EOL> old_path0 = sys . path [ <NUM_LIT:0> ] <EOL> sys . argv = args <EOL> if package : <EOL> sys . path [ <NUM_LIT:0> ] = '<STR_LIT>' <EOL> else : <EOL> sys . path [ <NUM_LIT:0> ] = os . path . abspath ( os . path . dirname ( filename ) ) <EOL> try : <EOL> try : <EOL> source_file = open ( filename , '<STR_LIT>' ) <EOL> except IOError : <EOL> raise NoSource ( "<STR_LIT>" % filename ) <EOL> try : <EOL> source = source_file . read ( ) <EOL> finally : <EOL> source_file . close ( ) <EOL> if source [ - <NUM_LIT:1> ] != '<STR_LIT:\n>' : <EOL> source += '<STR_LIT:\n>' <EOL> code = compile ( source , filename , "<STR_LIT>" ) <EOL> try : <EOL> exec code in 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> sys . path [ <NUM_LIT:0> ] = old_path0 <EOL> def main ( argv = None ) : <EOL> from optparse import OptionParser <EOL> if argv is None : <EOL> argv = sys . argv [ <NUM_LIT:1> : ] <EOL> usage = "<STR_LIT>" <EOL> parser = OptionParser ( usage = usage ) <EOL> parser . allow_interspersed_args = False <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , default = None ) <EOL> if not argv : <EOL> parser . print_usage ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> sys . argv [ : ] = args <EOL> if len ( args ) > <NUM_LIT:0> : <EOL> progname = args [ <NUM_LIT:0> ] <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . dirname ( progname ) ) <EOL> from peek . collector import Collector <EOL> from peek . reporter import HTMLReporter <EOL> collector = Collector ( log = ( not options . output ) ) <EOL> collector . start ( ) <EOL> try : <EOL> run_python_file ( progname , args ) <EOL> finally : <EOL> collector . stop ( ) <EOL> reporter = HTMLReporter ( progname , collector , output = options . output ) <EOL> reporter . report ( ) <EOL> else : <EOL> parser . print_usage ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
