<s> import py <EOL> import sys <EOL> from inspect import CO_VARARGS , CO_VARKEYWORDS <EOL> builtin_repr = repr <EOL> reprlib = py . builtin . _tryimport ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> from traceback import format_exception_only <EOL> else : <EOL> from py . _code . _py2traceback import format_exception_only <EOL> class Code ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rawcode ) : <EOL> if not hasattr ( rawcode , "<STR_LIT>" ) : <EOL> rawcode = py . code . getrawcode ( rawcode ) <EOL> try : <EOL> self . filename = rawcode . co_filename <EOL> self . firstlineno = rawcode . co_firstlineno - <NUM_LIT:1> <EOL> self . name = rawcode . co_name <EOL> except AttributeError : <EOL> raise TypeError ( "<STR_LIT>" % ( rawcode , ) ) <EOL> self . raw = rawcode <EOL> def __eq__ ( self , other ) : <EOL> return self . raw == other . raw <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> @ property <EOL> def path ( self ) : <EOL> """<STR_LIT>""" <EOL> p = py . path . local ( self . raw . co_filename ) <EOL> if not p . check ( ) : <EOL> p = self . raw . co_filename <EOL> return p <EOL> @ property <EOL> def fullsource ( self ) : <EOL> """<STR_LIT>""" <EOL> from py . _code import source <EOL> full , _ = source . findsource ( self . raw ) <EOL> return full <EOL> def source ( self ) : <EOL> """<STR_LIT>""" <EOL> return py . code . Source ( self . raw ) <EOL> def getargs ( self , var = False ) : <EOL> """<STR_LIT>""" <EOL> raw = self . raw <EOL> argcount = raw . co_argcount <EOL> if var : <EOL> argcount += raw . co_flags & CO_VARARGS <EOL> argcount += raw . co_flags & CO_VARKEYWORDS <EOL> return raw . co_varnames [ : argcount ] <EOL> class Frame ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , frame ) : <EOL> self . lineno = frame . f_lineno - <NUM_LIT:1> <EOL> self . f_globals = frame . f_globals <EOL> self . f_locals = frame . f_locals <EOL> self . raw = frame <EOL> self . code = py . code . Code ( frame . f_code ) <EOL> @ property <EOL> def statement ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . code . fullsource is None : <EOL> return py . code . Source ( "<STR_LIT>" ) <EOL> return self . code . fullsource . getstatement ( self . lineno ) <EOL> def eval ( self , code , ** vars ) : <EOL> """<STR_LIT>""" <EOL> f_locals = self . f_locals . copy ( ) <EOL> f_locals . update ( vars ) <EOL> return eval ( code , self . f_globals , f_locals ) <EOL> def exec_ ( self , code , ** vars ) : <EOL> """<STR_LIT>""" <EOL> f_locals = self . f_locals . copy ( ) <EOL> f_locals . update ( vars ) <EOL> py . builtin . exec_ ( code , self . f_globals , f_locals ) <EOL> def repr ( self , object ) : <EOL> """<STR_LIT>""" <EOL> return py . io . saferepr ( object ) <EOL> def is_true ( self , object ) : <EOL> return object <EOL> def getargs ( self , var = False ) : <EOL> """<STR_LIT>""" <EOL> retval = [ ] <EOL> for arg in self . code . getargs ( var ) : <EOL> try : <EOL> retval . append ( ( arg , self . f_locals [ arg ] ) ) <EOL> except KeyError : <EOL> pass <EOL> return retval <EOL> class TracebackEntry ( object ) : <EOL> """<STR_LIT>""" <EOL> _repr_style = None <EOL> exprinfo = None <EOL> def __init__ ( self , rawentry ) : <EOL> self . _rawentry = rawentry <EOL> self . lineno = rawentry . tb_lineno - <NUM_LIT:1> <EOL> def set_repr_style ( self , mode ) : <EOL> assert mode in ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . _repr_style = mode <EOL> @ property <EOL> def frame ( self ) : <EOL> return py . code . Frame ( self . _rawentry . tb_frame ) <EOL> @ property <EOL> def relline ( self ) : <EOL> return self . lineno - self . frame . code . firstlineno <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . frame . code . path , self . lineno + <NUM_LIT:1> ) <EOL> @ property <EOL> def statement ( self ) : <EOL> """<STR_LIT>""" <EOL> source = self . frame . code . fullsource <EOL> return source . getstatement ( self . lineno ) <EOL> @ property <EOL> def path ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . frame . code . path <EOL> def getlocals ( self ) : <EOL> return self . frame . f_locals <EOL> locals = property ( getlocals , None , None , "<STR_LIT>" ) <EOL> def reinterpret ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . exprinfo is None : <EOL> source = str ( self . statement ) . strip ( ) <EOL> x = py . code . _reinterpret ( source , self . frame , should_fail = True ) <EOL> if not isinstance ( x , str ) : <EOL> raise TypeError ( "<STR_LIT>" % ( x , ) ) <EOL> self . exprinfo = x <EOL> return self . exprinfo <EOL> def getfirstlinesource ( self ) : <EOL> return max ( self . frame . code . firstlineno , <NUM_LIT:0> ) <EOL> def getsource ( self , astcache = None ) : <EOL> """<STR_LIT>""" <EOL> from py . _code . source import getstatementrange_ast <EOL> source = self . frame . code . fullsource <EOL> if source is None : <EOL> return None <EOL> key = astnode = None <EOL> if astcache is not None : <EOL> key = self . frame . code . path <EOL> if key is not None : <EOL> astnode = astcache . get ( key , None ) <EOL> start = self . getfirstlinesource ( ) <EOL> try : <EOL> astnode , _ , end = getstatementrange_ast ( self . lineno , source , <EOL> astnode = astnode ) <EOL> except SyntaxError : <EOL> end = self . lineno + <NUM_LIT:1> <EOL> else : <EOL> if key is not None : <EOL> astcache [ key ] = astnode <EOL> return source [ start : end ] <EOL> source = property ( getsource ) <EOL> def ishidden ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . frame . f_locals [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> try : <EOL> return self . frame . f_globals [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> return False <EOL> def __str__ ( self ) : <EOL> try : <EOL> fn = str ( self . path ) <EOL> except py . error . Error : <EOL> fn = '<STR_LIT>' <EOL> name = self . frame . code . name <EOL> try : <EOL> line = str ( self . statement ) . lstrip ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> line = "<STR_LIT>" <EOL> return "<STR_LIT>" % ( fn , self . lineno + <NUM_LIT:1> , name , line ) <EOL> def name ( self ) : <EOL> return self . frame . code . raw . co_name <EOL> name = property ( name , None , None , "<STR_LIT>" ) <EOL> class Traceback ( list ) : <EOL> """<STR_LIT>""" <EOL> Entry = TracebackEntry <EOL> def __init__ ( self , tb ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( tb , '<STR_LIT>' ) : <EOL> def f ( cur ) : <EOL> while cur is not None : <EOL> yield self . Entry ( cur ) <EOL> cur = cur . tb_next <EOL> list . __init__ ( self , f ( tb ) ) <EOL> else : <EOL> list . __init__ ( self , tb ) <EOL> def cut ( self , path = None , lineno = None , firstlineno = None , excludepath = None ) : <EOL> """<STR_LIT>""" <EOL> for x in self : <EOL> code = x . frame . code <EOL> codepath = code . path <EOL> if ( ( path is None or codepath == path ) and <EOL> ( excludepath is None or not hasattr ( codepath , '<STR_LIT>' ) or <EOL> not codepath . relto ( excludepath ) ) and <EOL> ( lineno is None or x . lineno == lineno ) and <EOL> ( firstlineno is None or x . frame . code . firstlineno == firstlineno ) ) : <EOL> return Traceback ( x . _rawentry ) <EOL> return self <EOL> def __getitem__ ( self , key ) : <EOL> val = super ( Traceback , self ) . __getitem__ ( key ) <EOL> if isinstance ( key , type ( slice ( <NUM_LIT:0> ) ) ) : <EOL> val = self . __class__ ( val ) <EOL> return val <EOL> def filter ( self , fn = lambda x : not x . ishidden ( ) ) : <EOL> """<STR_LIT>""" <EOL> return Traceback ( filter ( fn , self ) ) <EOL> def getcrashentry ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( - <NUM_LIT:1> , - len ( self ) - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> entry = self [ i ] <EOL> if not entry . ishidden ( ) : <EOL> return entry <EOL> return self [ - <NUM_LIT:1> ] <EOL> def recursionindex ( self ) : <EOL> """<STR_LIT>""" <EOL> cache = { } <EOL> for i , entry in enumerate ( self ) : <EOL> key = entry . frame . code . path , id ( entry . frame . code . raw ) , entry . lineno <EOL> l = cache . setdefault ( key , [ ] ) <EOL> if l : <EOL> f = entry . frame <EOL> loc = f . f_locals <EOL> for otherloc in l : <EOL> if f . is_true ( f . eval ( co_equal , <EOL> __recursioncache_locals_1 = loc , <EOL> __recursioncache_locals_2 = otherloc ) ) : <EOL> return i <EOL> l . append ( entry . frame . f_locals ) <EOL> return None <EOL> co_equal = compile ( '<STR_LIT>' , <EOL> '<STR_LIT:?>' , '<STR_LIT>' ) <EOL> class ExceptionInfo ( object ) : <EOL> """<STR_LIT>""" <EOL> _striptext = '<STR_LIT>' <EOL> def __init__ ( self , tup = None , exprinfo = None ) : <EOL> if tup is None : <EOL> tup = sys . exc_info ( ) <EOL> if exprinfo is None and isinstance ( tup [ <NUM_LIT:1> ] , AssertionError ) : <EOL> exprinfo = getattr ( tup [ <NUM_LIT:1> ] , '<STR_LIT>' , None ) <EOL> if exprinfo is None : <EOL> exprinfo = str ( tup [ <NUM_LIT:1> ] ) <EOL> if exprinfo and exprinfo . startswith ( '<STR_LIT>' ) : <EOL> self . _striptext = '<STR_LIT>' <EOL> self . _excinfo = tup <EOL> self . type = tup [ <NUM_LIT:0> ] <EOL> self . value = tup [ <NUM_LIT:1> ] <EOL> self . tb = tup [ <NUM_LIT:2> ] <EOL> self . typename = self . type . __name__ <EOL> self . traceback = py . code . Traceback ( self . tb ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . typename , len ( self . traceback ) ) <EOL> def exconly ( self , tryshort = False ) : <EOL> """<STR_LIT>""" <EOL> lines = format_exception_only ( self . type , self . value ) <EOL> text = '<STR_LIT>' . join ( lines ) <EOL> text = text . rstrip ( ) <EOL> if tryshort : <EOL> if text . startswith ( self . _striptext ) : <EOL> text = text [ len ( self . _striptext ) : ] <EOL> return text <EOL> def errisinstance ( self , exc ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( self . value , exc ) <EOL> def _getreprcrash ( self ) : <EOL> exconly = self . exconly ( tryshort = True ) <EOL> entry = self . traceback . getcrashentry ( ) <EOL> path , lineno = entry . frame . code . raw . co_filename , entry . lineno <EOL> return ReprFileLocation ( path , lineno + <NUM_LIT:1> , exconly ) <EOL> def getrepr ( self , showlocals = False , style = "<STR_LIT>" , <EOL> abspath = False , tbfilter = True , funcargs = False ) : <EOL> """<STR_LIT>""" <EOL> if style == '<STR_LIT>' : <EOL> return ReprExceptionInfo ( ReprTracebackNative ( <EOL> py . std . traceback . format_exception ( <EOL> self . type , <EOL> self . value , <EOL> self . traceback [ <NUM_LIT:0> ] . _rawentry , <EOL> ) ) , self . _getreprcrash ( ) ) <EOL> fmt = FormattedExcinfo ( showlocals = showlocals , style = style , <EOL> abspath = abspath , tbfilter = tbfilter , funcargs = funcargs ) <EOL> return fmt . repr_excinfo ( self ) <EOL> def __str__ ( self ) : <EOL> entry = self . traceback [ - <NUM_LIT:1> ] <EOL> loc = ReprFileLocation ( entry . path , entry . lineno + <NUM_LIT:1> , self . exconly ( ) ) <EOL> return str ( loc ) <EOL> def __unicode__ ( self ) : <EOL> entry = self . traceback [ - <NUM_LIT:1> ] <EOL> loc = ReprFileLocation ( entry . path , entry . lineno + <NUM_LIT:1> , self . exconly ( ) ) <EOL> return unicode ( loc ) <EOL> class FormattedExcinfo ( object ) : <EOL> """<STR_LIT>""" <EOL> flow_marker = "<STR_LIT:>>" <EOL> fail_marker = "<STR_LIT:E>" <EOL> def __init__ ( self , showlocals = False , style = "<STR_LIT>" , abspath = True , tbfilter = True , funcargs = False ) : <EOL> self . showlocals = showlocals <EOL> self . style = style <EOL> self . tbfilter = tbfilter <EOL> self . funcargs = funcargs <EOL> self . abspath = abspath <EOL> self . astcache = { } <EOL> def _getindent ( self , source ) : <EOL> try : <EOL> s = str ( source . getstatement ( len ( source ) - <NUM_LIT:1> ) ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> try : <EOL> s = str ( source [ - <NUM_LIT:1> ] ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:4> + ( len ( s ) - len ( s . lstrip ( ) ) ) <EOL> def _getentrysource ( self , entry ) : <EOL> source = entry . getsource ( self . astcache ) <EOL> if source is not None : <EOL> source = source . deindent ( ) <EOL> return source <EOL> def _saferepr ( self , obj ) : <EOL> return py . io . saferepr ( obj ) <EOL> def repr_args ( self , entry ) : <EOL> if self . funcargs : <EOL> args = [ ] <EOL> for argname , argvalue in entry . frame . getargs ( var = True ) : <EOL> args . append ( ( argname , self . _saferepr ( argvalue ) ) ) <EOL> return ReprFuncArgs ( args ) <EOL> def get_source ( self , source , line_index = - <NUM_LIT:1> , excinfo = None , short = False ) : <EOL> """<STR_LIT>""" <EOL> lines = [ ] <EOL> if source is None or line_index >= len ( source . lines ) : <EOL> source = py . code . Source ( "<STR_LIT>" ) <EOL> line_index = <NUM_LIT:0> <EOL> if line_index < <NUM_LIT:0> : <EOL> line_index += len ( source ) <EOL> space_prefix = "<STR_LIT:U+0020>" <EOL> if short : <EOL> lines . append ( space_prefix + source . lines [ line_index ] . strip ( ) ) <EOL> else : <EOL> for line in source . lines [ : line_index ] : <EOL> lines . append ( space_prefix + line ) <EOL> lines . append ( self . flow_marker + "<STR_LIT:U+0020>" + source . lines [ line_index ] ) <EOL> for line in source . lines [ line_index + <NUM_LIT:1> : ] : <EOL> lines . append ( space_prefix + line ) <EOL> if excinfo is not None : <EOL> indent = <NUM_LIT:4> if short else self . _getindent ( source ) <EOL> lines . extend ( self . get_exconly ( excinfo , indent = indent , markall = True ) ) <EOL> return lines <EOL> def get_exconly ( self , excinfo , indent = <NUM_LIT:4> , markall = False ) : <EOL> lines = [ ] <EOL> indent = "<STR_LIT:U+0020>" * indent <EOL> exlines = excinfo . exconly ( tryshort = True ) . split ( '<STR_LIT:\n>' ) <EOL> failindent = self . fail_marker + indent [ <NUM_LIT:1> : ] <EOL> for line in exlines : <EOL> lines . append ( failindent + line ) <EOL> if not markall : <EOL> failindent = indent <EOL> return lines <EOL> def repr_locals ( self , locals ) : <EOL> if self . showlocals : <EOL> lines = [ ] <EOL> keys = [ loc for loc in locals if loc [ <NUM_LIT:0> ] != "<STR_LIT:@>" ] <EOL> keys . sort ( ) <EOL> for name in keys : <EOL> value = locals [ name ] <EOL> if name == '<STR_LIT>' : <EOL> lines . append ( "<STR_LIT>" ) <EOL> else : <EOL> str_repr = self . _saferepr ( value ) <EOL> lines . append ( "<STR_LIT>" % ( name , str_repr ) ) <EOL> return ReprLocals ( lines ) <EOL> def repr_traceback_entry ( self , entry , excinfo = None ) : <EOL> source = self . _getentrysource ( entry ) <EOL> if source is None : <EOL> source = py . code . Source ( "<STR_LIT>" ) <EOL> line_index = <NUM_LIT:0> <EOL> else : <EOL> line_index = entry . lineno - max ( entry . getfirstlinesource ( ) , <NUM_LIT:0> ) <EOL> lines = [ ] <EOL> style = entry . _repr_style <EOL> if style is None : <EOL> style = self . style <EOL> if style in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> short = style == "<STR_LIT>" <EOL> reprargs = self . repr_args ( entry ) if not short else None <EOL> s = self . get_source ( source , line_index , excinfo , short = short ) <EOL> lines . extend ( s ) <EOL> if short : <EOL> message = "<STR_LIT>" % ( entry . name ) <EOL> else : <EOL> message = excinfo and excinfo . typename or "<STR_LIT>" <EOL> path = self . _makepath ( entry . path ) <EOL> filelocrepr = ReprFileLocation ( path , entry . lineno + <NUM_LIT:1> , message ) <EOL> localsrepr = None <EOL> if not short : <EOL> localsrepr = self . repr_locals ( entry . locals ) <EOL> return ReprEntry ( lines , reprargs , localsrepr , filelocrepr , style ) <EOL> if excinfo : <EOL> lines . extend ( self . get_exconly ( excinfo , indent = <NUM_LIT:4> ) ) <EOL> return ReprEntry ( lines , None , None , None , style ) <EOL> def _makepath ( self , path ) : <EOL> if not self . abspath : <EOL> try : <EOL> np = py . path . local ( ) . bestrelpath ( path ) <EOL> except OSError : <EOL> return path <EOL> if len ( np ) < len ( str ( path ) ) : <EOL> path = np <EOL> return path <EOL> def repr_traceback ( self , excinfo ) : <EOL> traceback = excinfo . traceback <EOL> if self . tbfilter : <EOL> traceback = traceback . filter ( ) <EOL> recursionindex = None <EOL> if excinfo . errisinstance ( RuntimeError ) : <EOL> if "<STR_LIT>" in str ( excinfo . value ) : <EOL> recursionindex = traceback . recursionindex ( ) <EOL> last = traceback [ - <NUM_LIT:1> ] <EOL> entries = [ ] <EOL> extraline = None <EOL> for index , entry in enumerate ( traceback ) : <EOL> einfo = ( last == entry ) and excinfo or None <EOL> reprentry = self . repr_traceback_entry ( entry , einfo ) <EOL> entries . append ( reprentry ) <EOL> if index == recursionindex : <EOL> extraline = "<STR_LIT>" <EOL> break <EOL> return ReprTraceback ( entries , extraline , style = self . style ) <EOL> def repr_excinfo ( self , excinfo ) : <EOL> reprtraceback = self . repr_traceback ( excinfo ) <EOL> reprcrash = excinfo . _getreprcrash ( ) <EOL> return ReprExceptionInfo ( reprtraceback , reprcrash ) <EOL> class TerminalRepr : <EOL> def __str__ ( self ) : <EOL> s = self . __unicode__ ( ) <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> s = s . encode ( '<STR_LIT:utf-8>' ) <EOL> return s <EOL> def __unicode__ ( self ) : <EOL> io = py . io . TextIO ( ) <EOL> tw = py . io . TerminalWriter ( file = io ) <EOL> self . toterminal ( tw ) <EOL> return io . getvalue ( ) . strip ( ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , id ( self ) ) <EOL> class ReprExceptionInfo ( TerminalRepr ) : <EOL> def __init__ ( self , reprtraceback , reprcrash ) : <EOL> self . reprtraceback = reprtraceback <EOL> self . reprcrash = reprcrash <EOL> self . sections = [ ] <EOL> def addsection ( self , name , content , sep = "<STR_LIT:->" ) : <EOL> self . sections . append ( ( name , content , sep ) ) <EOL> def toterminal ( self , tw ) : <EOL> self . reprtraceback . toterminal ( tw ) <EOL> for name , content , sep in self . sections : <EOL> tw . sep ( sep , name ) <EOL> tw . line ( content ) <EOL> class ReprTraceback ( TerminalRepr ) : <EOL> entrysep = "<STR_LIT>" <EOL> def __init__ ( self , reprentries , extraline , style ) : <EOL> self . reprentries = reprentries <EOL> self . extraline = extraline <EOL> self . style = style <EOL> def toterminal ( self , tw ) : <EOL> last_style = None <EOL> for i , entry in enumerate ( self . reprentries ) : <EOL> if entry . style == "<STR_LIT>" : <EOL> tw . line ( "<STR_LIT>" ) <EOL> entry . toterminal ( tw ) <EOL> if i < len ( self . reprentries ) - <NUM_LIT:1> : <EOL> next_entry = self . reprentries [ i + <NUM_LIT:1> ] <EOL> if entry . style == "<STR_LIT>" or entry . style == "<STR_LIT>" and next_entry . style == "<STR_LIT>" : <EOL> tw . sep ( self . entrysep ) <EOL> if self . extraline : <EOL> tw . line ( self . extraline ) <EOL> class ReprTracebackNative ( ReprTraceback ) : <EOL> def __init__ ( self , tblines ) : <EOL> self . style = "<STR_LIT>" <EOL> self . reprentries = [ ReprEntryNative ( tblines ) ] <EOL> self . extraline = None <EOL> class ReprEntryNative ( TerminalRepr ) : <EOL> style = "<STR_LIT>" <EOL> def __init__ ( self , tblines ) : <EOL> self . lines = tblines <EOL> def toterminal ( self , tw ) : <EOL> tw . write ( "<STR_LIT>" . join ( self . lines ) ) <EOL> class ReprEntry ( TerminalRepr ) : <EOL> localssep = "<STR_LIT>" <EOL> def __init__ ( self , lines , reprfuncargs , reprlocals , filelocrepr , style ) : <EOL> self . lines = lines <EOL> self . reprfuncargs = reprfuncargs <EOL> self . reprlocals = reprlocals <EOL> self . reprfileloc = filelocrepr <EOL> self . style = style <EOL> def toterminal ( self , tw ) : <EOL> if self . style == "<STR_LIT>" : <EOL> self . reprfileloc . toterminal ( tw ) <EOL> for line in self . lines : <EOL> red = line . startswith ( "<STR_LIT>" ) <EOL> tw . line ( line , bold = True , red = red ) <EOL> return <EOL> if self . reprfuncargs : <EOL> self . reprfuncargs . toterminal ( tw ) <EOL> for line in self . lines : <EOL> red = line . startswith ( "<STR_LIT>" ) <EOL> tw . line ( line , bold = True , red = red ) <EOL> if self . reprlocals : <EOL> tw . line ( "<STR_LIT>" ) <EOL> self . reprlocals . toterminal ( tw ) <EOL> if self . reprfileloc : <EOL> if self . lines : <EOL> tw . line ( "<STR_LIT>" ) <EOL> self . reprfileloc . toterminal ( tw ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( "<STR_LIT:\n>" . join ( self . lines ) , <EOL> self . reprlocals , <EOL> self . reprfileloc ) <EOL> class ReprFileLocation ( TerminalRepr ) : <EOL> def __init__ ( self , path , lineno , message ) : <EOL> self . path = str ( path ) <EOL> self . lineno = lineno <EOL> self . message = message <EOL> def toterminal ( self , tw ) : <EOL> msg = self . message <EOL> i = msg . find ( "<STR_LIT:\n>" ) <EOL> if i != - <NUM_LIT:1> : <EOL> msg = msg [ : i ] <EOL> tw . line ( "<STR_LIT>" % ( self . path , self . lineno , msg ) ) <EOL> class ReprLocals ( TerminalRepr ) : <EOL> def __init__ ( self , lines ) : <EOL> self . lines = lines <EOL> def toterminal ( self , tw ) : <EOL> for line in self . lines : <EOL> tw . line ( line ) <EOL> class ReprFuncArgs ( TerminalRepr ) : <EOL> def __init__ ( self , args ) : <EOL> self . args = args <EOL> def toterminal ( self , tw ) : <EOL> if self . args : <EOL> linesofar = "<STR_LIT>" <EOL> for name , value in self . args : <EOL> ns = "<STR_LIT>" % ( name , value ) <EOL> if len ( ns ) + len ( linesofar ) + <NUM_LIT:2> > tw . fullwidth : <EOL> if linesofar : <EOL> tw . line ( linesofar ) <EOL> linesofar = ns <EOL> else : <EOL> if linesofar : <EOL> linesofar += "<STR_LIT:U+002CU+0020>" + ns <EOL> else : <EOL> linesofar = ns <EOL> if linesofar : <EOL> tw . line ( linesofar ) <EOL> tw . line ( "<STR_LIT>" ) <EOL> oldbuiltins = { } <EOL> def patch_builtins ( assertion = True , compile = True ) : <EOL> """<STR_LIT>""" <EOL> if assertion : <EOL> from py . _code import assertion <EOL> l = oldbuiltins . setdefault ( '<STR_LIT>' , [ ] ) <EOL> l . append ( py . builtin . builtins . AssertionError ) <EOL> py . builtin . builtins . AssertionError = assertion . AssertionError <EOL> if compile : <EOL> l = oldbuiltins . setdefault ( '<STR_LIT>' , [ ] ) <EOL> l . append ( py . builtin . builtins . compile ) <EOL> py . builtin . builtins . compile = py . code . compile <EOL> def unpatch_builtins ( assertion = True , compile = True ) : <EOL> """<STR_LIT>""" <EOL> if assertion : <EOL> py . builtin . builtins . AssertionError = oldbuiltins [ '<STR_LIT>' ] . pop ( ) <EOL> if compile : <EOL> py . builtin . builtins . compile = oldbuiltins [ '<STR_LIT>' ] . pop ( ) <EOL> def getrawcode ( obj , trycall = True ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return obj . __code__ <EOL> except AttributeError : <EOL> obj = getattr ( obj , '<STR_LIT>' , obj ) <EOL> obj = getattr ( obj , '<STR_LIT>' , obj ) <EOL> obj = getattr ( obj , '<STR_LIT>' , obj ) <EOL> obj = getattr ( obj , '<STR_LIT>' , obj ) <EOL> if trycall and not hasattr ( obj , '<STR_LIT>' ) : <EOL> if hasattr ( obj , '<STR_LIT>' ) and not py . std . inspect . isclass ( obj ) : <EOL> x = getrawcode ( obj . __call__ , trycall = False ) <EOL> if hasattr ( x , '<STR_LIT>' ) : <EOL> return x <EOL> return obj </s>
