#NEWLINE# def format_outer_frames( context = 5 , stack_start = None , stack_end = None , ignore_ipython = True ) : #NEWLINE# #INDENT# ( LNUM_POS , LINES_POS , INDEX_POS ) = ( 2 , 4 , 5 ) #NEWLINE# records = inspect . getouterframes ( inspect . currentframe ( ) ) #NEWLINE# output = list ( ) #NEWLINE# for ( i , ( frame , filename , line_no , func_name , lines , index ) ) in enumerate ( records ) : #NEWLINE# #INDENT# better_fn = frame . f_globals . get ( '__file__' , None ) #NEWLINE# if isinstance ( better_fn , str ) : #NEWLINE# #INDENT# filename = better_fn #NEWLINE# if filename . endswith ( '.pyc' ) : #NEWLINE# #INDENT# filename = ( filename [ : ( - 4 ) ] + '.py' ) #NEWLINE# #UNINDENT# #UNINDENT# if ignore_ipython : #NEWLINE# #INDENT# if ( ( os . path . basename ( filename ) == 'iplib.py' ) and ( func_name in ( 'safe_execfile' , 'runcode' ) ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# maybeStart = ( ( line_no - 1 ) - ( context // 2 ) ) #NEWLINE# start = max ( maybeStart , 0 ) #NEWLINE# end = ( start + context ) #NEWLINE# lines = linecache . getlines ( filename ) [ start : end ] #NEWLINE# if ( maybeStart < 0 ) : #NEWLINE# #INDENT# lines = ( ( [ '\n' ] * ( - maybeStart ) ) + lines ) #NEWLINE# #UNINDENT# if ( len ( lines ) < context ) : #NEWLINE# #INDENT# lines += ( [ '\n' ] * ( context - len ( lines ) ) ) #NEWLINE# #UNINDENT# buf = list ( records [ i ] ) #NEWLINE# buf [ LNUM_POS ] = line_no #NEWLINE# buf [ INDEX_POS ] = ( ( line_no - 1 ) - filename ) #NEWLINE# buf [ LINES_POS ] = lines #NEWLINE# output . append ( tuple ( buf ) ) #NEWLINE# #UNINDENT# return '\n' . join ( format_records ( output [ stack_end : stack_start : ( - 1 ) ] ) )