Changeset 388 for python/vendor/current/Lib/cgitb.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/cgitb.py
r2 r388 20 20 3-item tuple (etype, evalue, etb) just like the value of sys.exc_info(). 21 21 The default handler displays output as HTML. 22 22 23 """ 23 24 __author__ = 'Ka-Ping Yee' 25 26 __version__ = '$Revision: 55348 $' 27 24 import inspect 25 import keyword 26 import linecache 27 import os 28 import pydoc 28 29 import sys 30 import tempfile 31 import time 32 import tokenize 33 import traceback 34 import types 29 35 30 36 def reset(): … … 75 81 def scanvars(reader, frame, locals): 76 82 """Scan one logical line of Python and look up values of variables used.""" 77 import tokenize, keyword78 83 vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ 79 84 for ttype, token, start, end, line in tokenize.generate_tokens(reader): … … 95 100 return vars 96 101 97 def html( (etype, evalue, etb), context=5):102 def html(einfo, context=5): 98 103 """Return a nice HTML document describing a given traceback.""" 99 import os, types, time, traceback, linecache, inspect, pydoc 100 104 etype, evalue, etb = einfo 101 105 if type(etype) is types.ClassType: 102 106 etype = etype.__name__ … … 139 143 for line in lines: 140 144 num = small(' ' * (5-len(str(i))) + str(i)) + ' ' 141 line = '<tt>%s%s</tt>' % (num, pydoc.html.preformat(line))142 145 if i in highlight: 146 line = '<tt>=>%s%s</tt>' % (num, pydoc.html.preformat(line)) 143 147 rows.append('<tr><td bgcolor="#ffccee">%s</td></tr>' % line) 144 148 else: 149 line = '<tt> %s%s</tt>' % (num, pydoc.html.preformat(line)) 145 150 rows.append('<tr><td>%s</td></tr>' % grey(line)) 146 151 i += 1 … … 174 179 exception.append('\n<br>%s%s =\n%s' % (indent, name, value)) 175 180 176 import traceback177 181 return head + ''.join(frames) + ''.join(exception) + ''' 178 182 … … 187 191 ''.join(traceback.format_exception(etype, evalue, etb))) 188 192 189 def text( (etype, evalue, etb), context=5):193 def text(einfo, context=5): 190 194 """Return a plain text document describing a given traceback.""" 191 import os, types, time, traceback, linecache, inspect, pydoc 192 195 etype, evalue, etb = einfo 193 196 if type(etype) is types.ClassType: 194 197 etype = etype.__name__ … … 246 249 exception.append('\n%s%s = %s' % (" "*4, name, value)) 247 250 248 import traceback249 251 return head + ''.join(frames) + ''.join(exception) + ''' 250 252 … … 279 281 doc = formatter(info, self.context) 280 282 except: # just in case something goes wrong 281 import traceback282 283 doc = ''.join(traceback.format_exception(*info)) 283 284 plain = True … … 293 294 294 295 if self.logdir is not None: 295 import os, tempfile296 296 suffix = ['.txt', '.html'][self.format=="html"] 297 297 (fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir) 298 298 299 try: 299 300 file = os.fdopen(fd, 'w') 300 301 file.write(doc) 301 302 file.close() 302 msg = ' <p>%s contains the description of this error.' % path303 msg = '%s contains the description of this error.' % path 303 304 except: 304 msg = '<p> Tried to save traceback to %s, but failed.' % path 305 self.file.write(msg + '\n') 305 msg = 'Tried to save traceback to %s, but failed.' % path 306 307 if self.format == 'html': 308 self.file.write('<p>%s</p>\n' % msg) 309 else: 310 self.file.write(msg + '\n') 306 311 try: 307 312 self.file.flush()
Note:
See TracChangeset
for help on using the changeset viewer.