#NEWLINE# def structured_traceback( self , etype , evalue , etb , tb_offset = None , context = 5 ) : #NEWLINE# #INDENT# 'Return a nice text document describing the traceback.' #NEWLINE# tb_offset = ( self . tb_offset if ( tb_offset is None ) else tb_offset ) #NEWLINE# try : #NEWLINE# #INDENT# etype = etype . __name__ #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# Colors = self . Colors #NEWLINE# ColorsNormal = Colors . Normal #NEWLINE# col_scheme = self . color_scheme_table . active_scheme_name #NEWLINE# indent = ( ' ' * INDENT_SIZE ) #NEWLINE# em_normal = ( '%s\n%s%s' % ( Colors . valEm , indent , ColorsNormal ) ) #NEWLINE# undefined = ( '%sundefined%s' % ( Colors . em , ColorsNormal ) ) #NEWLINE# exc = ( '%s%s%s' % ( Colors . excName , etype , ColorsNormal ) ) #NEWLINE# def text_repr( value ) : #NEWLINE# #INDENT# 'Hopefully pretty robust repr equivalent.' #NEWLINE# try : #NEWLINE# #INDENT# return pydoc . text . repr ( value ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return repr ( value ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# name = getattr ( value , '__name__' , None ) #NEWLINE# if name : #NEWLINE# #INDENT# return text_repr ( name ) #NEWLINE# #UNINDENT# klass = getattr ( value , '__class__' , None ) #NEWLINE# if klass : #NEWLINE# #INDENT# return ( '%s instance' % text_repr ( klass ) ) #NEWLINE# #UNINDENT# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return 'UNRECOVERABLE REPR FAILURE' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# def eqrepr( value , repr = text_repr ) : #NEWLINE# #INDENT# return ( '=%s' % repr ( value ) ) #NEWLINE# #UNINDENT# def nullrepr( value , repr = text_repr ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# etype = etype . __name__ #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if self . long_header : #NEWLINE# #INDENT# pyver = ( ( ( 'Python ' + sys . version . split ( ) [ 0 ] ) + ': ' ) + sys . executable ) #NEWLINE# date = time . ctime ( time . time ( ) ) #NEWLINE# head = ( '%s%s%s\n%s%s%s\n%s' % ( Colors . topline , ( '-' * 75 ) , ColorsNormal , exc , ( ' ' * ( ( 75 - len ( str ( etype ) ) ) - len ( pyver ) ) ) , pyver , date . rjust ( 75 ) ) ) #NEWLINE# head += '\nA problem occured executing Python code.  Here is the sequence of function\ncalls leading up to the error, with the most recent (innermost) call last.' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# head = ( '%s%s%s\n%s%s' % ( Colors . topline , ( '-' * 75 ) , ColorsNormal , exc , 'Traceback (most recent call last)' . rjust ( ( 75 - len ( str ( etype ) ) ) ) ) ) #NEWLINE# #UNINDENT# frames = [ ] #NEWLINE# try : #NEWLINE# #INDENT# records = _fixed_getinnerframes ( etb , context , tb_offset ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# inspect_error ( ) #NEWLINE# traceback . print_exc ( file = self . ostream ) #NEWLINE# info ( '\nUnfortunately, your original traceback can not be constructed.\n' ) #NEWLINE# return '' #NEWLINE# #UNINDENT# tpl_link = ( '%s%%s%s' % ( Colors . filenameEm , ColorsNormal ) ) #NEWLINE# tpl_call = ( 'in %s%%s%s%%s%s' % ( Colors . vName , Colors . valEm , ColorsNormal ) ) #NEWLINE# tpl_call_fail = ( 'in %s%%s%s(***failed resolving arguments***)%s' % ( Colors . vName , Colors . valEm , ColorsNormal ) ) #NEWLINE# tpl_local_var = ( '%s%%s%s' % ( Colors . vName , ColorsNormal ) ) #NEWLINE# tpl_global_var = ( '%sglobal%s %s%%s%s' % ( Colors . em , ColorsNormal , Colors . vName , ColorsNormal ) ) #NEWLINE# tpl_name_val = ( '%%s %s= %%s%s' % ( Colors . valEm , ColorsNormal ) ) #NEWLINE# tpl_line = ( '%s%%s%s %%s' % ( Colors . lineno , ColorsNormal ) ) #NEWLINE# tpl_line_em = ( '%s%%s%s %%s%s' % ( Colors . linenoEm , Colors . line , ColorsNormal ) ) #NEWLINE# abspath = os . path . abspath #NEWLINE# for ( frame , file , lnum , func , lines , index ) in records : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# file = ( ( file and abspath ( file ) ) or '?' ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# link = ( tpl_link % file ) #NEWLINE# try : #NEWLINE# #INDENT# ( args , varargs , varkw , locals ) = inspect . getargvalues ( frame ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# inspect_error ( ) #NEWLINE# traceback . print_exc ( file = self . ostream ) #NEWLINE# info ( "\nIPython's exception reporting continues...\n" ) #NEWLINE# #UNINDENT# if ( func == '?' ) : #NEWLINE# #INDENT# call = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# var_repr = ( ( self . include_vars and eqrepr ) or nullrepr ) #NEWLINE# try : #NEWLINE# #INDENT# call = ( tpl_call % ( func , inspect . formatargvalues ( args , varargs , varkw , locals , formatvalue = var_repr ) ) ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# call = ( tpl_call_fail % func ) #NEWLINE# #UNINDENT# #UNINDENT# names = [ ] #NEWLINE# def tokeneater( token_type , token , start , end , line ) : #NEWLINE# #INDENT# 'Stateful tokeneater which builds dotted names.\n\n                The list of names it appends to (from the enclosing scope) can\n                contain repeated composite names.  This is unavoidable, since\n                there is no way to disambguate partial dotted structures until\n                the full list is known.  The caller is responsible for pruning\n                the final list of duplicates before using it.' #NEWLINE# if ( token == '.' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# names [ ( - 1 ) ] += '.' #NEWLINE# tokeneater . name_cont = True #NEWLINE# return #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( ( token_type == tokenize . NAME ) and ( token not in keyword . kwlist ) ) : #NEWLINE# #INDENT# if tokeneater . name_cont : #NEWLINE# #INDENT# names [ ( - 1 ) ] += token #NEWLINE# tokeneater . name_cont = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# names . append ( token ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( token_type == tokenize . NEWLINE ) : #NEWLINE# #INDENT# raise IndexError #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# tokeneater . name_cont = False #NEWLINE# def linereader( file = file , lnum = [ lnum ] , getline = linecache . getline ) : #NEWLINE# #INDENT# line = getline ( file , lnum [ 0 ] ) #NEWLINE# lnum [ 0 ] += 1 #NEWLINE# return line #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# for atoken in tokenize . _tokenize ( linereader , None ) : #NEWLINE# #INDENT# tokeneater ( * atoken ) #NEWLINE# #UNINDENT# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except UnicodeDecodeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except tokenize . TokenError as msg : #NEWLINE# #INDENT# _m = ( 'An unexpected error occurred while tokenizing input\nThe following traceback may be corrupted or invalid\nThe error message is: %s\n' % msg ) #NEWLINE# error ( _m ) #NEWLINE# #UNINDENT# unique_names = uniq_stable ( names ) #NEWLINE# lvals = [ ] #NEWLINE# if self . include_vars : #NEWLINE# #INDENT# for name_full in unique_names : #NEWLINE# #INDENT# name_base = name_full . split ( '.' , 1 ) [ 0 ] #NEWLINE# if ( name_base in frame . f_code . co_varnames ) : #NEWLINE# #INDENT# if ( name_base in locals ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# value = repr ( eval ( name_full , locals ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# value = undefined #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# value = undefined #NEWLINE# #UNINDENT# name = ( tpl_local_var % name_full ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name_base in frame . f_globals ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# value = repr ( eval ( name_full , frame . f_globals ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# value = undefined #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# value = undefined #NEWLINE# #UNINDENT# name = ( tpl_global_var % name_full ) #NEWLINE# #UNINDENT# lvals . append ( ( tpl_name_val % ( name , value ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if lvals : #NEWLINE# #INDENT# lvals = ( '%s%s' % ( indent , em_normal . join ( lvals ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lvals = '' #NEWLINE# #UNINDENT# level = ( '%s %s\n' % ( link , call ) ) #NEWLINE# if ( index is None ) : #NEWLINE# #INDENT# frames . append ( level ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# frames . append ( ( '%s%s' % ( level , '' . join ( _format_traceback_lines ( lnum , index , lines , Colors , lvals , col_scheme ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# ( etype_str , evalue_str ) = list ( map ( str , ( etype , evalue ) ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# ( etype , evalue ) = ( str , sys . exc_info ( ) [ : 2 ] ) #NEWLINE# ( etype_str , evalue_str ) = list ( map ( str , ( etype , evalue ) ) ) #NEWLINE# #UNINDENT# exception = [ ( '%s%s%s: %s' % ( Colors . excName , etype_str , ColorsNormal , evalue_str ) ) ] #NEWLINE# if records : #NEWLINE# #INDENT# ( filepath , lnum ) = records [ ( - 1 ) ] [ 1 : 3 ] #NEWLINE# filepath = os . path . abspath ( filepath ) #NEWLINE# ipinst = ipapi . get ( ) #NEWLINE# if ( ipinst is not None ) : #NEWLINE# #INDENT# ipinst . hooks . synchronize_with_editor ( filepath , lnum , 0 ) #NEWLINE# #UNINDENT# #UNINDENT# return ( ( [ head ] + frames ) + [ '' . join ( exception [ 0 ] ) ] )