Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/traceback.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@sBdZddlZddlZddlZddddddd	d
ddd
dddgZddd�Zdd�Zd�Zddd�Z	dd�Z
dd�Zddd�Zdd�Z
d�Zd�Zd�Zddd�Zdd�Zddd �Zdddd!�Zddd"�Zddd#�Zd$�ZdS(%s@Extract, format and print information about Python stack traces.i�Nt
extract_stackt
extract_tbtformat_exceptiontformat_exception_onlytformat_listtformat_stackt	format_tbt	print_exct
format_exctprint_exceptiont
print_lasttprint_stacktprint_tbt	tb_linenots
cCs|j||�dS(N(twrite(tfiletstrt
terminator((s/sys/lib/python2.7/traceback.pyt_printscCs�|dkrtj}nd}tjdkr6d}nxT|D]L\}}}}t|||||f�|r=t|d|j��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 %stplan9s  File "%s:%d", in %ss    %sN(tNonetsyststderrtplatformRtstrip(textracted_listRtfmttfilenametlinenotnametline((s/sys/lib/python2.7/traceback.pyt
print_lists	cCs�g}d}tjdkr$d}nxW|D]O\}}}}||||f}|rm|d|j�}n|j|�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
Rs  File "%s:%d", in %s
s    %s
(RRRtappend(RtlistRRRRRtitem((s/sys/lib/python2.7/traceback.pyRs
	cCs4|dkrtj}n|dkrBttd�rBtj}qBnd}d}tjdkrfd}nx�|dk	r/|dks�||kr/|j}|j}|j}|j	}|j
}	t|||||	f�tj
|�tj|||j�}
|
rt|d|
j��n|j}|d}qiWdS(	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 %sRs  File "%s:%d", in %ss    iN(RRRthasattrR$Rttb_frameR
tf_codetco_filenametco_nameRt	linecachet
checkcachetgetlinet	f_globalsRttb_next(ttbtlimitRtnRtfRtcoRRR((s/sys/lib/python2.7/traceback.pyR3s,	'					
	cCstt||��S(s5A shorthand for 'format_list(extract_tb(tb, limit))'.(RR(R/R0((s/sys/lib/python2.7/traceback.pyRQsc
Cs�|dkr*ttd�r*tj}q*ng}d}x�|dk	r�dks]||kr�j}|j}|j}|j}|j}t	j
|�t	j|||j�}	|	r�|	j
�}	nd}	|j||||	f�|j}|d}q9W|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(RR%RR$R&R
R'R(R)R*R+R,R-RR!R.(
R/R0R"R1R2RR3RRR((s/sys/lib/python2.7/traceback.pyRUs('					
	cCsr|dkrtj}n|r>t|d�t|||�nt||�}x|D]}t||d�qTWdS(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):RN(RRRRRR(tetypetvalueR/R0RtlinesR((s/sys/lib/python2.7/traceback.pyR	us

cCsB|r%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):
(RR(R4R5R/R0R"((s/sys/lib/python2.7/traceback.pyR�s		c
Cs�t|t�s?t|tj�s?|dks?t|�tkrOt||�gS|j}t	|t
�swt||�gSg}y|j\}\}}}}Wntk
r�n�|p�d}t
jdkr�jd||f�n|jd||f�|dk	r�|jd|j��|dk	r�|jd�}	tt|	�|�d}|	| j�}	d�|	D�}	|jd	d
j|	��q�n|}|jt||��|S(sFormat 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 always the last
    string in the list.

    s<string>Rs  File "%s", line %d
s  File "%s:%d"
s    %s
s
icss'|]}|j�r|pdVqdS(t N(tisspace(t.0tc((s/sys/lib/python2.7/traceback.pys	<genexpr>�ss    %s^
RN(t
isinstancet
BaseExceptionttypestInstanceTypeRttypeRt_format_final_exc_linet__name__t
issubclasstSyntaxErrortargst	ExceptionRRR!Rtrstriptmintlentlstriptjoin(
R4R5tstypeR6tmsgRRtoffsettbadlinet
caretspace((s/sys/lib/python2.7/traceback.pyR�s6	
 cCs@t|�}|dks|r,d|}nd||f}|S(sGReturn a list of a single line -- normal case for format_exception_onlys%s
s%s: %s
N(t	_some_strR(R4R5tvaluestrR((s/sys/lib/python2.7/traceback.pyR@�s

cCsgyt|�SWntk
r!nXy t|�}|jdd�SWntk
rUnXdt|�jS(Ntasciitbackslashreplaces<unprintable %s object>(RREtunicodetencodeR?RA(R5((s/sys/lib/python2.7/traceback.pyRP�s

cCs]|dkrtj}nz/tj�\}}}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(RRRtexc_infoR	(R0RR4R5R/((s/sys/lib/python2.7/traceback.pyR�scCsKz5tj�\}}}djt||||��SWdd}}}XdS(s%Like print_exc() but return a string.RN(RRVRJRR(R0R4R5R/((s/sys/lib/python2.7/traceback.pyR�s cCsYttd�std��n|dkr6tj}nttjtjtj||�dS(snThis is a shorthand for 'print_exception(sys.last_type,
    sys.last_value, sys.last_traceback, limit, file)'.t	last_typesno last exceptionN(	R%Rt
ValueErrorRRR	RWt
last_valuetlast_traceback(R0R((s/sys/lib/python2.7/traceback.pyR
scCs]|dkrCy
t�WqCtk
r?tj�djj}qCXntt||�|�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(RtZeroDivisionErrorRRVR&tf_backR R(R2R0R((s/sys/lib/python2.7/traceback.pyRs

cCsV|dkrCy
t�WqCtk
r?tj�djj}qCXntt||��S(s5Shorthand for 'format_list(extract_stack(f, limit))'.iN(RR[RRVR&R\RR(R2R0((s/sys/lib/python2.7/traceback.pyRs

c	CsB|dkrCy
t�WqCtk
r?tj�djj}qCXn|dkrmttd�rmtj}qmng}d}x�|dk	r3|dks�||kr3|j}|j	}|j
}|j}tj
|�tj|||j�}|r�j�}nd}|j||||f�|j}|d}q|W|j�|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(RR[RRVR&R\R%R$tf_linenoR'R(R)R*R+R,R-RR!treverse(	R2R0R"R1RR3RRR((s/sys/lib/python2.7/traceback.pyR#s2	

'				
	
cCs|jS(sRCalculate correct line number of traceback given in tb.

    Obsolete in 2.3.
    (R
(R/((s/sys/lib/python2.7/traceback.pyR
Es(t__doc__R*RR=t__all__RRR RRRRR	RRR@RPRRR
RRRR
(((s/sys/lib/python2.7/traceback.pyt<module>s2		
	 	;			

		"

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.