U e@sdZddlZddlZddlZddlZddlZddlZddlZzddlm Z Wn e k rlddlm Z YnXe e Z ddZd ddZd d ZGd d d ZdS)zSimple traceback introspection. Used to add additional information to AssertionErrors in tests, so that failure messages may be more informative. N)StringIOc CsRtd||jr|j}q |j}t|\}}t||\}}ttd |}t |j |j }|rzt |jD] }||qnWqt jk r} zLtd| |d|d8}ttd |}t |j |j }WYq\W5d} ~ XYqXqq\g} |jrH|jd} d} | D]6} | |kr.| d| n| d | | d7} qd | S) zInspect a traceback and its frame, returning source for the expression where the exception was raised, with simple variable replacement performed and the line on which the exception was raised marked with '>>' zinspect traceback %szTokenizer error: %srN z>> z )logdebugtb_nexttb_frametbsourcefind_inspectable_linesrtextwrapdedentjoinExpanderf_locals f_globalstokenizegenerate_tokensreadline TokenErrorpopexpanded_sourcesplitappend)tbframelinesZexc_lineZ inspect_linesZ mark_linesrcexptokepaddedZ exp_linesepliner$r@)rMttyperr8endr#valr$r$r%__call__s4          zExpander.__call__N)__name__ __module__ __qualname____doc__rNrZr$r$r$r%rsr)r')r^r,loggingr>r2r rrSior ImportError getLoggerr[rr&r r rr$r$r$r%s  / ,(