X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fcgi%2Fcgitb.py;h=fab248483a2e3cd1808340f339249aab531e2276;hb=5c31da71b45e1b9a8cf9f533540d549d3c961eed;hp=dce420e699b427d6b75ac3cedbe7290150029425;hpb=d371ceff3c1ce498681ae6a625cf86affa575679;p=roundup.git diff --git a/roundup/cgi/cgitb.py b/roundup/cgi/cgitb.py index dce420e..fab2484 100644 --- a/roundup/cgi/cgitb.py +++ b/roundup/cgi/cgitb.py @@ -1,13 +1,13 @@ # # This module was written by Ka-Ping Yee, . # -# $Id: cgitb.py,v 1.4 2002-09-09 05:28:48 richard Exp $ +# $Id: cgitb.py,v 1.7 2002-09-25 02:10:25 richard Exp $ __doc__ = """ Extended CGI traceback handler by Ka-Ping Yee, . """ -import sys, os, types, string, keyword, linecache, tokenize, inspect +import sys, os, types, string, keyword, linecache, tokenize, inspect, cgi import pydoc, traceback from roundup.i18n import _ @@ -20,43 +20,60 @@ def breaker(): def niceDict(indent, dict): l = [] for k,v in dict.items(): - l.append('%s%s: %r'%(indent,k,v)) + l.append('%s%s'%(k, + cgi.escape(repr(v)))) return '\n'.join(l) def pt_html(context=5): - import cgi - etype, evalue = sys.exc_type, sys.exc_value - if type(etype) is types.ClassType: - etype = etype.__name__ - pyver = 'Python ' + string.split(sys.version)[0] + '
' + sys.executable - head = pydoc.html.heading( - '%s: %s'%(etype, evalue), - '#ffffff', '#777777', pyver) - - head = head + _('

A problem occurred in your template

')
-
-    l = []
-    for frame, file, lnum, func, lines, index in inspect.trace(context):
+    l = ['

Templating Error

' + '

Debugging information follows

' + '
    '] + from roundup.cgi.PageTemplates.Expressions import TraversalError + t = inspect.trace(context) + t.reverse() + for frame, file, lnum, func, lines, index in t: args, varargs, varkw, locals = inspect.getargvalues(frame) if locals.has_key('__traceback_info__'): ti = locals['__traceback_info__'] - l.append(str(ti)) + if isinstance(ti, TraversalError): + s = [] + for name, info in ti.path: + s.append('
  1. "%s" (%s)
  2. '%(name,cgi.escape(repr(info)))) + s = '\n'.join(s) + l.append('
  3. Looking for "%s", current path:
      %s
  4. '%( + ti.name, s)) + else: + l.append('
  5. In %s
  6. '%cgi.escape(str(ti))) if locals.has_key('__traceback_supplement__'): ts = locals['__traceback_supplement__'] if len(ts) == 2: supp, context = ts - l.append('in template %r'%context.id) + s = 'A problem occurred in your template "%s".'%str(context.id) + if context._v_errors: + s = s + '
    ' + '
    '.join( + [cgi.escape(x) for x in context._v_errors]) + l.append('
  7. %s
  8. '%s) elif len(ts) == 3: supp, context, info = ts - l.append('in expression %r\n current variables:\n%s\n%s\n'%(info, - niceDict(' ', context.global_vars), - niceDict(' ', context.local_vars))) - # context._scope_stack)) - - l.append('\n') - l.append(''.join(traceback.format_exception(etype, evalue, - sys.exc_traceback))) - return head + cgi.escape('\n'.join(l)) + '

 

' + l.append(''' +
  • While evaluating the %r expression on line %d + + + %s + %s +
    Current variables:
  • +'''%(info, context.position[0], niceDict(' ', context.global_vars), + niceDict(' ', context.local_vars))) + + l.append(''' + + + + +
    Full traceback:
    %s
    '''%cgi.escape(''.join(traceback.format_exception(sys.exc_type, + sys.exc_value, sys.exc_traceback)))) + l.append('

     

    ') + return '\n'.join(l) def html(context=5): etype, evalue = sys.exc_type, sys.exc_value @@ -166,49 +183,4 @@ def handler(): print breaker() print html() -# -# $Log: not supported by cvs2svn $ -# Revision 1.3 2002/09/06 07:23:29 richard -# tweak -# -# Revision 1.2 2002/09/06 07:21:31 richard -# much nicer error messages when there's a templating error -# -# Revision 1.1 2002/08/30 08:28:44 richard -# New CGI interface support -# -# 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