<s> '''<STR_LIT>''' <EOL> import functools <EOL> import inspect <EOL> import traceback <EOL> import time <EOL> import sys <EOL> def breakpoint ( scope = None , global_scope = None ) : <EOL> from IPython . config . loader import Config <EOL> ipy_config = Config ( ) <EOL> ipy_config . PromptManager . in_template = '<STR_LIT>' <EOL> ipy_config . PromptManager . in2_template = '<STR_LIT>' <EOL> ipy_config . PromptManager . out_template = '<STR_LIT>' <EOL> ipy_config . InteractiveShellEmbed . confirm_exit = False <EOL> import gevent <EOL> import select <EOL> import sys <EOL> def stdin_ready ( ) : <EOL> infds , outfds , erfds = select . select ( [ sys . stdin ] , [ ] , [ ] , <NUM_LIT:0> ) <EOL> if infds : <EOL> return True <EOL> else : <EOL> return False <EOL> def inputhook_gevent ( ) : <EOL> try : <EOL> while not stdin_ready ( ) : <EOL> gevent . sleep ( <NUM_LIT> ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> return <NUM_LIT:0> <EOL> from IPython . lib . inputhook import inputhook_manager <EOL> inputhook_manager . set_inputhook ( inputhook_gevent ) <EOL> inputhook_manager . _current_gui = '<STR_LIT>' <EOL> from IPython . frontend . terminal . embed import InteractiveShellEmbed <EOL> from mock import patch <EOL> if scope is not None : <EOL> from pyon . container . shell_api import get_shell_api <EOL> from pyon . container . cc import Container <EOL> locals ( ) . update ( scope ) <EOL> locals ( ) . update ( { '<STR_LIT>' : get_stack } ) <EOL> if Container . instance : <EOL> locals ( ) . update ( get_shell_api ( Container . instance ) ) <EOL> if global_scope is not None : <EOL> globals ( ) . update ( global_scope ) <EOL> from pyon . core . bootstrap import get_sys_name <EOL> with patch ( "<STR_LIT>" ) : <EOL> ipshell = InteractiveShellEmbed ( config = ipy_config , <EOL> banner1 = "<STR_LIT>" , <EOL> exit_msg = '<STR_LIT>' ) <EOL> stack = traceback . extract_stack ( limit = <NUM_LIT:2> ) <EOL> message = '<STR_LIT>' % stack [ <NUM_LIT:0> ] [ : - <NUM_LIT:1> ] <EOL> ipshell ( '<STR_LIT>' % ( get_sys_name ( ) , message ) ) <EOL> def debug_wrapper ( func ) : <EOL> @ functools . wraps ( func ) <EOL> def wrapper ( * args , ** kwargs ) : <EOL> try : <EOL> return func ( * args , ** kwargs ) <EOL> except : <EOL> from traceback import print_exc <EOL> print_exc ( ) <EOL> raise <EOL> return wrapper <EOL> def get_stack ( message = None , stack_first_frame = <NUM_LIT:1> , max_frames = <NUM_LIT:15> ) : <EOL> try : <EOL> stack = inspect . stack ( ) <EOL> frame_num = stack_first_frame <EOL> context = [ ] <EOL> while len ( stack ) > frame_num and frame_num < ( max_frames + stack_first_frame ) : <EOL> exec_line = "<STR_LIT>" % ( stack [ frame_num ] [ <NUM_LIT:1> ] , stack [ frame_num ] [ <NUM_LIT:2> ] , stack [ frame_num ] [ <NUM_LIT:3> ] ) <EOL> context . insert ( <NUM_LIT:0> , exec_line ) <EOL> if exec_line . endswith ( "<STR_LIT>" ) or exec_line . endswith ( "<STR_LIT>" ) or exec_line . endswith ( "<STR_LIT>" ) or exec_line . endswith ( "<STR_LIT>" ) or exec_line . endswith ( "<STR_LIT>" ) : <EOL> break <EOL> frame_num += <NUM_LIT:1> <EOL> stack_str = "<STR_LIT>" . join ( context ) <EOL> if message : <EOL> stack_str = message + "<STR_LIT:\n>" + stack_str <EOL> return stack_str <EOL> except Exception as ex : <EOL> stack_str = "<STR_LIT>" + str ( ex ) <EOL> if message : <EOL> stack_str = message + "<STR_LIT:\n>" + stack_str <EOL> return stack_str <EOL> _global_profile_t0 = time . time ( ) <EOL> _global_profile_level = <NUM_LIT:0> <EOL> def time_profile ( func ) : <EOL> @ functools . wraps ( func ) <EOL> def wrapper ( * args , ** kwargs ) : <EOL> global _global_profile_t0 <EOL> global _global_profile_level <EOL> indent = '<STR_LIT>' . join ( [ '<STR_LIT:U+0020>' for i in xrange ( _global_profile_level ) ] ) <EOL> t0 = time . time ( ) <EOL> sys . stdout . write ( '<STR_LIT>' % ( indent , func . __name__ ) ) <EOL> _global_profile_level += <NUM_LIT:1> <EOL> retval = func ( * args , ** kwargs ) <EOL> _global_profile_level -= <NUM_LIT:1> <EOL> sys . stdout . write ( '<STR_LIT>' % ( indent , time . time ( ) - t0 , indent , time . time ( ) - _global_profile_t0 ) ) <EOL> return retval <EOL> return wrapper <EOL> class TimeIt : <EOL> def __init__ ( self , message ) : <EOL> self . message = message <EOL> def __enter__ ( self ) : <EOL> global _global_profile_t0 <EOL> global _global_profile_level <EOL> self . t0 = time . time ( ) <EOL> indent = '<STR_LIT>' . join ( [ '<STR_LIT:U+0020>' for i in xrange ( _global_profile_level ) ] ) <EOL> sys . stdout . write ( '<STR_LIT>' % ( indent , self . message ) ) <EOL> _global_profile_level += <NUM_LIT:1> <EOL> def __exit__ ( self , type , value , traceback ) : <EOL> global _global_profile_t0 <EOL> global _global_profile_level <EOL> _global_profile_level -= <NUM_LIT:1> <EOL> indent = '<STR_LIT>' . join ( [ '<STR_LIT:U+0020>' for i in xrange ( _global_profile_level ) ] ) <EOL> sys . stdout . write ( '<STR_LIT>' % ( indent , time . time ( ) - self . t0 , indent , time . time ( ) - _global_profile_t0 ) ) </s>
