�`^c@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZd�ZgZ
d�Zd�Zd�Zd�Zd�Zd d
�Zd d�Zddd
��YZe�jZddd dd�ZdS(s�More comprehensive traceback formatting for Python scripts.
To enable this module, do:
import cgitb; cgitb.enable()
at the top of your script. The optional arguments to enable() are:
display - if true, tracebacks are displayed in the web browser
logdir - if set, tracebacks are written to files in this directory
context - number of lines of source code to show for each stack frame
format - 'text' or 'html' controls the output format
By default, tracebacks are displayed but not saved, the context is 5 lines
and the output format is 'html' (for backwards compatibility with the
original use of this module)
Alternatively, if you have caught an exception and want cgitb to display it
for you, call cgitb.handler(). The optional argument to handler() is a
3-item tuple (etype, evalue, etb) just like the value of sys.exc_info().
The default handler displays output as HTML.
i�NcCsdS(sAReturn a string that resets the CGI and browser to a known state.s'<!--: spam
Content-Type: text/html
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
</font> </font> </font> </script> </object> </blockquote> </pre>
</table> </table> </table> </table> </table> </font> </font> </font>((((s/sys/lib/python2.7/cgitb.pytreset$scCs|rd|dSdSdS(Ns<small>s</small>t((ttext((s/sys/lib/python2.7/cgitb.pytsmall/scCs|rd|dSdSdS(Ns<strong>s </strong>R((R((s/sys/lib/python2.7/cgitb.pytstrong5scCs|rd|dSdSdS(Ns<font color="#909090">s</font>R((R((s/sys/lib/python2.7/cgitb.pytgrey;scCs�||krd||fS||jkr:d|j|fSd|jkr�|jd}t|�ti�kr�||kr�d||fSq�t||�r�dt||�fSndtfS(s9Find the value for a given name in the given environment.tlocaltglobalt__builtins__tbuiltinN(t f_globalsttypethasattrtgetattrtNonet __UNDEF__(tnametframetlocalstbuiltins((s/sys/lib/python2.7/cgitb.pytlookupAs
cCs2gdddtf\}}}}}xtj|�D]�}} }
}}|tjkr\Pn|tjkr�tjkr�dkr�|tk r�|| t�}|j || ||f�q�t
| ||�\}
}|j | |
|f�n/| dkr||d7}|}nd\}}| }q4W|S(sEScan one logical line of Python and look up values of variables used.Rt.N(NR(RRttokenizetgenerate_tokenstNEWLINEtNAMEtkeywordtkwlistR
tappendR(treaderRRtvarst lasttokentparenttprefixtvaluetttypettokentstarttendtlinetwhere((s/sys/lib/python2.7/cgitb.pytscanvarsQs"$%
ic" s�|\}}}t|�tjkr0|j}ndtjj�ddtj}tj tj��}dt
jjdt
t
jjt|���dd|d|�d }d
tdd�d
}g} tj||�}
x�D]�}�}}
}}�r4tjj���d�t
jj��f}n
d�}tj|�\}}}}d}|
dkr�dt
|
�tj||||dd��}ni�|g��fd�}t|||�}dd||fg}|d+k r�||}x�|D]�}tddtt|��t|��d}|�krpd|t
jj|�f}|jd|�n3d|t
jj|�f}|jdt|��|d7}qWnig}}x�|D]�\}}} ||kr��nd||<| tk r�|d,kr"d|t
|�}n8|dkr=t
|�}n|t
|jd �d!�}|jd"|t
jj| �f�q�|j|d#�q�W|jdttd$j |����| jd%d&j |��q�d't
t
jjt|���t
jjt|��fg}!t!|t"�r�xbt#|�D]Q}|d d(krNq2nt
jjt$||��} |!jd)||| f�q2Wn|dj | �dj |!�d*t
jjdj t%j&|||���S(-s9Return a nice HTML document describing a given traceback.sPython is: s<body bgcolor="#f0f0f8">s<big><big>%s</big></big>s#ffffffs#6622aas<br>s�
<p>A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.</p>s<tt>s is </tt>s<a href="file://%s">%s</a>t?Rsin tformatvaluecSsdtjj|�S(Nt=(tpydocthtmltrepr(R"((s/sys/lib/python2.7/cgitb.pyt<lambda>�scs>d�|d<ztj�|d�SWd|dcd7<XdS(Nii(t linecachetgetline(tlnum(tfilet highlight(s/sys/lib/python2.7/cgitb.pyR�ss+<tr><td bgcolor="#d8bbff">%s%s %s</td></tr>s<big> </big>s<tt>=>%s%s</tt>s&<tr><td bgcolor="#ffccee">%s</td></tr>s<tt> %s%s</tt>s<tr><td>%s</td></tr>iRR s<em>%s</em> RRi�s%s = %ss <em>undefined</em>s, sF
<table width="100%%" cellspacing=0 cellpadding=0 border=0>
%s</table>s
s <p>%s: %st_s
<br>%s%s =
%ss�
<!-- The above is a description of an error in a Python program, formatted
for a Web browser because the 'cgitb' module was enabled. In case you
are not reading this in a Web browser, here is the original traceback:
%s
-->
N(sglobalsbuiltin('Rttypest ClassTypet__name__tsystversiontsplitt
executablettimetctimeR-R.theadingRtescapetstrRtinspecttgetinnerframestostpathtabspathtgetargvaluestformatargvaluesR)Rtlent preformatRRRR/tjoint
isinstancet
BaseExceptiontdirR
t tracebacktformat_exception("teinfotcontexttetypetevaluetetbtpyvertdatetheadtindenttframestrecordsRR3tfunctlinestindextlinktargstvarargstvarkwRtcallRRtrowstiR'tnumtdonetdumpRR(R"t exception((R4R5s/sys/lib/python2.7/cgitb.pyR.fs~"@
.
&&! c s~|\}}}t|�tjkr0|j}ndtjj�ddtj}tj tj��}dt
|�||fd}g}tj||�} x$| D]\}
�}}}
}�r�t
jj��p�d�tj|
�\}}}}d}|dkr2d|tj||||d d
��}ni�|g��fd�}t||
|�}d�|fg}|dk r�||}x<|
D]1}d
|}|j||j��|d7}q�Wnig}}x�|D]�\}}}||kr�nd||<|tk rz|dkr.d|}n&|dkrT||jd�d}n|jd|tjj|�f�q�|j|d�q�W|jdj|��|jddj|��q�Wdt
|�t
|�fg}t|t�r@xLt|�D];}tjjt||��}|jdd||f�q�|dj|�dj|�ddjtj |||��S(s:Return a plain text document describing a given traceback.sPython is: s %s
%s
%s
s�
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
R*Rsin R+cSsdtjj|�S(NR,(R-RR/(R"((s/sys/lib/python2.7/cgitb.pyR0�scs>d�|d<ztj�|d�SWd|dcd7<XdS(Nii(R1R2(R3(R4R5(s/sys/lib/python2.7/cgitb.pyR�ss %s %ss%5d iRsglobal RRi�s%s = %ss
undefineds
s
%s
s%s: %ss
%s%s = %st isc
The above is a description of an error in a Python program. Here is
the original traceback:
%s
Ns (!RR7R8R9R:R;R<R=R>R?RBRCRDRERFRGRHRIR)RRtrstripRR-RR/RLRMRNROR
RPRQ( RRRSRTRURVRWRXRYR[R\RR3R]R^R_RaRbRcRRdRRReRfR'RgRhRiRR(R"Rj((R4R5s/sys/lib/python2.7/cgitb.pyR�s`"
&!tHookcBs;eZdZdddddd�Zd�Zdd�ZRS(s?A hook to replace sys.excepthook that shows tracebacks in HTML.iiR.cCs:||_||_||_|p'tj|_||_dS(N(tdisplaytlogdirRSR:tstdoutR4tformat(tselfRnRoRSR4Rq((s/sys/lib/python2.7/cgitb.pyt__init__s
cCs|j|||f�dS(N(thandle(RrRTRURV((s/sys/lib/python2.7/cgitb.pyt__call__sc
Cs�|ptj�}|jdkr7|jjt��n|jdkrLtpOt}t}y|||j �}Wn%dj
tj|��}t
}nX|jr�r�|jdd�jdd�}|jjd|d�q|jj|d �n|jjd
�|jdk r�ddg|jdk}tjd
|d|j�\}}y7tj|d�}|j|�|j�d|} Wnd|} nX|jdkr�|jjd| �q�|jj| d �ny|jj�WnnXdS(NR.Rt&s&t<s<s<pre>s</pre>
s
s*<p>A problem occurred in a Python script.
s.txts.htmltsuffixROtws*%s contains the description of this error.s*Tried to save traceback to %s, but failed.s
<p>%s</p>
(R:texc_infoRqR4twriteRR.RtFalseRSRLRPRQtTrueRntreplaceRoRttempfiletmkstempREtfdopentclosetflush(
Rrtinfot formattertplaintdocRxtfdRFR4tmsg((s/sys/lib/python2.7/cgitb.pyRtsB
!
N(R9t
__module__t__doc__RRsRuRt(((s/sys/lib/python2.7/cgitb.pyRms
iR.c Cs(td|d|d|d|�t_dS(sInstall an exception handler that formats tracebacks as HTML.
The optional argument 'display' can be set to 0 to suppress sending the
traceback to the browser, and 'logdir' can be set to a directory to cause
tracebacks to be written to files there.RnRoRSRqN(RmR:t
excepthook(RnRoRSRq((s/sys/lib/python2.7/cgitb.pytenable<s((R�RCRR1RER-R:RR>RRPR7RRRRRRR)R.RRmRtthandlerRR�(((s/sys/lib/python2.7/cgitb.pyt<module>s.
[B8
|