<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> __date__ = '<STR_LIT>' <EOL> import sys , os , types , string , re , dis , imp , tokenize , linecache <EOL> def ismodule ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . ModuleType ) <EOL> def isclass ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . ClassType ) or hasattr ( object , '<STR_LIT>' ) <EOL> def ismethod ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . MethodType ) <EOL> def ismethoddescriptor ( object ) : <EOL> """<STR_LIT>""" <EOL> return ( hasattr ( object , "<STR_LIT>" ) <EOL> and not hasattr ( object , "<STR_LIT>" ) <EOL> and not ismethod ( object ) <EOL> and not isfunction ( object ) <EOL> and not isclass ( object ) ) <EOL> def isdatadescriptor ( object ) : <EOL> """<STR_LIT>""" <EOL> return ( hasattr ( object , "<STR_LIT>" ) and hasattr ( object , "<STR_LIT>" ) ) <EOL> def isfunction ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . FunctionType ) <EOL> def istraceback ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . TracebackType ) <EOL> def isframe ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . FrameType ) <EOL> def iscode ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . CodeType ) <EOL> def isbuiltin ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , types . BuiltinFunctionType ) <EOL> def isroutine ( object ) : <EOL> """<STR_LIT>""" <EOL> return ( isbuiltin ( object ) <EOL> or isfunction ( object ) <EOL> or ismethod ( object ) <EOL> or ismethoddescriptor ( object ) ) <EOL> def getmembers ( object , predicate = None ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> for key in dir ( object ) : <EOL> value = getattr ( object , key ) <EOL> if not predicate or predicate ( value ) : <EOL> results . append ( ( key , value ) ) <EOL> results . sort ( ) <EOL> return results <EOL> def classify_class_attrs ( cls ) : <EOL> """<STR_LIT>""" <EOL> mro = getmro ( cls ) <EOL> names = dir ( cls ) <EOL> result = [ ] <EOL> for name in names : <EOL> if name in cls . __dict__ : <EOL> obj = cls . __dict__ [ name ] <EOL> else : <EOL> obj = getattr ( cls , name ) <EOL> homecls = getattr ( obj , "<STR_LIT>" , None ) <EOL> if homecls is None : <EOL> for base in mro : <EOL> if name in base . __dict__ : <EOL> homecls = base <EOL> break <EOL> if homecls is not None and name in homecls . __dict__ : <EOL> obj = homecls . __dict__ [ name ] <EOL> obj_via_getattr = getattr ( cls , name ) <EOL> if isinstance ( obj , staticmethod ) : <EOL> kind = "<STR_LIT>" <EOL> elif isinstance ( obj , classmethod ) : <EOL> kind = "<STR_LIT>" <EOL> elif isinstance ( obj , property ) : <EOL> kind = "<STR_LIT>" <EOL> elif ( ismethod ( obj_via_getattr ) or <EOL> ismethoddescriptor ( obj_via_getattr ) ) : <EOL> kind = "<STR_LIT>" <EOL> else : <EOL> kind = "<STR_LIT:data>" <EOL> result . append ( ( name , kind , homecls , obj ) ) <EOL> return result <EOL> def _searchbases ( cls , accum ) : <EOL> if cls in accum : <EOL> return <EOL> accum . append ( cls ) <EOL> for base in cls . __bases__ : <EOL> _searchbases ( base , accum ) <EOL> def getmro ( cls ) : <EOL> "<STR_LIT>" <EOL> if hasattr ( cls , "<STR_LIT>" ) : <EOL> return cls . __mro__ <EOL> else : <EOL> result = [ ] <EOL> _searchbases ( cls , result ) <EOL> return tuple ( result ) <EOL> def indentsize ( line ) : <EOL> """<STR_LIT>""" <EOL> expline = string . expandtabs ( line ) <EOL> return len ( expline ) - len ( string . lstrip ( expline ) ) <EOL> def getdoc ( object ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> doc = object . __doc__ <EOL> except AttributeError : <EOL> return None <EOL> if not isinstance ( doc , types . StringTypes ) : <EOL> return None <EOL> try : <EOL> lines = string . split ( string . expandtabs ( doc ) , '<STR_LIT:\n>' ) <EOL> except UnicodeError : <EOL> return None <EOL> else : <EOL> margin = sys . maxint <EOL> for line in lines [ <NUM_LIT:1> : ] : <EOL> content = len ( string . lstrip ( line ) ) <EOL> if content : <EOL> indent = len ( line ) - content <EOL> margin = min ( margin , indent ) <EOL> if lines : <EOL> lines [ <NUM_LIT:0> ] = lines [ <NUM_LIT:0> ] . lstrip ( ) <EOL> if margin < sys . maxint : <EOL> for i in range ( <NUM_LIT:1> , len ( lines ) ) : lines [ i ] = lines [ i ] [ margin : ] <EOL> while lines and not lines [ - <NUM_LIT:1> ] : <EOL> lines . pop ( ) <EOL> while lines and not lines [ <NUM_LIT:0> ] : <EOL> lines . pop ( <NUM_LIT:0> ) <EOL> return string . join ( lines , '<STR_LIT:\n>' ) <EOL> def getfile ( object ) : <EOL> """<STR_LIT>""" <EOL> if ismodule ( object ) : <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> return object . __file__ <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if isclass ( object ) : <EOL> object = sys . modules . get ( object . __module__ ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> return object . __file__ <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if ismethod ( object ) : <EOL> object = object . im_func <EOL> if isfunction ( object ) : <EOL> object = object . func_code <EOL> if istraceback ( object ) : <EOL> object = object . tb_frame <EOL> if isframe ( object ) : <EOL> object = object . f_code <EOL> if iscode ( object ) : <EOL> return object . co_filename <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def getmoduleinfo ( path ) : <EOL> """<STR_LIT>""" <EOL> filename = os . path . basename ( path ) <EOL> suffixes = map ( lambda ( suffix , mode , mtype ) : <EOL> ( - len ( suffix ) , suffix , mode , mtype ) , imp . get_suffixes ( ) ) <EOL> suffixes . sort ( ) <EOL> for neglen , suffix , mode , mtype in suffixes : <EOL> if filename [ neglen : ] == suffix : <EOL> return filename [ : neglen ] , suffix , mode , mtype <EOL> def getmodulename ( path ) : <EOL> """<STR_LIT>""" <EOL> info = getmoduleinfo ( path ) <EOL> if info : return info [ <NUM_LIT:0> ] <EOL> def getsourcefile ( object ) : <EOL> """<STR_LIT>""" <EOL> filename = getfile ( object ) <EOL> if string . lower ( filename [ - <NUM_LIT:4> : ] ) in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> filename = filename [ : - <NUM_LIT:4> ] + '<STR_LIT>' <EOL> for suffix , mode , kind in imp . get_suffixes ( ) : <EOL> if '<STR_LIT:b>' in mode and string . lower ( filename [ - len ( suffix ) : ] ) == suffix : <EOL> return None <EOL> if os . path . exists ( filename ) : <EOL> return filename <EOL> def getabsfile ( object ) : <EOL> """<STR_LIT>""" <EOL> return os . path . normcase ( <EOL> os . path . abspath ( getsourcefile ( object ) or getfile ( object ) ) ) <EOL> modulesbyfile = { } <EOL> def getmodule ( object ) : <EOL> """<STR_LIT>""" <EOL> if ismodule ( object ) : <EOL> return object <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> return sys . modules . get ( object . __module__ ) <EOL> try : <EOL> file = getabsfile ( object ) <EOL> except TypeError : <EOL> return None <EOL> if file in modulesbyfile : <EOL> return sys . modules . get ( modulesbyfile [ file ] ) <EOL> for module in sys . modules . values ( ) : <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> modulesbyfile [ <EOL> os . path . realpath ( <EOL> getabsfile ( module ) ) ] = module . __name__ <EOL> if file in modulesbyfile : <EOL> return sys . modules . get ( modulesbyfile [ file ] ) <EOL> main = sys . modules [ '<STR_LIT:__main__>' ] <EOL> if not hasattr ( object , '<STR_LIT>' ) : <EOL> return None <EOL> if hasattr ( main , object . __name__ ) : <EOL> mainobject = getattr ( main , object . __name__ ) <EOL> if mainobject is object : <EOL> return main <EOL> builtin = sys . modules [ '<STR_LIT>' ] <EOL> if hasattr ( builtin , object . __name__ ) : <EOL> builtinobject = getattr ( builtin , object . __name__ ) <EOL> if builtinobject is object : <EOL> return builtin <EOL> def findsource ( object ) : <EOL> """<STR_LIT>""" <EOL> file = getsourcefile ( object ) or getfile ( object ) <EOL> lines = linecache . getlines ( file ) <EOL> if not lines : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> if ismodule ( object ) : <EOL> return lines , <NUM_LIT:0> <EOL> if isclass ( object ) : <EOL> name = object . __name__ <EOL> pat = re . compile ( r'<STR_LIT>' + name + r'<STR_LIT>' ) <EOL> for i in range ( len ( lines ) ) : <EOL> if pat . match ( lines [ i ] ) : return lines , i <EOL> else : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> if ismethod ( object ) : <EOL> object = object . im_func <EOL> if isfunction ( object ) : <EOL> object = object . func_code <EOL> if istraceback ( object ) : <EOL> object = object . tb_frame <EOL> if isframe ( object ) : <EOL> object = object . f_code <EOL> if iscode ( object ) : <EOL> if not hasattr ( object , '<STR_LIT>' ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> lnum = object . co_firstlineno - <NUM_LIT:1> <EOL> pat = re . compile ( r'<STR_LIT>' ) <EOL> while lnum > <NUM_LIT:0> : <EOL> if pat . match ( lines [ lnum ] ) : break <EOL> lnum = lnum - <NUM_LIT:1> <EOL> return lines , lnum <EOL> raise IOError ( '<STR_LIT>' ) <EOL> def getcomments ( object ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> lines , lnum = findsource ( object ) <EOL> except ( IOError , TypeError ) : <EOL> return None <EOL> if ismodule ( object ) : <EOL> start = <NUM_LIT:0> <EOL> if lines and lines [ <NUM_LIT:0> ] [ : <NUM_LIT:2> ] == '<STR_LIT>' : start = <NUM_LIT:1> <EOL> while start < len ( lines ) and string . strip ( lines [ start ] ) in [ '<STR_LIT>' , '<STR_LIT:#>' ] : <EOL> start = start + <NUM_LIT:1> <EOL> if start < len ( lines ) and lines [ start ] [ : <NUM_LIT:1> ] == '<STR_LIT:#>' : <EOL> comments = [ ] <EOL> end = start <EOL> while end < len ( lines ) and lines [ end ] [ : <NUM_LIT:1> ] == '<STR_LIT:#>' : <EOL> comments . append ( string . expandtabs ( lines [ end ] ) ) <EOL> end = end + <NUM_LIT:1> <EOL> return string . join ( comments , '<STR_LIT>' ) <EOL> elif lnum > <NUM_LIT:0> : <EOL> indent = indentsize ( lines [ lnum ] ) <EOL> end = lnum - <NUM_LIT:1> <EOL> if end >= <NUM_LIT:0> and string . lstrip ( lines [ end ] ) [ : <NUM_LIT:1> ] == '<STR_LIT:#>' and indentsize ( lines [ end ] ) == indent : <EOL> comments = [ string . lstrip ( string . expandtabs ( lines [ end ] ) ) ] <EOL> if end > <NUM_LIT:0> : <EOL> end = end - <NUM_LIT:1> <EOL> comment = string . lstrip ( string . expandtabs ( lines [ end ] ) ) <EOL> while comment [ : <NUM_LIT:1> ] == '<STR_LIT:#>' and indentsize ( lines [ end ] ) == indent : <EOL> comments [ : <NUM_LIT:0> ] = [ comment ] <EOL> end = end - <NUM_LIT:1> <EOL> if end < <NUM_LIT:0> : break <EOL> comment = string . lstrip ( string . expandtabs ( lines [ end ] ) ) <EOL> while comments and string . strip ( comments [ <NUM_LIT:0> ] ) == '<STR_LIT:#>' : <EOL> comments [ : <NUM_LIT:1> ] = [ ] <EOL> while comments and string . strip ( comments [ - <NUM_LIT:1> ] ) == '<STR_LIT:#>' : <EOL> comments [ - <NUM_LIT:1> : ] = [ ] <EOL> return string . join ( comments , '<STR_LIT>' ) <EOL> class ListReader : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , lines ) : <EOL> self . lines = lines <EOL> self . index = <NUM_LIT:0> <EOL> def readline ( self ) : <EOL> i = self . index <EOL> if i < len ( self . lines ) : <EOL> self . index = i + <NUM_LIT:1> <EOL> return self . lines [ i ] <EOL> else : return '<STR_LIT>' <EOL> class EndOfBlock ( Exception ) : pass <EOL> class BlockFinder : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . indent = <NUM_LIT:0> <EOL> self . islambda = False <EOL> self . started = False <EOL> self . passline = False <EOL> self . last = <NUM_LIT:0> <EOL> def tokeneater ( self , type , token , ( srow , scol ) , ( erow , ecol ) , line ) : <EOL> if not self . started : <EOL> if token in ( "<STR_LIT>" , "<STR_LIT:class>" , "<STR_LIT>" ) : <EOL> if token == "<STR_LIT>" : <EOL> self . islambda = True <EOL> self . started = True <EOL> self . passline = True <EOL> elif type == tokenize . NEWLINE : <EOL> self . passline = False <EOL> self . last = srow <EOL> elif self . passline : <EOL> pass <EOL> elif self . islambda : <EOL> raise EndOfBlock , self . last <EOL> elif type == tokenize . INDENT : <EOL> self . indent = self . indent + <NUM_LIT:1> <EOL> self . passline = True <EOL> elif type == tokenize . DEDENT : <EOL> self . indent = self . indent - <NUM_LIT:1> <EOL> if self . indent == <NUM_LIT:0> : <EOL> raise EndOfBlock , self . last <EOL> elif type == tokenize . NAME and scol == <NUM_LIT:0> : <EOL> raise EndOfBlock , self . last <EOL> def getblock ( lines ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> tokenize . tokenize ( ListReader ( lines ) . readline , BlockFinder ( ) . tokeneater ) <EOL> except EndOfBlock , eob : <EOL> return lines [ : eob . args [ <NUM_LIT:0> ] ] <EOL> return lines [ : <NUM_LIT:1> ] <EOL> def getsourcelines ( object ) : <EOL> """<STR_LIT>""" <EOL> lines , lnum = findsource ( object ) <EOL> if ismodule ( object ) : return lines , <NUM_LIT:0> <EOL> else : return getblock ( lines [ lnum : ] ) , lnum + <NUM_LIT:1> <EOL> def getsource ( object ) : <EOL> """<STR_LIT>""" <EOL> lines , lnum = getsourcelines ( object ) <EOL> return string . join ( lines , '<STR_LIT>' ) <EOL> def walktree ( classes , children , parent ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> classes . sort ( key = lambda c : ( c . __module__ , c . __name__ ) ) <EOL> for c in classes : <EOL> results . append ( ( c , c . __bases__ ) ) <EOL> if c in children : <EOL> results . append ( walktree ( children [ c ] , children , c ) ) <EOL> return results <EOL> def getclasstree ( classes , unique = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> children = { } <EOL> roots = [ ] <EOL> for c in classes : <EOL> if c . __bases__ : <EOL> for parent in c . __bases__ : <EOL> if not parent in children : <EOL> children [ parent ] = [ ] <EOL> children [ parent ] . append ( c ) <EOL> if unique and parent in classes : break <EOL> elif c not in roots : <EOL> roots . append ( c ) <EOL> for parent in children : <EOL> if parent not in classes : <EOL> roots . append ( parent ) <EOL> return walktree ( roots , children , None ) <EOL> CO_OPTIMIZED , CO_NEWLOCALS , CO_VARARGS , CO_VARKEYWORDS = <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:8> <EOL> def getargs ( co ) : <EOL> """<STR_LIT>""" <EOL> if not iscode ( co ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> code = co . co_code <EOL> nargs = co . co_argcount <EOL> names = co . co_varnames <EOL> args = list ( names [ : nargs ] ) <EOL> step = <NUM_LIT:0> <EOL> for i in range ( nargs ) : <EOL> if args [ i ] [ : <NUM_LIT:1> ] in [ '<STR_LIT>' , '<STR_LIT:.>' ] : <EOL> stack , remain , count = [ ] , [ ] , [ ] <EOL> while step < len ( code ) : <EOL> op = ord ( code [ step ] ) <EOL> step = step + <NUM_LIT:1> <EOL> if op >= dis . HAVE_ARGUMENT : <EOL> opname = dis . opname [ op ] <EOL> value = ord ( code [ step ] ) + ord ( code [ step + <NUM_LIT:1> ] ) * <NUM_LIT> <EOL> step = step + <NUM_LIT:2> <EOL> if opname in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> remain . append ( value ) <EOL> count . append ( value ) <EOL> elif opname == '<STR_LIT>' : <EOL> stack . append ( names [ value ] ) <EOL> if not remain : <EOL> stack [ <NUM_LIT:0> ] = [ stack [ <NUM_LIT:0> ] ] <EOL> break <EOL> else : <EOL> remain [ - <NUM_LIT:1> ] = remain [ - <NUM_LIT:1> ] - <NUM_LIT:1> <EOL> while remain [ - <NUM_LIT:1> ] == <NUM_LIT:0> : <EOL> remain . pop ( ) <EOL> size = count . pop ( ) <EOL> stack [ - size : ] = [ stack [ - size : ] ] <EOL> if not remain : break <EOL> remain [ - <NUM_LIT:1> ] = remain [ - <NUM_LIT:1> ] - <NUM_LIT:1> <EOL> if not remain : break <EOL> args [ i ] = stack [ <NUM_LIT:0> ] <EOL> varargs = None <EOL> if co . co_flags & CO_VARARGS : <EOL> varargs = co . co_varnames [ nargs ] <EOL> nargs = nargs + <NUM_LIT:1> <EOL> varkw = None <EOL> if co . co_flags & CO_VARKEYWORDS : <EOL> varkw = co . co_varnames [ nargs ] <EOL> return args , varargs , varkw <EOL> def getargspec ( func ) : <EOL> """<STR_LIT>""" <EOL> if ismethod ( func ) : <EOL> func = func . im_func <EOL> if not isfunction ( func ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> args , varargs , varkw = getargs ( func . func_code ) <EOL> return args , varargs , varkw , func . func_defaults <EOL> def getargvalues ( frame ) : <EOL> """<STR_LIT>""" <EOL> args , varargs , varkw = getargs ( frame . f_code ) <EOL> return args , varargs , varkw , frame . f_locals <EOL> def joinseq ( seq ) : <EOL> if len ( seq ) == <NUM_LIT:1> : <EOL> return '<STR_LIT:(>' + seq [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT:(>' + string . join ( seq , '<STR_LIT:U+002CU+0020>' ) + '<STR_LIT:)>' <EOL> def strseq ( object , convert , join = joinseq ) : <EOL> """<STR_LIT>""" <EOL> if type ( object ) in [ types . ListType , types . TupleType ] : <EOL> return join ( map ( lambda o , c = convert , j = join : strseq ( o , c , j ) , object ) ) <EOL> else : <EOL> return convert ( object ) <EOL> def formatargspec ( args , varargs = None , varkw = None , defaults = None , <EOL> formatarg = str , <EOL> formatvarargs = lambda name : '<STR_LIT:*>' + name , <EOL> formatvarkw = lambda name : '<STR_LIT>' + name , <EOL> formatvalue = lambda value : '<STR_LIT:=>' + repr ( value ) , <EOL> join = joinseq ) : <EOL> """<STR_LIT>""" <EOL> specs = [ ] <EOL> if defaults : <EOL> firstdefault = len ( args ) - len ( defaults ) <EOL> for i in range ( len ( args ) ) : <EOL> spec = strseq ( args [ i ] , formatarg , join ) <EOL> if defaults and i >= firstdefault : <EOL> spec = spec + formatvalue ( defaults [ i - firstdefault ] ) <EOL> specs . append ( spec ) <EOL> if varargs is not None : <EOL> specs . append ( formatvarargs ( varargs ) ) <EOL> if varkw is not None : <EOL> specs . append ( formatvarkw ( varkw ) ) <EOL> return '<STR_LIT:(>' + string . join ( specs , '<STR_LIT:U+002CU+0020>' ) + '<STR_LIT:)>' <EOL> def formatargvalues ( args , varargs , varkw , locals , <EOL> formatarg = str , <EOL> formatvarargs = lambda name : '<STR_LIT:*>' + name , <EOL> formatvarkw = lambda name : '<STR_LIT>' + name , <EOL> formatvalue = lambda value : '<STR_LIT:=>' + repr ( value ) , <EOL> join = joinseq ) : <EOL> """<STR_LIT>""" <EOL> def convert ( name , locals = locals , <EOL> formatarg = formatarg , formatvalue = formatvalue ) : <EOL> return formatarg ( name ) + formatvalue ( locals [ name ] ) <EOL> specs = [ ] <EOL> for i in range ( len ( args ) ) : <EOL> specs . append ( strseq ( args [ i ] , convert , join ) ) <EOL> if varargs : <EOL> specs . append ( formatvarargs ( varargs ) + formatvalue ( locals [ varargs ] ) ) <EOL> if varkw : <EOL> specs . append ( formatvarkw ( varkw ) + formatvalue ( locals [ varkw ] ) ) <EOL> return '<STR_LIT:(>' + string . join ( specs , '<STR_LIT:U+002CU+0020>' ) + '<STR_LIT:)>' <EOL> def getframeinfo ( frame , context = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if istraceback ( frame ) : <EOL> lineno = frame . tb_lineno <EOL> frame = frame . tb_frame <EOL> else : <EOL> lineno = frame . f_lineno <EOL> if not isframe ( frame ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> filename = getsourcefile ( frame ) or getfile ( frame ) <EOL> if context > <NUM_LIT:0> : <EOL> start = lineno - <NUM_LIT:1> - context // <NUM_LIT:2> <EOL> try : <EOL> lines , lnum = findsource ( frame ) <EOL> except IOError : <EOL> lines = index = None <EOL> else : <EOL> start = max ( start , <NUM_LIT:1> ) <EOL> start = max ( <NUM_LIT:0> , min ( start , len ( lines ) - context ) ) <EOL> lines = lines [ start : start + context ] <EOL> index = lineno - <NUM_LIT:1> - start <EOL> else : <EOL> lines = index = None <EOL> return ( filename , lineno , frame . f_code . co_name , lines , index ) <EOL> def getlineno ( frame ) : <EOL> """<STR_LIT>""" <EOL> return frame . f_lineno <EOL> def getouterframes ( frame , context = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> framelist = [ ] <EOL> while frame : <EOL> framelist . append ( ( frame , ) + getframeinfo ( frame , context ) ) <EOL> frame = frame . f_back <EOL> return framelist <EOL> def getinnerframes ( tb , context = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> framelist = [ ] <EOL> while tb : <EOL> framelist . append ( ( tb . tb_frame , ) + getframeinfo ( tb , context ) ) <EOL> tb = tb . tb_next <EOL> return framelist <EOL> currentframe = sys . _getframe <EOL> def stack ( context = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return getouterframes ( sys . _getframe ( <NUM_LIT:1> ) , context ) <EOL> def trace ( context = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return getinnerframes ( sys . exc_info ( ) [ <NUM_LIT:2> ] , context ) </s>
