U e5d@/@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddZ gZ ddZ ddZd d Zd d Zd dZdddZdddZGdddZejZdddZdS)aMore 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.8/cgitb.pyreset#srcCs|rd|dSdSdS)Nzzrtextrrrsmall.s rcCs|rd|dSdSdS)Nzz rrrrrrstrong4s r cCs|rd|dSdSdS)Nzzrrrrrrgrey:s r cCs||krd||fS||jkr,d|j|fSd|jkr~|jd}t|tikrf||kr~d||fSnt||r~dt||fSdtfS)z9Find the value for a given name in the given environment.localglobal __builtins__builtinN) f_globalstypehasattrgetattr __UNDEF__)nameframelocalsbuiltinsrrrlookup@s     rcCsgdddtf\}}}}}t|D]\}} } } } |tjkr>q|tjkr| tjkr|dkr|tk rt|| t}||| ||fqt | ||\} }|| | |fn"| dkr||d7}|}nd\}}| }q"|S)zEScan one logical line of Python and look up values of variables used.Nr.)Nr) rtokenizegenerate_tokensNEWLINENAMEkeywordkwlistrappendr)readerrrvarsZ lasttokenparentprefixvalueZttypetokenstartendlinewhererrrscanvarsPs"   r+c" s|\}}}t|tr|j}dtjddtj}tt}dt j dt t j t|dd|d|d }d td d }g} t||} | D]F\} } } }}rtjd t j f}nd}t| \}}}}d}| dkr8dt t j | }| dkr8|tj||||ddd7}i| gffdd }t|| |}dd||fg}|dk r | |}|D]}tddtt|t|d}|krd|t j |f}|d|n&d|t j |f}|dt||d 7}qig}}|D]\}}} ||kr0qd ||<| tk r|d!kr^d"|t |}n*|d#krrt |}n|t |d$d%}|d&|t j | fn||d'q|dttd(|| d)d*|qd+t t j t|t j t|fg}!t|D]B}|dd d,kr4qt j t ||} |!d-||| fq|d| d|!d.t j dt!"|||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?rin cSsdtj|SN=)pydochtmlreprr%rrrzhtml..Z formatvaluec s8d|d<zt|dWS|dd7<XdSNr linecachegetlinelnumfileZ highlightrrr!s zhtml..readerz+%s%s %sz Nz r,z=>%s%sz&%sz  %s%sz%sr<)r rz %s r rz %s = %sz undefinedz, zF %s
 z

%s: %s_z
%s%s = %sz )# isinstancer__name__sysversionsplit executabletimectimer4r5Zheadingr escapestrrinspectgetinnerframesospathabspath getargvaluesformatargvaluesr+lenZ preformatr r rr6joindirr tracebackformat_exception)"einfocontextetypeevalueetbpyverdateheadindentframesrecordsrrAfunclinesindexlinkargsvarargsvarkwrcallr!r"rowsir)numdonedumprr*r% exceptionrrBrr5es         $          r5c s|\}}}t|tr|j}dtjddtj}tt}dt |||fd}g}t ||} | D]\} } } } }rt j pdt | \}}}}d}| dkrd| }| d kr|t j||||d d d 7}i| gffd d }t|| |}d|fg}|dk rP| |}| D](}d|}||||d7}q&ig}}|D]\}}}||krvq^d||<|tk r|dkrd|}n|dkr||dd}|d|tj|fn||dq^|d||dd|qndt |t |fg}t|D],}tjt||}|dd||fq*|d|d|ddt|||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)r4rr6r7rrrr8r9ztext..r:c s8d|d<zt|dWS|dd7<XdSr;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 )rGrrHrIrJrKrLrMrNrPrQrRrSrTrUrVrWr+r rstriprr4rr6rYrZrr[r\) r]r^r_r`rarbrcrdrfrgrrArhrirjrlrmrnrror!r"rprqr)rrrsrtrr*r%rurrBrrsb            rc@s,eZdZdZd ddZdd Zd d d ZdS)Hookz?A hook to replace sys.excepthook that shows tracebacks in HTML.r<Nr,r5cCs(||_||_||_|ptj|_||_dSN)displaylogdirr^rIstdoutrCformat)selfryrzr^rCr|rrr__init__s  z Hook.__init__cCs||||fdSrx)handle)r}r_r`rarrr__call__ sz Hook.__call__c Csz|p t}|jdkr$|jt|jdkr2tp4t}d}z|||j}Wn d t j |}d}YnX|j r|rt j|}|jd|dq|j|dn |jd|jdk rZd d g|jdk}tj||jd \}}z.t|d }||W5QRXd |} Wnd|} YnX|jdkrJ|jd| n|j| dz|jWn YnXdS)Nr5FrTz

z
rEz*

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

%s

)rIexc_infor|rCwriterr5rr^rYr[r\ryr4rOrztempfileZmkstemprSfdopenflush) r}infoZ formatterZplaindocrfdrTrCmsgrrrrs@        z Hook.handle)r<Nr,Nr5)N)rH __module__ __qualname____doc__r~rrrrrrrws  rwr<cCst||||dt_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.ryrzr^r|N)rwrI excepthookrrrrenable:sr)r,)r,)r<Nr,r5)rrQrr>rSr4rIrrMrr[rrrr r rr+r5rrwrZhandlerrrrrrs,  [ B7