ó K9•Qc@sÊdZddlZddlZddlZddlZddlZddlZyddlmZWn!e k r…ddlmZnXej e ƒZ d„Z dd„Zd„Zdd d „ƒYZdS( s’Simple traceback introspection. Used to add additional information to AssertionErrors in tests, so that failure messages may be more informative. iÿÿÿÿN(tStringIOcCs¾tjd|ƒx|jr(|j}qW|j}t|ƒ\}}t||ƒ\}}ttjdj |ƒƒƒ}t |j |j ƒ}x¬|r:y+x$t j|jƒD]}||Œq«WWnst jk r5} tjd| ƒ|jdƒ|d8}ttjdj |ƒƒƒ}t |j |j ƒ}qnXPqWg} |jr±|jjdƒ} d} xL| D]A} | |kr| jd| ƒn| jd| ƒ| d7} qiWndj | ƒS( sÞ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 '>>' sinspect traceback %stsTokenizer error: %siis s>> s (tlogtdebugttb_nextttb_framettbsourcetfind_inspectable_linesRttextwraptdedenttjointExpandertf_localst f_globalsttokenizetgenerate_tokenstreadlinet TokenErrortpoptexpanded_sourcetsplittappend(ttbtframetlinestexc_linet inspect_linest mark_linetsrctexpttoktetpaddedt exp_linesteptline((s2/sys/lib/python2.7/site-packages/nose/inspector.pytinspect_tracebacks<         ic Csc|j}|j}|dkr6|d|d}tjd||ƒytj|ƒ\}}Wn!tk rdgd}}qFX|}t|dƒ}tdt|t |ƒ|ƒƒ}||||!}|d|}t j d krF|dkrFx?||dj ƒj dƒr/|d8}||||!}qôWqFndgd}}tjd||ƒ||fS( sGet 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. iiislineno: %s start: %sRis\s'tbsource lines '''%s''' around index %s(ii(t tb_linenoRRRtinspectt findsourcetIOErrortmaxtmintlentsyst version_infotstriptendswith( RtcontexttlinenoRtstartRtdummytindext all_lines((s2/sys/lib/python2.7/site-packages/nose/inspector.pyRAs*    "  c Cs˜tjdƒ}tjdƒ}tjdƒ}g}||}|j|ƒjƒd}|t|ddƒ|!}|jƒ||dt|dt|ƒƒ!} x>|D]6} |j| ƒjƒd|krÚ|j| ƒq¥Pq¥W|jƒ|j|ƒt|ƒd} |j |ƒ} xc| D][} | sG|j| ƒjƒd|krv|j | ƒ rv|j| ƒ|j | ƒ} qPqWt j d|| ƒ|| fS( s'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) s \\[\s\n]*$s :[\s\n]*$s^(\s*)iiiis#Inspecting lines '''%s''' around %s( tretcompiletmatchtgroupsR)treverseR*R+RtsearchRR( Rtpostcnttdftindt toinspectthomet home_indenttbeforetafterR#thome_post continued((s2/sys/lib/python2.7/site-packages/nose/inspector.pyRms2   $    % R cBs eZdZd„Zd„ZRS(sxSimple expression expander. Uses tokenize to find the names and expands any that can be looked up in the frame. cCs(||_||_d|_d|_dS(NR(tlocalstglobalstNonetlposR(tselfRGRH((s2/sys/lib/python2.7/site-packages/nose/inspector.pyt__init__™s   cCs„|jdk rs|d|jkrC|jd|d|j7_qs|d|jkrs|jd|d7_qsn|d|_|tjkr’nÂ|tjkrEy2|j|}t|ƒrÆ|}n t|ƒ}Wn]t k r2y2|j |}t|ƒr|}n t|ƒ}Wq3t k r.|}q3XnX|j|7_n|j|7_t j d||dƒr€|jd7_ndS(Nit s\s+\\\ns \ ( RJRIRRtINDENTtNAMERGtcallabletreprtKeyErrorRHR6R8(RKtttypeRR2tendR#tval((s2/sys/lib/python2.7/site-packages/nose/inspector.pyt__call__Ÿs4 !         (t__name__t __module__t__doc__RLRV(((s2/sys/lib/python2.7/site-packages/nose/inspector.pyR •s ((RYR&tloggingR6R,RRt cStringIORt ImportErrort getLoggerRWRR$RRR (((s2/sys/lib/python2.7/site-packages/nose/inspector.pyts        / , (