diff --git a/roundup/cgi/cgitb.py b/roundup/cgi/cgitb.py
index 21f19426d4eb55c39db339223fc1956904501f95..630121b7d65c5518677782feba285c90da780503 100644 (file)
--- a/roundup/cgi/cgitb.py
+++ b/roundup/cgi/cgitb.py
#
# This module was written by Ka-Ping Yee, <ping@lfw.org>.
#
-# $Id: cgitb.py,v 1.1 2002-08-30 08:28:44 richard Exp $
+# $Id: cgitb.py,v 1.6 2002-09-13 03:31:18 richard Exp $
__doc__ = """
Extended CGI traceback handler by Ka-Ping Yee, <ping@lfw.org>.
"""
-import sys, os, types, string, keyword, linecache, tokenize, inspect, pydoc
+import sys, os, types, string, keyword, linecache, tokenize, inspect, cgi
+import pydoc, traceback
from roundup.i18n import _
'<font color="white" size="-5"> > </font> ' +
'</table>' * 5)
+def niceDict(indent, dict):
+ l = []
+ for k,v in dict.items():
+ l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k,
+ cgi.escape(repr(v))))
+ return '\n'.join(l)
+
+def pt_html(context=5):
+ l = ['<h1>Templating Error</h1>'
+ '<p class="help">Debugging information follows</p>'
+ '<ol>']
+ from roundup.cgi.PageTemplates.Expressions import TraversalError
+ for frame, file, lnum, func, lines, index in inspect.trace(context):
+ args, varargs, varkw, locals = inspect.getargvalues(frame)
+ if locals.has_key('__traceback_info__'):
+ ti = locals['__traceback_info__']
+ if isinstance(ti, TraversalError):
+ s = []
+ for name, info in ti.path:
+ s.append('<li>"%s" (%s)</li>'%(name,cgi.escape(repr(info))))
+ s = '\n'.join(s)
+ l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%(
+ ti.name, s))
+ else:
+ l.append('<li>In %s</li>'%cgi.escape(str(ti)))
+ if locals.has_key('__traceback_supplement__'):
+ ts = locals['__traceback_supplement__']
+ if len(ts) == 2:
+ supp, context = ts
+ l.append('<li>A problem occurred in your template "%s"</li>'%
+ str(context.id))
+ elif len(ts) == 3:
+ supp, context, info = ts
+ l.append('''
+<li>While evaluating the %r expression on line %d
+<table class="otherinfo" style="font-size: 90%%">
+ <tr><th colspan="2" class="header">Current variables:</th></tr>
+ %s
+ %s
+</table></li>
+'''%(info, context.position[0], niceDict(' ', context.global_vars),
+ niceDict(' ', context.local_vars)))
+
+ l.append('''
+</ol>
+<table style="font-size: 80%%; color: gray">
+ <tr><th class="header" align="left">Full traceback:</th></tr>
+ <tr><td><pre>%s</pre></td></tr>
+</table>'''%cgi.escape(''.join(traceback.format_exception(sys.exc_type,
+ sys.exc_value, sys.exc_traceback))))
+ l.append('<p> </p>')
+ return '\n'.join(l)
+
def html(context=5):
etype, evalue = sys.exc_type, sys.exc_value
if type(etype) is types.ClassType:
traceback = []
for frame, file, lnum, func, lines, index in inspect.trace(context):
if file is None:
- link = '<file is None - probably inside <tt>eval</tt> or <tt>exec</tt>>'
+ link = '''<file is None - probably inside <tt>eval</tt> or
+ <tt>exec</tt>>'''
else:
file = os.path.abspath(file)
link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file))
traceback.append('<p>' + level)
continue
- # do a fil inspection
+ # do a file inspection
names = []
def tokeneater(type, token, start, end, line, names=names):
if type == tokenize.NAME and token not in keyword.kwlist:
try:
tokenize.tokenize(linereader, tokeneater)
- except IndexError: pass
+ except IndexError:
+ pass
lvals = []
for name in names:
if name in frame.f_code.co_varnames:
else:
value = _('<em>undefined</em>')
name = '<em>global</em> <strong>%s</strong>' % name
- lvals.append('%s = %s' % (name, value))
+ lvals.append('%s = %s'%(name, value))
if lvals:
lvals = string.join(lvals, ', ')
- lvals = indent + '''
-<small><font color="#909090">%s</font></small><br>''' % lvals
+ lvals = indent + '<small><font color="#909090">%s'\
+ '</font></small><br>'%lvals
else:
lvals = ''
print breaker()
print html()
-#
-# $Log: not supported by cvs2svn $
-# Revision 1.10 2002/01/16 04:49:45 richard
-# Handle a special case that the CGI interface tickles. I need to check if
-# this needs fixing in python's core.
-#
-# Revision 1.9 2002/01/08 11:56:24 richard
-# missed an import _
-#
-# Revision 1.8 2002/01/05 02:22:32 richard
-# i18n'ification
-#
-# Revision 1.7 2001/11/22 15:46:42 jhermann
-# Added module docstrings to all modules.
-#
-# Revision 1.6 2001/09/29 13:27:00 richard
-# CGI interfaces now spit up a top-level index of all the instances they can
-# serve.
-#
-# Revision 1.5 2001/08/07 00:24:42 richard
-# stupid typo
-#
-# 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