comparison roundup/cgi/cgitb.py @ 1136:7e193bbda38e

added generic item editing . much nicer layout of template rendering errors . added context/is_edit_ok and context/is_view_ok convenience methods and implemented use of them in the classic template
author Richard Jones <richard@users.sourceforge.net>
date Fri, 13 Sep 2002 03:31:19 +0000
parents e5826025eeb7
children b862bbf2067a
comparison
equal deleted inserted replaced
1135:645a7caa2e9c 1136:7e193bbda38e
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.5 2002-09-10 01:07:05 richard Exp $ 4 # $Id: cgitb.py,v 1.6 2002-09-13 03:31:18 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
10 import sys, os, types, string, keyword, linecache, tokenize, inspect 10 import sys, os, types, string, keyword, linecache, tokenize, inspect, cgi
11 import pydoc, traceback 11 import pydoc, traceback
12 12
13 from roundup.i18n import _ 13 from roundup.i18n import _
14 14
15 def breaker(): 15 def breaker():
18 '</table>' * 5) 18 '</table>' * 5)
19 19
20 def niceDict(indent, dict): 20 def niceDict(indent, dict):
21 l = [] 21 l = []
22 for k,v in dict.items(): 22 for k,v in dict.items():
23 l.append('%s%s: %r'%(indent,k,v)) 23 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k,
24 cgi.escape(repr(v))))
24 return '\n'.join(l) 25 return '\n'.join(l)
25 26
26 def pt_html(context=5): 27 def pt_html(context=5):
27 import cgi 28 l = ['<h1>Templating Error</h1>'
28 etype, evalue = sys.exc_type, sys.exc_value 29 '<p class="help">Debugging information follows</p>'
29 if type(etype) is types.ClassType: 30 '<ol>']
30 etype = etype.__name__ 31 from roundup.cgi.PageTemplates.Expressions import TraversalError
31 pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable
32 head = pydoc.html.heading(
33 '<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue),
34 '#ffffff', '#777777', pyver)
35
36 head = head + _('<p>A problem occurred in your template</p><pre>')
37
38 l = []
39 for frame, file, lnum, func, lines, index in inspect.trace(context): 32 for frame, file, lnum, func, lines, index in inspect.trace(context):
40 args, varargs, varkw, locals = inspect.getargvalues(frame) 33 args, varargs, varkw, locals = inspect.getargvalues(frame)
41 if locals.has_key('__traceback_info__'): 34 if locals.has_key('__traceback_info__'):
42 ti = locals['__traceback_info__'] 35 ti = locals['__traceback_info__']
43 l.append(str(ti)) 36 if isinstance(ti, TraversalError):
37 s = []
38 for name, info in ti.path:
39 s.append('<li>"%s" (%s)</li>'%(name,cgi.escape(repr(info))))
40 s = '\n'.join(s)
41 l.append('<li>Looking for "%s", current path:<ol>%s</ol></li>'%(
42 ti.name, s))
43 else:
44 l.append('<li>In %s</li>'%cgi.escape(str(ti)))
44 if locals.has_key('__traceback_supplement__'): 45 if locals.has_key('__traceback_supplement__'):
45 ts = locals['__traceback_supplement__'] 46 ts = locals['__traceback_supplement__']
46 if len(ts) == 2: 47 if len(ts) == 2:
47 supp, context = ts 48 supp, context = ts
48 l.append('in template %r'%context.id) 49 l.append('<li>A problem occurred in your template "%s"</li>'%
50 str(context.id))
49 elif len(ts) == 3: 51 elif len(ts) == 3:
50 supp, context, info = ts 52 supp, context, info = ts
51 l.append('in expression %r\n current variables:\n%s\n%s\n'%(info, 53 l.append('''
52 niceDict(' ', context.global_vars), 54 <li>While evaluating the %r expression on line %d
53 niceDict(' ', context.local_vars))) 55 <table class="otherinfo" style="font-size: 90%%">
54 # context._scope_stack)) 56 <tr><th colspan="2" class="header">Current variables:</th></tr>
57 %s
58 %s
59 </table></li>
60 '''%(info, context.position[0], niceDict(' ', context.global_vars),
61 niceDict(' ', context.local_vars)))
55 62
56 l.append('\n') 63 l.append('''
57 l.append(''.join(traceback.format_exception(etype, evalue, 64 </ol>
58 sys.exc_traceback))) 65 <table style="font-size: 80%%; color: gray">
59 return head + cgi.escape('\n'.join(l)) + '</pre><p>&nbsp;</p>' 66 <tr><th class="header" align="left">Full traceback:</th></tr>
67 <tr><td><pre>%s</pre></td></tr>
68 </table>'''%cgi.escape(''.join(traceback.format_exception(sys.exc_type,
69 sys.exc_value, sys.exc_traceback))))
70 l.append('<p>&nbsp;</p>')
71 return '\n'.join(l)
60 72
61 def html(context=5): 73 def html(context=5):
62 etype, evalue = sys.exc_type, sys.exc_value 74 etype, evalue = sys.exc_type, sys.exc_value
63 if type(etype) is types.ClassType: 75 if type(etype) is types.ClassType:
64 etype = etype.__name__ 76 etype = etype.__name__

Roundup Issue Tracker: http://roundup-tracker.org/