B °-_ò.ã@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/lib/python3.7/cgitb.pyÚreset#srcCs|rd|dSdSdS)NzzÚr)ÚtextrrrÚsmall.s rcCs|rd|dSdSdS)Nzz rr)rrrrÚstrong4s rcCs|rd|dSdSdS)Nzzrr)rrrrÚgrey:s r cCs†||krd||fS||jkr,d|j|fSd|jkr~|jd}t|ƒtiƒkrf||kr~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\}}}}}x¶t |¡D]¨\}} } } } |tjkr>P|tjkr¦| tjkr¦|dkr„|tk r¤t|| tƒ}| || ||f¡qÈt | ||ƒ\} }| | | |f¡n"| dkrÀ||d7}|}nd\}}| }q$W|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 ||¡} xJ| D]@\} ‰} } }}ˆrÚtj ˆ¡‰d ˆt j   ˆ¡f}nd‰}t | ¡\}}}}d}| dkr.dt t j   | ¡ƒtj||||dd„d}i‰| gf‡‡fdd„ }t|| |ƒ}dd||fg}|dk r| |}xŽ|D]†}tddtt|ƒƒt|ƒƒd}|ˆkrÐd|t j  |¡f}| d|¡n&d|t j  |¡f}| dt|ƒ¡|d7}qzWig}}x¤|D]œ\}}} ||kr,qd||<| tk r |d krZd!|t |ƒ}n*|d"krnt |ƒ}n|t | d#¡d$ƒ}| d%|t j  | ¡f¡n| |d&¡qW| dttd' |¡ƒƒ¡|  d(d) |¡¡q¢Wd*t t j   t|ƒ¡ƒt j   t|ƒ¡fg}!xNt|ƒD]B}|dd…d+kr6qt j  t ||ƒ¡} |! d,||| f¡qW|d | ¡d |!¡d-t j   d t! "|||¡¡¡S).z9Return a nice HTML document describing a given traceback.zPython rz: 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ú?rzin cSsdtj |¡S)Nú=)ÚpydocÚhtmlÚrepr)r$rrrÚózhtml..)Ú formatvaluec s4dˆ|d<zt ˆ|d¡S|dd7<XdS)Nér)Ú linecacheÚgetline)Úlnum)ÚfileÚ highlightrrr „s zhtml..readerz+%s%s %sz Nz r+z=>%s%sz&%sz  %s%sz%sr4)r r z %s r réÿÿÿÿz %s = %sz undefinedz, zF %s
Ú z

%s: %sÚ_z
%s%s = %szî )#Ú isinstancerÚ__name__ÚsysÚversionÚsplitÚ executableÚtimeÚctimer.r/ZheadingrÚescapeÚstrrÚinspectÚgetinnerframesÚosÚpathÚabspathÚ getargvaluesÚformatargvaluesr*ÚlenZ preformatrr rr0ÚjoinÚdirrÚ tracebackÚformat_exception)"ÚeinfoÚcontextÚetypeÚevalueÚetbÚpyverÚdateÚheadÚindentÚframesÚrecordsrr7ÚfuncÚlinesÚindexÚlinkÚargsÚvarargsÚvarkwrÚcallr r!ÚrowsÚir(ÚnumÚdoneÚdumprr)r$Ú exceptionr)r8r9rr/es|  0       $        r/c sŽ|\}}}t|tƒr|j}dtj ¡ddtj}t t ¡¡}dt |ƒ||fd}g}t   ||¡} x | D]–\} ‰} } } }ˆr”t j  ˆ¡p–d‰t  | ¡\}}}}d}| dkrÖd| t j||||d d „d }i‰| gf‡‡fd d „ }t|| |ƒ}dˆ|fg}|dk rL| |}x0| D](}d|}| || ¡¡|d7}q Wig}}xŽ|D]†\}}}||krtq\d||<|tk rÒ|dkršd|}n|dkr¶|| d¡d}| d|tj |¡f¡n| |d¡q\W| d |¡¡| dd |¡¡qrWdt |ƒt |ƒfg}x8t|ƒD],}tj t||ƒ¡}| dd||f¡q.W|d |¡d |¡dd t |||¡¡S)z:Return a plain text document describing a given traceback.zPython rz: 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,rzin cSsdtj |¡S)Nr-)r.rr0)r$rrrr1Ôr2ztext..)r3c s4dˆ|d<zt ˆ|d¡S|dd7<XdS)Nr4r)r5r6)r7)r8r9rrr ×s ztext..readerz %s %sNz%5d r4r zglobal r rr:z%s = %sz undefinedr;z %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 )r=rr>r?r@rArBrCrDrFrGrHrIrJrKrLrMr*rÚrstriprr.rr0rOrPrrQrR) rSrTrUrVrWrXrYrZr\r]rr7r^r_r`rbrcrdrrer r!rfrgr(rhrirjrr)r$rkr)r8r9rr¿s^            rc@s,eZdZdZd dd„Zdd „Zd d d „ZdS)ÚHookz?A hook to replace sys.excepthook that shows tracebacks in HTML.r4Nr+r/cCs(||_||_||_|ptj|_||_dS)N)ÚdisplayÚlogdirrTr?Ústdoutr8Úformat)ÚselfrnrorTr8rqrrrÚ__init__s  z Hook.__init__cCs| |||f¡dS)N)Úhandle)rrrUrVrWrrrÚ__call__ sz Hook.__call__c Csz|p t ¡}|jdkr$|j tƒ¡|jdkr2tp4t}d}y|||jƒ}Wn d  t j |Ž¡}d}YnX|j rª|r˜t j |¡}|j d|d¡q¶|j |d¡n |j d¡|jdk rZd d g|jdk}tj||jd \}}y.t |d ¡}| |¡WdQRXd |} Wnd|} YnX|jdkrJ|j d| ¡n|j | d¡y|j ¡Wn YnXdS)Nr/FrTz

z
r;z*

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

%s

)r?Úexc_inforqr8Úwriterr/rrTrOrQrRrnr.rEroÚtempfileZmkstemprIÚfdopenÚflush) rrÚinfoZ formatterZplainÚdocrvÚfdrJr8Úmsgrrrrts@        z Hook.handle)r4Nr+Nr/)N)r>Ú __module__Ú __qualname__Ú__doc__rsrurtrrrrrms  rmr4cCst||||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.)rnrorTrqN)rmr?Ú excepthook)rnrorTrqrrrÚenable8sr…)r+)r+)r4Nr+r/)rƒrGrr5rIr.r?rzrCrrQrrrrr rr*r/rrmrtZhandlerr…rrrrÚs,  Z A7