o ?Og@/ã@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ú,/opt/alt/python310/lib64/python3.10/cgitb.pyÚreset#srcCó|rd|dSdS)NzzÚr©ÚtextrrrÚsmall.ó r cCr)Nzz rrrrrrÚstrong4r r cCr)NzzrrrrrrÚgrey:r r cCsŒ||vr d||fS||jvrd|j|fSd|jvrB|jd}t|ƒtiƒur6||vr2d||fSdtfSt||ƒrBdt||ƒ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]V\}} } } } |tjkr |S|tjkrT| tjvrT|dkrC|turBt|| tƒ}| || ||f¡n"t | ||ƒ\} }| | | |f¡n| dkra||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] \} ‰} } }}ˆrktj ˆ¡‰d ˆt j   ˆ¡f}nd‰}t | ¡\}}}}d}| dkršdt t j   | ¡ƒ}| dkrš|tj||||dd„d7}i‰| gf‡‡fdd„ }t|| |ƒ}dd||fg}|dur| |}|D]A}tddtt|ƒƒt|ƒƒd}|ˆvréd|t j  |¡f}| d|¡nd|t j  |¡f}| dt|ƒ¡|d 7}q¿ig}}|D]O\}}} ||vrqd ||<| turO|d!vr+d"|t |ƒ}n|d#kr5t |ƒ}n |t | d$¡d%ƒ}| d&|t j  | ¡f¡q| |d'¡q| dttd( |¡ƒƒ¡|  d)d* |¡¡qOd+t t j   t|ƒ¡ƒt j   t|ƒ¡fg}!t|ƒD]!}|dd …d,kr—qŠt 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 úcSódtj |¡S©Nú=)ÚpydocÚhtmlÚrepr©r'rrrÚ‚ózhtml..©Z formatvaluec óBdˆ|d<zt ˆ|d¡W|dd7<S|dd7<w©Nér©Ú linecacheÚgetline©Úlnum©ÚfileZ highlightrrr#…ó $zhtml..readerz+%s%s %sz Nz r.z=>%s%sz&%sz  %s%sz%sr@)rrz %s r réÿÿÿÿz %s = %sz undefinedz, zF %s
Ú z

%s: %sÚ_z
%s%s = %szî )#Ú isinstancerÚ__name__ÚsysÚversionÚsplitÚ executableÚtimeÚctimer7r8Zheadingr ÚescapeÚstrr ÚinspectÚgetinnerframesÚosÚpathÚabspathÚ getargvaluesÚformatargvaluesr-ÚlenZ preformatr"r rr9ÚjoinÚdirrÚ tracebackÚformat_exception)"ÚeinfoÚcontextÚetypeÚevalueÚetbÚpyverÚdateÚheadÚindentÚframesÚrecordsrrEÚfuncÚlinesÚindexÚlinkÚargsÚvarargsÚvarkwrÚcallr#r$ÚrowsÚir+ÚnumÚdoneÚdumprr,r'Ú exceptionrrFrr8es’  ÿýý  ÿ ÿ $      þÿ  ÿ÷r8c sv|\}}}t|tƒr |j}dtj ¡ddtj}t t ¡¡}dt |ƒ||fd}g}t   ||¡} | D]Å\} ‰} } } }ˆrGt j  ˆ¡pHd‰t  | ¡\}}}}d}| dkrnd| }| d krn|t j||||d d „d 7}i‰| gf‡‡fd d„ }t|| |ƒ}dˆ|fg}|dur¥| |}| D]}d|}| || ¡¡|d7}q‘ig}}|D]=\}}}||vr¶q¬d||<|turâ|dkrÇd|}n |dkrÔ|| d¡d}| d|tj |¡f¡q¬| |d¡q¬| d |¡¡| dd |¡¡q7dt |ƒ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/rr0z %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. r1rr2r3cSr4r5)r7rr9r:rrrr;Ör<ztext..r=c r>r?rArDrFrrr#ÙrHztext..readerz %s %sNz%5d r@rzglobal r rrIz%s = %sz undefinedrJz %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 )rLrrMrNrOrPrQrRrSrUrVrWrXrYrZr[r\r-r"Úrstriprr7rr9r^r_rr`ra) rbrcrdrerfrgrhrirkrlrrErmrnrorqrrrsrrtr#r$rurvr+rwrxryrr,r'rzrrFrrÀs\   ÿ     úrc@s0eZdZdZ  d dd„Zdd „Zd d d „ZdS)ÚHookz?A hook to replace sys.excepthook that shows tracebacks in HTML.r@Nr.r8cCs(||_||_||_|p tj|_||_dS©N)ÚdisplayÚlogdirrcrNÚstdoutrGÚformat)Úselfr~rrcrGrrrrÚ__init__s   z Hook.__init__cCs| |||f¡dSr})Úhandle)r‚rdrerfrrrÚ__call__ sz Hook.__call__c Cs€|pt ¡}|jdkr|j tƒ¡|jdkrtpt}d}z|||jƒ}Wnd  t j |Ž¡}d}Y|j rS|rJt j |¡}|j d|d¡n|j |d¡n|j d¡|jdur±d d g|jdk}tj||jd \}}z!t |d ¡ }| |¡Wdƒn1sˆwYd |} Wnd|} Y|jdkr©|j d| ¡n|j | d¡z|j ¡WdSYdS)Nr8FrTz

z
rJz*

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

)rNÚexc_inforrGÚwriterr8rrcr^r`rar~r7rTrÚtempfileZmkstemprXÚfdopenÚflush) r‚ÚinfoZ formatterZplainÚdocr†ÚfdrYrGÚmsgrrrr„s@      ÿ    z Hook.handle)r@Nr.Nr8r})rMÚ __module__Ú __qualname__Ú__doc__rƒr…r„rrrrr|s ÿr|r@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.©r~rrcrN)r|rNÚ excepthookr”rrrÚenable:s ÿr–)r.)r@Nr.r8)r“rVr rBrXr7rNrŠrRrr`rrr r r rr-r8rr|r„Zhandlerr–rrrrÚs.   [B7