[go: up one dir, main page]

Menu

[cec0f2]: / roundup / cgitb.py  Maximize  Restore  History

Download this file

150 lines (134 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
# This module is free software, and you may redistribute it and/or modify
# under the same terms as Python, so long as this copyright message and
# disclaimer are retained in their original form.
#
# IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
# $Id: cgitb.py,v 1.5 2001-08-07 00:24:42 richard Exp $
import sys, os, types, string, keyword, linecache, tokenize, inspect, pydoc
def breaker():
return ('<body bgcolor="#f0f0ff">' +
'<font color="#f0f0ff" size="-5"> > </font> ' +
'</table>' * 5)
def html(context=5):
etype, evalue = sys.exc_type, sys.exc_value
if type(etype) is types.ClassType:
etype = etype.__name__
pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable
head = pydoc.html.heading(
'<font size=+1><strong>%s</strong>: %s</font>'%(str(etype), str(evalue)),
'#ffffff', '#aa55cc', pyver)
head = head + ('<p>A problem occurred while running a Python script. '
'Here is the sequence of function calls leading up to '
'the error, with the most recent (innermost) call first. '
'The exception attributes are:')
indent = '<tt><small>%s</small>&nbsp;</tt>' % ('&nbsp;' * 5)
traceback = []
for frame, file, lnum, func, lines, index in inspect.trace(context):
if file is None:
link = '&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;'
else:
file = os.path.abspath(file)
link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file))
args, varargs, varkw, locals = inspect.getargvalues(frame)
if func == '?':
call = ''
else:
call = 'in <strong>%s</strong>' % func + inspect.formatargvalues(
args, varargs, varkw, locals,
formatvalue=lambda value: '=' + pydoc.html.repr(value))
level = '''
<table width="100%%" bgcolor="#d8bbff" cellspacing=0 cellpadding=2 border=0>
<tr><td>%s %s</td></tr></table>''' % (link, call)
if file is None:
traceback.append('<p>' + level)
continue
# do a fil inspection
names = []
def tokeneater(type, token, start, end, line, names=names):
if type == tokenize.NAME and token not in keyword.kwlist:
if token not in names:
names.append(token)
if type == tokenize.NEWLINE: raise IndexError
def linereader(file=file, lnum=[lnum]):
line = linecache.getline(file, lnum[0])
lnum[0] = lnum[0] + 1
return line
try:
tokenize.tokenize(linereader, tokeneater)
except IndexError: pass
lvals = []
for name in names:
if name in frame.f_code.co_varnames:
if locals.has_key(name):
value = pydoc.html.repr(locals[name])
else:
value = '<em>undefined</em>'
name = '<strong>%s</strong>' % name
else:
if frame.f_globals.has_key(name):
value = pydoc.html.repr(frame.f_globals[name])
else:
value = '<em>undefined</em>'
name = '<em>global</em> <strong>%s</strong>' % name
lvals.append('%s&nbsp;= %s' % (name, value))
if lvals:
lvals = string.join(lvals, ', ')
lvals = indent + '''
<small><font color="#909090">%s</font></small><br>''' % lvals
else:
lvals = ''
excerpt = []
i = lnum - index
for line in lines:
number = '&nbsp;' * (5-len(str(i))) + str(i)
number = '<small><font color="#909090">%s</font></small>' % number
line = '<tt>%s&nbsp;%s</tt>' % (number, pydoc.html.preformat(line))
if i == lnum:
line = '''
<table width="100%%" bgcolor="#ffccee" cellspacing=0 cellpadding=0 border=0>
<tr><td>%s</td></tr></table>''' % line
excerpt.append('\n' + line)
if i == lnum:
excerpt.append(lvals)
i = i + 1
traceback.append('<p>' + level + string.join(excerpt, '\n'))
traceback.reverse()
exception = '<p><strong>%s</strong>: %s' % (str(etype), str(evalue))
attribs = []
if type(evalue) is types.InstanceType:
for name in dir(evalue):
value = pydoc.html.repr(getattr(evalue, name))
attribs.append('<br>%s%s&nbsp;= %s' % (indent, name, value))
return head + string.join(attribs) + string.join(traceback) + '<p>&nbsp;</p>'
def handler():
print breaker()
print html()
#
# $Log: not supported by cvs2svn $
# Revision 1.4 2001/08/07 00:15:51 richard
# Added the copyright/license notice to (nearly) all files at request of
# Bizar Software.
#
# Revision 1.3 2001/07/29 07:01:39 richard
# Added vim command to all source so that we don't get no steenkin' tabs :)
#
# Revision 1.2 2001/07/22 12:09:32 richard
# Final commit of Grande Splite
#
# Revision 1.1 2001/07/22 11:58:35 richard
# More Grande Splite
#
#
# vim: set filetype=python ts=4 sw=4 et si