a �DOg@/�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z dd�Z gZ dd�Z dd�Zd d �Zd d �Zd d�Zddd�Zddd�ZGdd�d�Ze�jZddd�ZdS)a�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. �NcCsdS)zAReturn a string that resets the CGI and browser to a known state.a' --> --> �rrr�/usr/lib64/python3.9/cgitb.py�reset#srcCs|rd|dSdSdS)Nzz�r��textrrr�small.s rcCs|rd|dSdSdS)Nzz rrrrrr�strong4s r cCs|rd|dSdSdS)Nzzrrrrrr�grey:s r cCs�||vrd||fS||jvr,d|j|fSd|jvr~|jd}t|�ti�urf||vr~d||fSnt||�r~dt||�fSdtfS)z9Find the value for a given name in the given environment.�local�global� __builtins__�builtinN)� f_globals�type�hasattr�getattr� __UNDEF__)�name�frame�locals�builtinsrrr�lookup@s     rcCs�gdddtf\}}}}}t�|�D]�\}} } } } |tjkr>q�|tjkr�| tjvr�|dkr�|tur�t|| t�}|�|| ||f�q�t | ||�\} }|�| | |f�n"| dkr�||d7}|}nd\}}| }q"|S)zEScan one logical line of Python and look up values of variables used.Nr�.)Nr) r�tokenize�generate_tokens�NEWLINE�NAME�keyword�kwlistr�appendr)�readerrr�varsZ lasttoken�parent�prefix�valueZttype�token�start�end�line�whererrr�scanvarsPs   r+�c" s�|\}}}t|t�r|j}dtj��ddtj}t�t���}dt j � dt t j � t|���dd|d|�d }d td �d }g} t�||�} | D�]F\} �} } }}�r�tj����d �t j � ��f}nd�}t�| �\}}}}d}| dk�r8dt t j � | ��}| dk�r8|tj||||dd�d�7}i�| gf��fdd� }t|| |�}dd||fg}|du�r | |}|D]�}tddtt|��t|��d}|�v�r�d|t j �|�f}|�d|�n&d|t j �|�f}|�dt|��|d 7}�q�ig}}|D]�\}}} ||v�r0�qd ||<| tu�r�|d!v�r^d"|t |�}n*|d#k�rrt |�}n|t |�d$�d%�}|�d&|t j �| �f�n|�|d'��q|�dttd(�|����| �d)d*�|��q�d+t t j � t|���t j � t|��fg}!t|�D]B}|dd �d,k�r4�qt j �t ||��} |!�d-||| f��q|d�| �d�|!�d.t j � d�t!�"|||���S)/z9Return a nice HTML document describing a given traceback.�Python r�: zz%sz#ffffffz#6622aaz
z�

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

zz     z  z%s�?r�in �cSsdtj�|�S�N�=)�pydoc�html�repr�r%rrr���zhtml..�Z formatvaluec sFd�|d<z"t��|d�W|dd7<S|dd7<0dS�N�r�� linecache�getline��lnum��fileZ highlightrrr!�s  �zhtml..readerz+%s%s %sz Nz r,z=>%s%sz&%sz  %s%sz%sr<)r rz %s r r�����z %s = %sz undefinedz, zF %s
� z

%s: %s�_z
%s%s = %sz� )#� isinstancer�__name__�sys�version�split� executable�time�ctimer4r5�headingr �escape�strr�inspect�getinnerframes�os�path�abspath� getargvalues�formatargvaluesr+�lenZ preformatr r rr6�join�dirr� traceback�format_exception)"�einfo�context�etype�evalue�etb�pyver�date�head�indent�frames�recordsrrA�func�lines�index�link�args�varargs�varkwr�callr!r"�rows�ir)�num�done�dumprr*r%� exceptionrrBrr5es�  ���    � � $       ��  ��r5c s�|\}}}t|t�r|j}dtj��ddtj}t�t���}dt |�||fd}g}t � ||�} | D�]�\} �} } } }�r�t j ���p�d�t �| �\}}}}d}| dkr�d| }| d kr�|t j||||d d �d �7}i�| gf��fd d� }t|| |�}d�|fg}|du�rP| |}| D](}d|}|�||���|d7}�q&ig}}|D]�\}}}||v�rv�q^d||<|tu�r�|dk�r�d|}n|dk�r�||�d�d}|�d|tj�|�f�n|�|d��q^|�d�|��|�dd�|��qndt |�t |�fg}t|�D],}tj�t||��}|�dd||f��q*|d�|�d�|�dd�t�|||��S) z:Return a plain text document describing a given traceback.r-rr.z %s %s %s z� 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/rr0r1cSsdtj�|�Sr2)r4rr6r7rrrr8�r9ztext..r:c sFd�|d<z"t��|d�W|dd7<S|dd7<0dSr;r=r@rBrrr!�s  �ztext..readerz %s %sNz%5d r<r zglobal r rrDz%s = %sz undefinedrEz %s z%s: %sz %s%s = %sz zc The above is a description of an error in a Python program. Here is the original traceback: %s )rGrrHrIrJrKrLrMrNrQrRrSrTrUrVrWrXr+r �rstriprr4rr6rZr[rr\r]) r^r_r`rarbrcrdrergrhrrArirjrkrmrnrorrpr!r"rqrrr)rsrtrurr*r%rvrrBrr�s\   �      �rc@s,eZdZdZd dd�Zdd �Zd d d �ZdS)�Hookz?A hook to replace sys.excepthook that shows tracebacks in HTML.r<Nr,r5cCs(||_||_||_|ptj|_||_dS�N)�display�logdirr_rI�stdoutrC�format)�selfrzr{r_rCr}rrr�__init__s  z Hook.__init__cCs|�|||f�dSry)�handle)r~r`rarbrrr�__call__ sz Hook.__call__c Cs�|p t��}|jdkr$|j�t��|jdkr2tp4t}d}z|||j�}Wn d� t j |��}d}Yn0|j r�|r�t j�|�}|j�d|d�q�|j�|d�n |j�d�|jdu�rpd d g|jdk}tj||jd �\}}zDt�|d ��}|�|�Wd�n1�s0Yd |} Wnd|} Yn0|jdk�r`|j�d| �n|j�| d�z|j��Wn Yn0dS)Nr5FrTz

z
rEz*

A problem occurred in a Python script. z.txtz.html)�suffixr[�wz*%s contains the description of this error.z*Tried to save traceback to %s, but failed.z

%s

)rI�exc_infor}rC�writerr5rr_rZr\r]rzr4rPr{�tempfile�mkstemprT�fdopen�flush) r~�info� formatterZplain�docr��fdrUrC�msgrrrr�s>      *  z Hook.handle)r<Nr,Nr5)N)rH� __module__� __qualname__�__doc__rr�r�rrrrrxs � rxr<cCst||||d�t_dS)aInstall 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.�rzr{r_r}N)rxrI� excepthookr�rrr�enable:s�r�)r,)r,)r<Nr,r5)r�rRrr>rTr4rIr�rMrr\rrrr r rr+r5rrxr��handlerr�rrrr�s,  [ B7