U e* @sddlZddlZddlmZdZdZedZGdddeZ Gdd d e Z Gd d d e Z Gd d d Z GdddZGdddZddZdS)N)CodeTypez3.0.0) TracebackTracebackParseErrorFrameCodezO^\s*File "(?P.+)", line (?P\d+)(, in (?P.+))?$c@seZdZdZddZdS) _AttrDictcCs.z ||WStk r(t|dYnXdSN)KeyErrorAttributeError)selfnamerr|j|_|j|_d|_d|_d|_d|_d|_d|_d|_dS)Nrr@) co_filenameco_name co_argcountco_kwonlyargcount co_varnames co_nlocals co_stacksizeco_flagsco_firstlineno)r coderrr__init__%sz Code.__init__)rrr__doc__co_coder!rrrrrsrc@s&eZdZdZddddZddZdS)ra Class that replicates just enough of the builtin Frame object to enable serialization and traceback rendering. Args: get_locals (callable): A function that take a frame argument and returns a dict. See :class:`Traceback` class for example. N get_localscCsD|dkr in|||_dd|jD|_t|j|_|j|_dS)NcSsi|]\}}|dkr||qS)__file__rr).0kvrrr >sz"Frame.__init__..)f_locals f_globalsitemsrf_codef_lineno)r framer%rrrr!<s zFrame.__init__cCsdS)z For compatibility with PyPy 3.5; clear() was added to frame in Python 3.4 and is called by traceback.clear_frames(), which in turn is called by unittest.TestCase.assertRaises Nr)r rrrclearBsz Frame.clear)rrrr"r!r2rrrrr1s rc@sTeZdZdZdZddddZddZeZdd ZeZ e d d Z e dd dZ dS)ra' Class that wraps builtin Traceback objects. Args: get_locals (callable): A function that take a frame argument and returns a dict. Ideally you will only return exactly what you need, and only with simple types that can be json serializable. Example: .. code:: python def get_locals(frame): if frame.f_locals.get("__tracebackhide__"): return {"__tracebackhide__": True} else: return {} Nr$cCsrt|j|d|_t|j|_|j}|}t|}|dk rnt|}t|j|d|_t|j|_||_|}|j}q.dS)Nr$)rtb_frameint tb_linenotb_nexttypeobject__new__)r tbr%Zprev_tracebackcls tracebackrrrr!as   zTraceback.__init__cCs|}d}d}|r|jj}td|jdd|jjjd}t|dr^|jd|j|jddd }ns   @