mò %U²Ic@s0dZdkZdkZdkZdddddddd d d d d ddgZddd„Zdd„Zd„Zddd„Z dd„Z dd„Z ddd„Z dd„Z d„Zd„Zddd„Zdd„Zddd„Zdddd„Zddd „Zddd!„Zd"„ZdS(#s@Extract, format and print information about Python stack traces.Nt extract_stackt extract_tbtformat_exceptiontformat_exception_onlyt format_listt format_stackt format_tbt print_exct format_exctprint_exceptiont print_lastt print_stacktprint_tbt tb_linenots cCs|i||ƒdS(N(tfiletwritetstrt terminator(RRR((t&/data/zmath/lib/python2.4/traceback.pyt_print scCsw|djo ti}nxV|D]N\}}}}t |d|||fƒ|ot |d|i ƒƒq!q!WdS(syPrint the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file.s File "%s", line %d, in %ss %sN( RtNonetsyststderrtextracted_listtfilenametlinenotnametlineRtstrip(RRRRRR((Rt print_lists  cCsfg}xY|D]Q\}}}}d|||f}|o|d|iƒ}n|i|ƒq W|S(s²Format a list of traceback entry tuples for printing. Given a list of tuples as returned by extract_tb() or extract_stack(), return a list of strings ready for printing. Each string in the resulting list corresponds to the item with the same index in the argument list. Each string ends in a newline; the strings may contain internal newlines as well, for those items whose source text line is not None. s File "%s", line %d, in %s s %s N( tlistRRRRRtitemRtappend(RRRRR RR((RRs c Cs|djo ti}n|djo!ttdƒo ti}qHnd}xÇ|dj o¹|djp ||joŸ|i }|i }|i }|i} |i}t|d| ||fƒti| ƒti| |ƒ}|ot|d|iƒƒn|i}|d}qQWdS(sPrint up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. ttracebacklimitis File "%s", line %d, in %ss iN(RRRRtlimitthasattrR"tnttbttb_frametfR Rtf_codetcot co_filenameRtco_nameRRt linecachet checkcachetgetlineRRttb_next( R&R#RR*RR(R%RRR((RR .s,   '       cCstt||ƒƒS(s6A shorthand for 'format_list(extract_stack(f, limit)).N(RRR&R#(R&R#((RRJsc Cs|djo!ttdƒo ti}q.ng}d}xÁ|dj o³|djp ||jo™|i}|i }|i }|i} |i}ti| ƒti| |ƒ}|o|iƒ}nd}|i| |||fƒ|i}|d}q=W|S(síReturn list of up to limit pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a quadruple (filename, line number, function name, text) representing the information that is usually printed for a stack trace. The text is a string with leading and trailing whitespace stripped; if the source is not available it is None. R"iiN(R#RR$RR"RR%R&R'R(R RR)R*R+RR,RR-R.R/RRR!R0( R&R#R*RR(RR%RRR((RRNs,  '       cCsŽ|djo ti}n|o!t|dƒt|||ƒnt||ƒ}x"|d D]}t||dƒq\Wt||ddƒdS(sùPrint exception up to 'limit' stack trace entries from 'tb' to 'file'. This differs from print_tb() in the following ways: (1) if traceback is not None, it prints a header "Traceback (most recent call last):"; (2) it prints the exception type and value after the stack trace; (3) if type is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret on the next line indicating the approximate position of the error. s"Traceback (most recent call last):iÿÿÿÿt RN( RRRRR&RR R#RtetypetvaluetlinesR(R2R3R&R#RR4R((RR ns     cCsD|o dg}|t||ƒ}ng}|t||ƒ}|S(szFormat a stack trace and the exception information. The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception(). s#Traceback (most recent call last): N(R&RRR#RR2R3(R2R3R&R#R((RRƒs c CsØg}t|ƒtijo |i}n|}|d jo|i t |ƒdƒn~|t jo%y|\}\}} } } Wnq‰X|p d}n|i d|| fƒ| d j oÆd}x3|t| ƒjo| |iƒo|d}qÈW|i d| iƒƒ| d j o\d}x>| || d!D]+}|iƒo||}q7|d}q7W|i d |ƒn|}q‰nt|ƒ}|o!|i d t |ƒ|fƒn|i d t |ƒƒ|S( s Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.last_type and sys.last_value. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is the always last string in the list. s ss File "%s", line %d iis %s s R1s%s^ s%s: %s s%s N(RttypeR2ttypest ClassTypet__name__tstypeR3RR!Rt SyntaxErrortmsgRRtoffsetRtitlentisspaceRtstct _some_str( R2R3R=RRARR;R@R9R<RR((RR”sF      $   !cCs-yt|ƒSWndt|ƒiSnXdS(Ns(RR3R5R8(R3((RRBÅscCs_|djo ti}nz/tiƒ\}}}t|||||ƒWdd}}}XdS(s¾Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'. (In fact, it uses sys.exc_info() to retrieve the same information in a thread-safe way.)N( RRRRtexc_infoR2R3R&R R#(R#RR3R2R&((RRÌs  cCsKz5tiƒ\}}}dit||||ƒƒSWdd}}}XdS(s%Like print_exc() but return a string.RN( RRCR2R3R&tjoinRR#R(R#R3R2R&((RRÙs  cCs=|djo ti}nttititi||ƒdS(snThis is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.N( RRRRR t last_typet last_valuetlast_tracebackR#(R#R((RR âs   cCsa|djo:y t‚WqGtj otiƒdii}qGXntt||ƒ|ƒdS(s÷Print a stack trace from its invocation point. The optional 'f' argument can be used to specify an alternate stack frame at which to start. The optional 'limit' and 'file' arguments have the same meaning as for print_exception(). iN( R(RtZeroDivisionErrorRRCR'tf_backRRR#R(R(R#R((RR ës  cCsZ|djo:y t‚WqGtj otiƒdii}qGXntt||ƒƒS(s5Shorthand for 'format_list(extract_stack(f, limit))'.iN( R(RRHRRCR'RIRRR#(R(R#((RRùs  c CsJ|djo:y t‚WqGtj otiƒdii}qGXn|djo!ttdƒo ti }qung}d}x¸|dj oª|djp ||jo|i }|i}|i}|i}ti|ƒti||ƒ}|o|iƒ}nd}|i||||fƒ|i}|d}q„W|iƒ|S(ssExtract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. iR"iiN(R(RRHRRCR'RIR#R$R"RR%tf_linenoRR)R*R+RR,RR-R.R/RRR!treverse( R(R#R*RRR%RRR((RRs6   '       cCs|iS(sRCalculate correct line number of traceback given in tb. Obsolete in 2.3. N(R&R (R&((RR $s(t__doc__R-RR6t__all__RRRRR RRR RRRBRRR R RRR (R R R RRR RMRRRRRR RR6RRRRBRR-((Rt?s*   0     1    "