mò %U²Ic@s§dZdZdZdkZd„ZgZd„Zd„Zd„Zd„Z d „Z d d „Z d d „Z d fd„ƒYZ e ƒiZddd 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. s Ka-Ping Yees$Revision: 39082 $NcCsdS(sAReturn a string that resets the CGI and browser to a known state.s' --> --> N((((t"/data/zmath/lib/python2.4/cgitb.pytresetscCs|od|dSndSdS(Nsst(ttext(R((Rtsmall(scCs|od|dSndSdS(Nss R(R(R((Rtstrong.scCs|od|dSndSdS(NssR(R(R((Rtgrey4scCsÒ||jod||fSn||ijod|i|fSnd|ijot|id}t|ƒthƒjo#||jod||fSqÄqÈt||ƒodt||ƒfSqÈndt fS(s9Find the value for a given name in the given environment.tlocaltglobalt __builtins__tbuiltinN( tnametlocalstframet f_globalstbuiltinsttypethasattrtgetattrtNonet __UNDEF__(R R R R((Rtlookup:s   cCsOdk} dk}gdddtf\}} }} }x| i |ƒD]\} }} }}| | ijoPn| | ijo||ijo€| djoA|tj o0t||tƒ}|i| || |fƒq qAt|||ƒ\}}|i|||fƒn2|djo| | d7} |}n d\}} |} qFW|S(sEScan one logical line of Python and look up values of variables used.NRt.(NR(ttokenizetkeywordRRtvarst lasttokentparenttprefixtvaluetgenerate_tokenstreadertttypettokentstarttendtlinetNEWLINEtNAMEtkwlistRtappendRR R twhere(RR R RR#RRR!RR"RRRR R$R)((RtscanvarsJs($   "    ic+ s|\}}}dk}*dk}dk}(dk}#dk‰dk}dk ‰t |ƒ|i jo |i }ndt iiƒddt i}|(i|(iƒƒ}dˆiidtˆiit|ƒƒƒdd|d |ƒd }d td d ƒd}g} |i||ƒ} xõ| D]í\}‰}}}$}ˆo2|*i&i'ˆƒ‰dˆˆiiˆƒf}n d‰}|i)|ƒ\}}}"} d}|djo6dt|ƒ|i/|||"| d‡d†ƒ}nh‰|g‡‡‡d†}t2||| ƒ}dd||fg}|dj o¬||}!xŸ|$D]“}td d t8t|!ƒƒt|!ƒƒd }d|ˆii:|ƒf}|!ˆjo|i;d|ƒn|i;dt<|ƒƒ|!d7}!qIWnhg} }xß|D]×\}} }%|| joqønd| |<|%tBj oŒ| ddgjod| t|ƒ}n;| djot|ƒ}n| t|id ƒd!ƒ}|i;d"|ˆiiC|%ƒfƒqø|i;|d#ƒqøW|i;dtt<d$iD|ƒƒƒƒ| i;d%d&iD|ƒƒq&Wd'tˆiit|ƒƒƒˆiit|ƒƒfg}t |ƒ|iFjohxetG|ƒD]S}|d d(joqwnˆiiCtH||ƒƒ}%|i;d)|||%fƒqwWndk}#|diD| ƒdiD|ƒd*diD|#iI|||ƒƒS(+s9Return a nice HTML document describing a given traceback.NsPython is: ss%ss#ffffffs#6622aas
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.

ss is  s%st?Rsin t formatvaluecsdˆii|ƒS(Nt=(tpydocthtmltreprR(R(R.(Rt}scs>dˆ|d%s%s %ss s %s%ss&%ss%siRR s %s RRiÿÿÿÿs %s = %ss undefineds, sF %s
s s

%s: %st_s
%s%s = %ssî (Jtetypetevaluetetbtosttypesttimet tracebackR4tinspectR.Rt ClassTypet__name__tsystversiontsplitt executabletpyvertctimetdateR/theadingRtescapetstrtheadRtindenttframestgetinnerframestcontexttrecordsR R6R3tfunctlinestindextpathtabspathtlinkt getargvaluestargstvarargstvarkwR tcalltformatargvaluesR2RR*RtrowsRtiR$tlentnumt preformatR(RtdonetdumpR R)RRR0tjoint exceptiont InstanceTypetdirRtformat_exception(+t.0RPR8R9R:RR3R RaRcR6RNR)R R^RdRFR\RRLRYRTR?RWRRRZRHR$R<RfRMR RQR_R[R>RSRR.R4R=R2R;((R6R.R4R2RR/`s|? "+     .      '&= " c) så|\}}}dk}(dk}dk}&dk}!dk‰dk}dk ‰t |ƒ|i jo |i }ndt iiƒddt i}|&i|&iƒƒ}dt|ƒ||fd}g} |i||ƒ}x5|D]-\}‰}}}"}ˆo|(i i!ˆƒpd‰|i"|ƒ\}}} } d}|djo0d ||i(||| | d ‡d †ƒ}nh‰|g‡‡‡d †}t+||| ƒ}d ˆ|fg}|dj oJ||}x=|"D]1}d|}|i2||i3ƒƒ|d7}qÛWnhg} }x½|D]µ\}} }#|| joq(nd| |<|#t9j oj| djod|}n)| djo| |idƒd}n|i2d|ˆi:i;|#ƒfƒq(|i2|dƒq(W|i2di<|ƒƒ| i2ddi<|ƒƒqäWdt|ƒt|ƒfg}t |ƒ|i>joTxQt?|ƒD]?}ˆi:i;t@||ƒƒ}#|i2ddd||#fƒqWWndk}!|di<| ƒdi<|ƒddi<|!iA|||ƒƒS(s:Return a plain text document describing a given traceback.NsPython 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,csdˆii|ƒS(NR-(R.RR0R(R(R.(RR1Ñscs>dˆ|dR4R?R.RR@RARBRCRDRERFRGRHRKRLRNRORPRQR R6R3RRRSRTRURVRXRYRZR[R R\R]R2RR*RR^RR_R$RaR(trstripRcRdR R)RRRR0ReRfRgRhRRi()RjRPR8R9R:RR3R RaRcR6RNR)R R^RdRFR\RRLRYRTR?RQRRRZRHR$R<RfR R_R[R>RSRR.R4R=R2R;((R6R.R4R2RR»sf? "           ' & tHookcBs;tZdZdededd„Zd„Zed„ZRS(s?A hook to replace sys.excepthook that shows tracebacks in HTML.iiR/cCs;||_||_||_|pti|_||_dS(N(tdisplaytselftlogdirRPR6RBtstdouttformat(RoRnRpRPR6Rr((Rt__init__s    cCs|i|||fƒdS(N(RothandleR8R9R:(RoR8R9R:((Rt__call__ sc Csõ|p tiƒ}|idjo|iitƒƒn|idjotpt } t }y| ||i ƒ}Wn.dk}di|i|Œƒ}t}nX|ioY|o:|iddƒiddƒ}|iid|dƒq|ii|d ƒn|iid ƒ|idj o¯dk}dk}d d g|idj} |id | d|iƒ\}} y7|i|dƒ}|i|ƒ|iƒd| } Wnd| } nX|ii| d ƒny|ii ƒWnnXdS(NR/Rt&s&ts s s*

A problem occurred in a Python script. s.txts.htmltsuffixRhtws.

%s contains the description of this error.s.

Tried to save traceback to %s, but failed.(!tinfoRBtexc_infoRoRrR6twriteRR/Rt formattertFalsetplainRPtdocR>ReRitTrueRntreplaceRpRR;ttempfileRxtmkstemptfdRUtfdopentclosetmsgtflush( RoRzR;RƒR>R€R…R6RRˆRUR}Rx((RRt sB   !  (RAt __module__t__doc__RRsRuRt(((RRmÿs  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.RnRpRPRrN(RmRnRpRPRrRBt excepthook(RnRpRPRr((Rtenable5s(R‹t __author__t __version__RBRRRRRRR*R/RRmRtthandlerRR(RRRR*RRRŽRBRmR/RRRRR((RR+s        [ D5