Mercurial > p > roundup > code
comparison roundup/cgi/cgitb.py @ 4362:74476eaac38a
more modernisation
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 26 Feb 2010 00:38:53 +0000 |
| parents | b1e614c6759f |
| children | 6e3e4f24c753 |
comparison
equal
deleted
inserted
replaced
| 4360:661466ba19cd | 4362:74476eaac38a |
|---|---|
| 35 '<font color="white" size="-5"> > </font> ' + | 35 '<font color="white" size="-5"> > </font> ' + |
| 36 '</table>' * 5) | 36 '</table>' * 5) |
| 37 | 37 |
| 38 def niceDict(indent, dict): | 38 def niceDict(indent, dict): |
| 39 l = [] | 39 l = [] |
| 40 keys = dict.keys() | 40 for k in sorted(dict): |
| 41 keys.sort() | |
| 42 for k in keys: | |
| 43 v = dict[k] | 41 v = dict[k] |
| 44 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k, | 42 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k, |
| 45 cgi.escape(repr(v)))) | 43 cgi.escape(repr(v)))) |
| 46 return '\n'.join(l) | 44 return '\n'.join(l) |
| 47 | 45 |
| 57 from roundup.cgi.PageTemplates.Expressions import TraversalError | 55 from roundup.cgi.PageTemplates.Expressions import TraversalError |
| 58 t = inspect.trace(context) | 56 t = inspect.trace(context) |
| 59 t.reverse() | 57 t.reverse() |
| 60 for frame, file, lnum, func, lines, index in t: | 58 for frame, file, lnum, func, lines, index in t: |
| 61 args, varargs, varkw, locals = inspect.getargvalues(frame) | 59 args, varargs, varkw, locals = inspect.getargvalues(frame) |
| 62 if locals.has_key('__traceback_info__'): | 60 if '__traceback_info__' in locals: |
| 63 ti = locals['__traceback_info__'] | 61 ti = locals['__traceback_info__'] |
| 64 if isinstance(ti, TraversalError): | 62 if isinstance(ti, TraversalError): |
| 65 s = [] | 63 s = [] |
| 66 for name, info in ti.path: | 64 for name, info in ti.path: |
| 67 s.append(_('<li>"%(name)s" (%(info)s)</li>') | 65 s.append(_('<li>"%(name)s" (%(info)s)</li>') |
| 70 l.append(_('<li>Looking for "%(name)s", ' | 68 l.append(_('<li>Looking for "%(name)s", ' |
| 71 'current path:<ol>%(path)s</ol></li>' | 69 'current path:<ol>%(path)s</ol></li>' |
| 72 ) % {'name': ti.name, 'path': s}) | 70 ) % {'name': ti.name, 'path': s}) |
| 73 else: | 71 else: |
| 74 l.append(_('<li>In %s</li>') % esc(str(ti))) | 72 l.append(_('<li>In %s</li>') % esc(str(ti))) |
| 75 if locals.has_key('__traceback_supplement__'): | 73 if '__traceback_supplement__' in locals: |
| 76 ts = locals['__traceback_supplement__'] | 74 ts = locals['__traceback_supplement__'] |
| 77 if len(ts) == 2: | 75 if len(ts) == 2: |
| 78 supp, context = ts | 76 supp, context = ts |
| 79 s = _('A problem occurred in your template "%s".') \ | 77 s = _('A problem occurred in your template "%s".') \ |
| 80 % str(context.id) | 78 % str(context.id) |
| 109 l.append('<p> </p>') | 107 l.append('<p> </p>') |
| 110 return '\n'.join(l) | 108 return '\n'.join(l) |
| 111 | 109 |
| 112 def html(context=5, i18n=None): | 110 def html(context=5, i18n=None): |
| 113 _ = get_translator(i18n) | 111 _ = get_translator(i18n) |
| 114 etype, evalue = sys.exc_type, sys.exc_value | 112 etype, evalue = sys.exc_info()[0], sys.exc_info()[1] |
| 115 if type(etype) is types.ClassType: | 113 if type(etype) is type: |
| 116 etype = etype.__name__ | 114 etype = etype.__name__ |
| 117 pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable | 115 pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable |
| 118 head = pydoc.html.heading( | 116 head = pydoc.html.heading( |
| 119 _('<font size=+1><strong>%(exc_type)s</strong>: %(exc_value)s</font>') | 117 _('<font size=+1><strong>%(exc_type)s</strong>: %(exc_value)s</font>') |
| 120 % {'exc_type': etype, 'exc_value': evalue}, | 118 % {'exc_type': etype, 'exc_value': evalue}, |
| 167 except IndexError: | 165 except IndexError: |
| 168 pass | 166 pass |
| 169 lvals = [] | 167 lvals = [] |
| 170 for name in names: | 168 for name in names: |
| 171 if name in frame.f_code.co_varnames: | 169 if name in frame.f_code.co_varnames: |
| 172 if locals.has_key(name): | 170 if name in locals: |
| 173 value = pydoc.html.repr(locals[name]) | 171 value = pydoc.html.repr(locals[name]) |
| 174 else: | 172 else: |
| 175 value = _('<em>undefined</em>') | 173 value = _('<em>undefined</em>') |
| 176 name = '<strong>%s</strong>' % name | 174 name = '<strong>%s</strong>' % name |
| 177 else: | 175 else: |
| 178 if frame.f_globals.has_key(name): | 176 if name in frame.f_globals: |
| 179 value = pydoc.html.repr(frame.f_globals[name]) | 177 value = pydoc.html.repr(frame.f_globals[name]) |
| 180 else: | 178 else: |
| 181 value = _('<em>undefined</em>') | 179 value = _('<em>undefined</em>') |
| 182 name = '<em>global</em> <strong>%s</strong>' % name | 180 name = '<em>global</em> <strong>%s</strong>' % name |
| 183 lvals.append('%s = %s'%(name, value)) | 181 lvals.append('%s = %s'%(name, value)) |
