\d0 dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Ze jeddZgZdZdZd Zd Zd Zdd Z ddZGddZejZddZdS)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. N)escape) )removecdS)zAReturn a string that resets the CGI and browser to a known state.a' --> --> r..\python\lib\cgitb.pyresetr (s H Hr c|rd|zdzSdS)Nzzrtexts r smallr3s 4*,,rr c|rd|zdzSdS)Nzz r rrs r strongr9s D ;..rr c|rd|zdzSdS)Nzzr rrs r greyr?s '$.::rr c*||vr d||fS||jvrd|j|fSd|jvr\|jd}t|tiur||vr d||fSn"t||rdt||fSdtfS)z9Find the value for a given name in the given environment.localglobal __builtins__builtinN) f_globalstypehasattrgetattr __UNDEF__)nameframelocalsbuiltinss r lookupr#Es v~~t $$ u...((?>2 >>T"XX % %x (4.00 x&& : '(D"9"999 ?r cgdddtf\}}}}}tj|D]\}} } } } |tjkrn|tjkr|| t jvrn|dkr;|tur1t|| t}||| z||fnCt| ||\} }|| | |fn| dkr ||dzz }|}nd\}}| }|S)zEScan one logical line of Python and look up values of variables used.Nr .)Nr ) rtokenizegenerate_tokensNEWLINENAMEkeywordkwlistrappendr#)readerr r!vars lasttokenparentprefixvaluettypetokenstartendlinewheres r scanvarsr9Us-/tR-J*D)VVU*2*B6*J*J&ueS$ H$ $ $ee HM ! !e7>&A&AC**#FE9==EKK% ?@@@%eUF;; u UE512222 c\\ i#o %FFF%NFF Kr c ^ "#|\}}}t|tr|j}dtjdzdztjz}tjtj}dtt|d|d|d}dtd zd z}g} tj ||} | D] \} "} } }}"rFtj""d "d t"j"d }ndx"}tj| \}}}}d}| dkrRdt+t"j| z}| dkr|tj||||dz }i#| gf"#fd }t/|| |}dd|d|dg}|| |z }|D]}tddt1t|z zt|zdz}|#vr>d|t"j|d}|d|znJd|t"j|d}|d t7|z|d!z }ig}}|D]\}}} ||vr d!||<| t8ur|d"vrd#|zt+|z}nA|d$krt+|}n+|t+|d%d&z}||d't"j| ||d(z|d tt7d)|z| d*d+|z d,t+t"jt|dt"jt|g}!t?|D][}|dd!d-krt"jtA||} |!d.||d/| \|d| zd|!zd0t"jdtCj"|||zzS)1z9Return a nice HTML document describing a given traceback.Python r: z
 
 
zo
z
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  zz?r in cFdtj|zSN=)pydochtmlreprr2s r zhtml..cEJOOE4J4J.Jr  formatvaluecd|d<tj|d|dxxdz cc<S#|dxxdz cc<wxYwNr linecachegetlinelnumfile highlights r r-zhtml..readerY!"Id1g !)$Q88!WWW\WWWWT!WWW\WWWWWWW 8A zz  z Nz r:z =>zz&%sz  z%srN)rrz %s rr%z = z undefinedz, zF %s
 z

_z
z = z )# isinstancer__name__sysversionsplit executabletimectime html_escapestrrinspectgetinnerframesospathabspathrDrEr getargvaluesrformatargvaluesr9len preformatr,rrrFjoindirr tracebackformat_exception)$einfocontextetypeevalueetbpyverdateheadindentframesrecordsr rSfunclinesindexlinkargsvarargsvarkwr!callr-r.rowsir7numdonedumprr8r2 exceptionrTrUs$ @@r rErEjsE63%  ))++A. . 5 FE :dikk " "D K s5zz** K K05 K K;? K K KDeL)) )M 9F F$S'22G185!5!-tT4  7??4((DD37449J9J49P9P9P9PQDD D4'.';E'B'B$guf 3;;6%*"3"3D"9"9:::Dz!!/guf J JLLLL  " " " " " " "v..%$dddDDD23  u A  H#c!ff++ 6Q?@@8K >>>363 8L8LT8R8R8R8RSDKK H4 OPPPP";>#uz?S?STX?Y?Y?Y?YZDKK 6d CDDDQd"& : : D%t||XDJI%%111*U2fTllBDDg%%!$<#>>D dddEJOOE4J4J4JKLLLL D#889999 *U4 $3H3H-I-IIJJJ  $  ! ! ! !g5!n!'uz'8'8U'D'D E E E E % 1 1#f++ > > >@AIF JJ 8s??H  5 566FFDDD%%HIIII "''&// !BGGI$6$6 6 : j ''),UFC@@ A ACC :C C Cr c  !|\}}}t|tr|j}dtjdzdztjz}tjtj}t|d|d|ddz}g}tj ||} | D]\} } } } } rtj  pd tj| \}}}}d}| dkr(d| z}| d kr|tj||||d z }i!| gf !fd }t#|| |}d d |g}|>| |z }| D]6}d|z}|||z|dz }7ig}}|D]\}}}||vr d||<|t(urh|dkrd|z}n$|dkr||ddz}||dt*j|||dz|d||dd|zt|dt|g}t3|D]L}t*jt5||}|dd|d|M|d|zd|zddt7j|||zzS)z:Return a plain text document describing a given traceback.r<rr=rZz 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>r r?r@cFdtj|zSrB)rDrrFrGs r rHztext..rIr rJcd|d<tj|d|dxxdz cc<S#|dxxdz cc<wxYwrMrOrRs r r-ztext..readerrVrWrXNz%5d rNrzglobal rr%rYz = z undefinedz %s z zc The above is a description of an error in a Python program. Here is the original traceback: %s )r\rr]r^r_r`rarbrcrerfrgrhrirjrkrlr9r,rstriprrDrrFrorprrqrr)"rsrtrurvrwrxryrzr|r}r rSr~rrrrrr!rr-r.rrr7rrrrr8r2rrTrUs" @@r rrsE63%  ))++A. . 5 FE :dikk " "D ZZZZ 59 D F$S'22G18%2%2-tT4---4'.';E'B'B$guf 3;;4>>> "''&// !BGGI$6$6 6:  ggi(<<== :> >>r c,eZdZdZ d dZdZd dZdS) Hookz?A hook to replace sys.excepthook that shows tracebacks in HTML.rNNr:rEcd||_||_||_|p tj|_||_dSN)displaylogdirrtr^stdoutrTformat)selfrrrtrTrs r __init__z Hook.__init__s0   &CJ  r c6||||fdSr)handle)rrurvrws r __call__z Hook.__call__s! UFC()))))r c.|ptj}|jdkr&|jt |jdkrt pt}d} |||j}n*#d tj |}d}YnxYw|j r`|r@tj|}|jd|zdzn8|j|dzn|jd|jd d g|jdk}t!j||j \}} t%j|d 5}||dddn #1swxYwYd |z} n #d|z} YnxYw|jdkr|jd| zn|j| dz |jdS#YdSxYw)NrEFr Tz

z
rZz*

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

%s

)r^exc_inforrTwriter rErrtrorqrrrrDrrtempfilemkstemprhfdopenflush) rinfo formatterplaindocrfdrirTmsgs r rz Hook.handlesP%s|~~ ;& IOOEGG $ $ $[&(2d:d  )D$,//CC '')4d;<rs.  &&&&&&Xg....HHH      *_C_C_C_CB@>@>@>@>D55555555n $&&-::::::r