1919for you, call cgitb.handler(). The optional argument to handler() is a
20203-item tuple (etype, evalue, etb) just like the value of sys.exc_info().
2121The default handler displays output as HTML.
22- """
23-
24- __author__ = 'Ka-Ping Yee'
25-
26- __version__ = '$Revision$'
2722
23+ """
24+ import inspect
25+ import keyword
26+ import linecache
27+ import os
28+ import pydoc
2829import sys
30+ import tempfile
31+ import time
32+ import tokenize
33+ import traceback
34+ import types
2935
3036def reset ():
3137 """Return a string that resets the CGI and browser to a known state."""
@@ -74,7 +80,6 @@ def lookup(name, frame, locals):
7480
7581def scanvars (reader , frame , locals ):
7682 """Scan one logical line of Python and look up values of variables used."""
77- import tokenize , keyword
7883 vars , lasttoken , parent , prefix , value = [], None , None , '' , __UNDEF__
7984 for ttype , token , start , end , line in tokenize .generate_tokens (reader ):
8085 if ttype == tokenize .NEWLINE : break
@@ -96,8 +101,6 @@ def scanvars(reader, frame, locals):
96101
97102def html (einfo , context = 5 ):
98103 """Return a nice HTML document describing a given traceback."""
99- import os , time , traceback , linecache , inspect , pydoc
100-
101104 etype , evalue , etb = einfo
102105 if isinstance (etype , type ):
103106 etype = etype .__name__
@@ -173,7 +176,6 @@ def reader(lnum=[lnum]):
173176 value = pydoc .html .repr (getattr (evalue , name ))
174177 exception .append ('\n <br>%s%s =\n %s' % (indent , name , value ))
175178
176- import traceback
177179 return head + '' .join (frames ) + '' .join (exception ) + '''
178180
179181
@@ -188,8 +190,6 @@ def reader(lnum=[lnum]):
188190
189191def text (einfo , context = 5 ):
190192 """Return a plain text document describing a given traceback."""
191- import os , time , traceback , linecache , inspect , pydoc
192-
193193 etype , evalue , etb = einfo
194194 if isinstance (etype , type ):
195195 etype = etype .__name__
@@ -245,7 +245,6 @@ def reader(lnum=[lnum]):
245245 value = pydoc .text .repr (getattr (evalue , name ))
246246 exception .append ('\n %s%s = %s' % (" " * 4 , name , value ))
247247
248- import traceback
249248 return head + '' .join (frames ) + '' .join (exception ) + '''
250249
251250The above is a description of an error in a Python program. Here is
@@ -278,7 +277,6 @@ def handle(self, info=None):
278277 try :
279278 doc = formatter (info , self .context )
280279 except : # just in case something goes wrong
281- import traceback
282280 doc = '' .join (traceback .format_exception (* info ))
283281 plain = True
284282
@@ -292,7 +290,6 @@ def handle(self, info=None):
292290 self .file .write ('<p>A problem occurred in a Python script.\n ' )
293291
294292 if self .logdir is not None :
295- import os , tempfile
296293 suffix = ['.txt' , '.html' ][self .format == "html" ]
297294 (fd , path ) = tempfile .mkstemp (suffix = suffix , dir = self .logdir )
298295 try :
0 commit comments