o ?Ognf@sJdZddlZddlZddlZddlZgdZd8ddZddZd9dd Zd8d d Z d8d d Z dZ dZ GdddZ e ZddZeedddfddZeeddfddZefddZddZddZd:dd Zd;d!d"Zd:d#d$Zdr selfr r r!__repr__Xz_Sentinel.__repr__N)__name__ __module__ __qualname__r-r r r r!r)Ws r)cCsT|tu|tukr td||urtur&n||fS|dur$||jfSdS||fS)Nz-Both or neither of value and tb must be givenNN) _sentinel ValueError __traceback__)excvaluer&r r r!_parse_value_tb]s r8TcCsXt|||\}}|durtj}tt||||dd}|j|dD] }t||ddq dS)aPrint 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. NTr$compactchainrr)r8rrrtyperr)r6r7r&r$rr<teliner r r!r hs r cCs6t|||\}}tt||||dd}t|j|dS)azFormat 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(). Tr9r;)r8rr=listr)r6r7r&r$r<r>r r r!r|s rcCs,|tur|}tt||ddd}t|S)aFormat the exception part of a traceback. 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 always the last string in the list. NT)r:)r3rr=r@r)r6r7r>r r r!rs rcCs0t|}|dus |sd|}|Sd||f}|S)Nz%s z%s: %s ) _some_str)etyper7valuestrr?r r r!_format_final_exc_lines   rDcCs$zt|WSdt|jYS)Nz)strr=r/)r7r r r!rAs rAcCstt|||ddS)z>Shorthand for 'print_exception(*sys.exc_info(), limit, file)'.r$rr<N)r rexc_inforFr r r!r r cCsdtt||dS)z%Like print_exc() but return a string.rr$r<)joinrrrGrIr r r!r rHr cCs.ttds tdttjtjtj|||dS)znThis is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'. last_typezno last exceptionN)hasattrrr4r rK last_valuelast_tracebackrFr r r!r s r cCs*|dur tj}tt||d|ddS)zPrint 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(). Nr#r%)r _getframef_backr"r)fr$rr r r!r s r cCs"|dur tj}tt||dS)z5Shorthand for 'format_list(extract_stack(f, limit))'.Nr#)rrOrPrr)rQr$r r r!rs rcCs0|dur tj}tjt||d}||S)asExtract 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. Nr#)rrOrPrr(rreverse)rQr$stackr r r!rs  rcCs@|durz|jWn tyYnw|j}|dusdSdS)zEClear all references to local variables in the frames of a traceback.N)tb_frameclear RuntimeErrortb_nextr&r r r!rs rc@sZeZdZdZdZddddddZdd Zd d Zd d ZddZ ddZ e ddZ dS)ra,A single frame from a traceback. - :attr:`filename` The filename for the frame. - :attr:`lineno` The line within filename for the frame that was active when the frame was captured. - :attr:`name` The name of the function or method that was executing when the frame was captured. - :attr:`line` The text from the linecache module for the of code that was running when the frame was captured. - :attr:`locals` Either None if locals were not supplied, or a dict mapping the name to the repr() of the variable. )filenamelinenoname_linelocalsTN) lookup_liner]r?cCsH||_||_||_||_|r|j|rdd|D|_dSd|_dS)aConstruct a FrameSummary. :param lookup_line: If True, `linecache` is consulted for the source code line. Otherwise, the line will be looked up when first needed. :param locals: If supplied the frame locals, which will be captured as object representations. :param line: If provided, use this instead of looking up the line in the linecache. cSsi|] \}}|t|qSr )repr).0kvr r r! sz)FrameSummary.__init__..N)rYrZr[r\r?itemsr])r,rYrZr[r^r]r?r r r!__init__s &zFrameSummary.__init__cCs`t|tr|j|jko|j|jko|j|jko|j|jkSt|tr.|j|j|j|jf|kStSN) isinstancerrYrZr[r]tupler?NotImplementedr,otherr r r!__eq__s      zFrameSummary.__eq__cCs|j|j|j|jf|Srf)rYrZr[r?)r,posr r r! __getitem__ zFrameSummary.__getitem__cCst|j|j|j|jgSrf)iterrYrZr[r?r+r r r!__iter__#rozFrameSummary.__iter__cCsdj|j|j|jdS)Nz7)rYrZr[)rrYrZr[r+r r r!r-&s zFrameSummary.__repr__cCr*)Nr r+r r r!__len__*r.zFrameSummary.__len__cCs4|jdur|jdur dSt|j|j|_|jSrf)r\rZ linecachegetlinerYstripr+r r r!r?-s   zFrameSummary.line) r/r0r1__doc__ __slots__rerlrnrqr-rspropertyr?r r r r!rs   rccs@|dur tjj}|dur||jfV|j}|dusdSdS)zWalk a stack yielding the frame and line number for each frame. This will follow f.f_back from the given frame. If no frame is given, the current stack is used. Usually used with StackSummary.extract. N)rrOrPf_lineno)rQr r r!r5s  rccs.|dur|j|jfV|j}|dusdSdS)zWalk a traceback yielding the frame and line number for each frame. This will follow tb.tb_next (and thus is in the opposite order to walk_stack). Usually used with StackSummary.extract. N)rT tb_linenorWrXr r r!rBs rc@s:eZdZdZeddddddZedd Zd d ZdS) rzA stack of frames.NTFr$ lookup_linescapture_localsc Cs|durttdd}|dur|dkrd}|dur+|dkr#t||}ntj|| d}|}t}|D]-\}}|j} | j} | j } | | t | |j |rR|j} nd} |t| || d| dq3|D]} t | qc|ru|D]}|jqo|S)a?Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. Ntracebacklimitr)maxlenF)r^r])getattrr itertoolsislice collectionsdequesetf_code co_filenameco_nameaddrt lazycache f_globalsf_localsappendr checkcacher?) klass frame_genr$r~rresultfnamesrQrZcorYr[rr r r!r(Rs8      zStackSummary.extractc CsLt}|D]}t|tr||q|\}}}}|t||||dq|S)z Create a StackSummary object from a supplied list of FrameSummary objects or old-style list of tuples. )r?)rrgrr)ra_listrframerYrZr[r?r r r!rs    zStackSummary.from_listc Csdg}d}d}d}d}|D]}|dus)||jks)|dus)||jks)|dus)||jkrN|tkrC|t8}|d|d|dkr=dndd|j}|j}|j}d}|d7}|tkrWq g}|d |j|j|j|jrt|d |j|jrt |j D]\}} |d j|| d q~|d |q |tkr|t8}|d|d|dkrdndd|S) aFormat the stack ready for printing. Returns a list of strings ready for printing. Each string in the resulting list corresponds to a single frame from the stack. Each string ends in a newline; the strings may contain internal newlines as well, for those items with source text lines. For long sequences of the same frame and line, the first few repetitions are shown, followed by a summary line stating the exact number of further repetitions. Nrz [Previous line repeated z more timesrz] z File "{}", line {}, in {}  {} z {name} = {value} )r[r7) rYrZr[_RECURSIVE_CUTOFFrrr?rvr]sortedrdrJ) r,r last_file last_line last_namecountrrowr[r7r r r!rsR  zStackSummary.format)r/r0r1rw classmethodr(rrr r r r!rOs/  rc@sheZdZdZddddddddZedd Zd d Zd d ZddZ ddZ ddZ ddddZ dS)raAn exception ready for rendering. The traceback module captures enough attributes from the original exception to this intermediary form to ensure that no references are held, while still being able to fully print or format it. Use `from_exception` to create TracebackException instances from exception objects, or the constructor to create TracebackException instances from individual components. - :attr:`__cause__` A TracebackException of the original *__cause__*. - :attr:`__context__` A TracebackException of the original *__context__*. - :attr:`__suppress_context__` The *__suppress_context__* value from the original exception. - :attr:`stack` A `StackSummary` representing the traceback. - :attr:`exc_type` The class of the original traceback. - :attr:`filename` For syntax errors - the filename where the error occurred. - :attr:`lineno` For syntax errors - the linenumber where the error occurred. - :attr:`end_lineno` For syntax errors - the end linenumber where the error occurred. Can be `None` if not present. - :attr:`text` For syntax errors - the text where the error occurred. - :attr:`offset` For syntax errors - the offset into the text where the error occurred. - :attr:`end_offset` For syntax errors - the end offset into the text where the error occurred. Can be `None` if not present. - :attr:`msg` For syntax errors - the compiler error message. NTF)r$r~rr:_seenc Cs|du} |dur t}|t|tjt||||d|_||_t||_ |r]t |t r]|j |_ |j } | durecause need_contextcontextr r r!res      zTracebackException.__init__cOs |t|||jg|Ri|S)z.Create a TracebackException from an exception.)r=r5)clsr6argskwargsr r r!from_exception9s z!TracebackException.from_exceptioncCs|jD]}|jqdS)z7Private API. force all lines in the stack to be loaded.N)rSr?)r,rr r r!r>s zTracebackException._load_linescCst|tr |j|jkStSrf)rgr__dict__rirjr r r!rlCs  zTracebackException.__eq__cCs|jSrf)rr+r r r!__str__HszTracebackException.__str__ccs|jdurtd|jVdS|jj}|jj}|dvr(t|ts"d}|d|}t|jts7t||jVdS| |EdHdS)aFormat the exception part of the traceback. The return value is a generator of strings, each ending in a newline. Normally, the generator emits a single string; however, for SyntaxError exceptions, it emits several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the output. N)__main__builtinsz .) rrDrr1r0rgrErr_format_syntax_error)r,stypesmodr r r!rKs    z(TracebackException.format_exception_onlyc cs,d}|jdurd|jpd|jVn |jdurd|j}|j}|dur|d}|d}t|t|}d|V|jdur|j}|jd vrN|jn|}||ksX|d kr\|d }|d |} |d |} | d krd d|d| D} dd | d| | dV|j pd} d|| |VdS)z0Format SyntaxError exceptions (internal helper).rNz File "{}", line {} zz ({}) z r>rNrrcss |] }|r |ndVqdS) N)isspace)r`cr r r! sz:TracebackException._format_syntax_error..z {}{}^zz {}: {}{} ) rZrrYrrstriplstriplenrrrJr) r,rfilename_suffixrrtextltextspacesrrcolno end_colno caretspacerr r r!rhs4            z'TracebackException._format_syntax_errorr;ccsg}|}|r;|r0|jdurt}|j}n|jdur"|js"t}|j}nd}d}|||f|}n |d|fd}|st|D] \}}|durJ|V|jrXdV|jEdH| EdHq?dS)aFormat the exception. If chain is not *True*, *__cause__* and *__context__* will not be formatted. The return value is a generator of strings, each ending in a newline and some containing internal newlines. `print_exception` is a wrapper around this method which just prints the lines to a file. The message indicating which exception occurred is always the last string in the output. Nz#Traceback (most recent call last): ) r_cause_messagerr_context_messagerreversedrSrr)r,r<outputr6 chained_msg chained_excrr r r!rs8   zTracebackException.format) r/r0r1rwrerrrrlrrrrr r r r!rs P $rrfr2)NNT)NT)NNN)#rwrrrtr__all__r"rrrrrrr)r3r8r rrrDrAr r r r rrrrrrrr@rrr r r r!sP           B  z