B t `‚ã@s¤dZddlZddlZddlZddlZddlZddlZddlZyddlm Z Wn e k rlddlm Z YnXe  e ¡Z dd„Zd dd„Zd d „ZGd d „d ƒZdS)z’Simple traceback introspection. Used to add additional information to AssertionErrors in tests, so that failure messages may be more informative. éN)ÚStringIOc Cs\t d|¡x|jr|j}qW|j}t|ƒ\}}t||ƒ\}}tt d  |¡¡ƒ}t |j |j ƒ}x”|rôy"xt  |j¡D] }||ŽqvWWnft jk rî} zFt d| ¡| d¡|d8}tt d  |¡¡ƒ}t |j |j ƒ}wbWdd} ~ XYnXPqbWg} |jrR|j d¡} d} x>| D]6} | |kr6|  d| ¡n|  d | ¡| d7} qWd  | ¡S) zÞInspect 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 %sÚzTokenizer error: %sréNÚ z>> z )ÚlogÚdebugÚtb_nextÚtb_frameÚtbsourceÚfind_inspectable_linesrÚtextwrapÚdedentÚjoinÚExpanderÚf_localsÚ f_globalsÚtokenizeÚgenerate_tokensÚreadlineÚ TokenErrorÚpopÚexpanded_sourceÚsplitÚappend)ÚtbÚframeÚlinesZexc_lineZ inspect_linesZ mark_lineÚsrcÚexpÚtokÚeZpaddedZ exp_linesÚepÚline©r#ú2/tmp/pip-unpacked-wheel-cjhnoqsi/nose/inspector.pyÚinspect_tracebacks<        r%éc Cs|j}|j}|dkrð|d|d}t d||¡yt |¡\}}Wn tk rddgd}}YnŠX|}t|dƒ}tdt|t |ƒ|ƒƒ}||||…}|d|}t j dkrî|dkrîx@||d  ¡  d¡rì|d8}||||…}q¼Wn dgd}}t d||¡||fS) aGet source from a traceback object. A tuple of two things is returned: a list of lines of context from the source code, and the index of the current line within that list. The optional second argument specifies the number of lines of context to return, which are centered around the current line. .. Note :: This is adapted from inspect.py in the python 2.4 standard library, since a bug in the 2.3 version of inspect prevents it from correctly locating source lines in a traceback frame. rrézlineno: %s start: %sr)r'éú\z'tbsource lines '''%s''' around index %s)Ú tb_linenor rrÚinspectÚ findsourceÚIOErrorÚmaxÚminÚlenÚsysÚ version_infoÚstripÚendswith) rÚcontextÚlinenorÚstartrÚdummyÚindexZ all_linesr#r#r$r Bs*   r c Cs6t d¡}t d¡}t d¡}g}||}| |¡ ¡d}|t|ddƒ|…}| ¡||dt|dt|ƒƒ…} x0|D](} | | ¡ ¡d|kr¤| | ¡q~Pq~W| ¡| |¡t|ƒd} |  |¡} xL| D]D} | sø| | ¡ ¡d|kr|  | ¡s| | ¡|  | ¡} qØPqØWt   d|| ¡|| fS) a'Find lines in home that are inspectable. Walk back from the err line up to 3 lines, but don't walk back over changes in indent level. Walk forward up to 3 lines, counting \ separated lines as 1. Don't walk over changes in indent level (unless part of an extended line) z \\[\s\n]*$z :[\s\n]*$z^(\s*)réréz#Inspecting lines '''%s''' around %s) ÚreÚcompileÚmatchÚgroupsr.Úreverser/r0rÚsearchrr) rÚposZcntZdfÚindZ toinspectÚhomeZ home_indentÚbeforeÚafterr"Zhome_posÚ continuedr#r#r$r ns2            r c@s eZdZdZdd„Zdd„ZdS)rzxSimple expression expander. Uses tokenize to find the names and expands any that can be looked up in the frame. cCs||_||_d|_d|_dS)Nr)ÚlocalsÚglobalsÚlposr)ÚselfrHrIr#r#r$Ú__init__šszExpander.__init__c CsF|jdk rZ|d|jkr6|jd|d|j7_n$|d|jkrZ|jd|d7_|d|_|tjkrpnª|tjkr y(|j|}t|tjƒrš|}nt |ƒ}WnVt k rúy(|j |}t|tjƒrÒ|}nt |ƒ}Wnt k rô|}YnXYnX|j|7_n|j|7_t   d||dd…¡rB|jd7_dS)Nrú z\s+\\\nz \ )rJrrÚINDENTÚNAMErHÚ isinstanceÚ collectionsÚCallableÚreprÚKeyErrorrIr<r>)rKZttyperr7Úendr"Úvalr#r#r$Ú__call__ s4          zExpander.__call__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rLrWr#r#r#r$r–sr)r&)r[r+Úloggingr<r1r rrQÚiorÚ ImportErrorÚ getLoggerrXrr%r r rr#r#r#r$Ús  / ,(