Mercurial > p > roundup > code
comparison roundup/cgi/cgitb.py @ 1396:cce5b4309005
extra info in template error report
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 21 Jan 2003 23:54:28 +0000 |
| parents | b862bbf2067a |
| children | 0e19e99075e3 15a7aae3f34c |
comparison
equal
deleted
inserted
replaced
| 1395:9c7055b9910a | 1396:cce5b4309005 |
|---|---|
| 1 # | 1 # |
| 2 # This module was written by Ka-Ping Yee, <ping@lfw.org>. | 2 # This module was written by Ka-Ping Yee, <ping@lfw.org>. |
| 3 # | 3 # |
| 4 # $Id: cgitb.py,v 1.7 2002-09-25 02:10:25 richard Exp $ | 4 # $Id: cgitb.py,v 1.8 2003-01-21 23:54:28 richard Exp $ |
| 5 | 5 |
| 6 __doc__ = """ | 6 __doc__ = """ |
| 7 Extended CGI traceback handler by Ka-Ping Yee, <ping@lfw.org>. | 7 Extended CGI traceback handler by Ka-Ping Yee, <ping@lfw.org>. |
| 8 """ | 8 """ |
| 9 | 9 |
| 23 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k, | 23 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k, |
| 24 cgi.escape(repr(v)))) | 24 cgi.escape(repr(v)))) |
| 25 return '\n'.join(l) | 25 return '\n'.join(l) |
| 26 | 26 |
| 27 def pt_html(context=5): | 27 def pt_html(context=5): |
| 28 l = ['<h1>Templating Error</h1>' | 28 esc = cgi.escape |
| 29 '<p class="help">Debugging information follows</p>' | 29 l = ['<h1>Templating Error</h1>', |
| 30 '<ol>'] | 30 '<p><b>%s</b>: %s</p>'%(esc(str(sys.exc_type)), |
| 31 esc(str(sys.exc_value))), | |
| 32 '<p class="help">Debugging information follows</p>', | |
| 33 '<ol>',] | |
| 31 from roundup.cgi.PageTemplates.Expressions import TraversalError | 34 from roundup.cgi.PageTemplates.Expressions import TraversalError |
| 32 t = inspect.trace(context) | 35 t = inspect.trace(context) |
| 33 t.reverse() | 36 t.reverse() |
| 34 for frame, file, lnum, func, lines, index in t: | 37 for frame, file, lnum, func, lines, index in t: |
| 35 args, varargs, varkw, locals = inspect.getargvalues(frame) | 38 args, varargs, varkw, locals = inspect.getargvalues(frame) |
| 36 if locals.has_key('__traceback_info__'): | 39 if locals.has_key('__traceback_info__'): |
| 37 ti = locals['__traceback_info__'] | 40 ti = locals['__traceback_info__'] |
| 38 if isinstance(ti, TraversalError): | 41 if isinstance(ti, TraversalError): |
| 39 s = [] | 42 s = [] |
| 40 for name, info in ti.path: | 43 for name, info in ti.path: |
| 41 s.append('<li>"%s" (%s)</li>'%(name,cgi.escape(repr(info)))) | 44 s.append('<li>"%s" (%s)</li>'%(name, esc(repr(info)))) |
| 42 s = '\n'.join(s) | 45 s = '\n'.join(s) |
| 43 l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( | 46 l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%( |
| 44 ti.name, s)) | 47 ti.name, s)) |
| 45 else: | 48 else: |
| 46 l.append('<li>In %s</li>'%cgi.escape(str(ti))) | 49 l.append('<li>In %s</li>'%esc(str(ti))) |
| 47 if locals.has_key('__traceback_supplement__'): | 50 if locals.has_key('__traceback_supplement__'): |
| 48 ts = locals['__traceback_supplement__'] | 51 ts = locals['__traceback_supplement__'] |
| 49 if len(ts) == 2: | 52 if len(ts) == 2: |
| 50 supp, context = ts | 53 supp, context = ts |
| 51 s = 'A problem occurred in your template "%s".'%str(context.id) | 54 s = 'A problem occurred in your template "%s".'%str(context.id) |
| 52 if context._v_errors: | 55 if context._v_errors: |
| 53 s = s + '<br>' + '<br>'.join( | 56 s = s + '<br>' + '<br>'.join( |
| 54 [cgi.escape(x) for x in context._v_errors]) | 57 [esc(x) for x in context._v_errors]) |
| 55 l.append('<li>%s</li>'%s) | 58 l.append('<li>%s</li>'%s) |
| 56 elif len(ts) == 3: | 59 elif len(ts) == 3: |
| 57 supp, context, info = ts | 60 supp, context, info = ts |
| 58 l.append(''' | 61 l.append(''' |
| 59 <li>While evaluating the %r expression on line %d | 62 <li>While evaluating the %r expression on line %d |
