-def cgi_error_guts():
- """
- Report an exception while we're acting as a CGI, together with lots of
- information about our state.
-
- Our caller has, probably at great expense, arranged that we can format lots
- of text.
- """
-
- ## Grab the exception information.
- exty, exval, extb = SYS.exc_info()
-
- ## Print the exception itself.
- PRINT("""\
-<h2>Exception</h2>
-<pre>%s</pre>""" % html_quotify(
- '\n'.join(TB.format_exception_only(exty, exval))))
-
- ## Format a traceback so we can find out what has gone wrong.
- PRINT("""\
-<h2>Traceback</h2>
-<ol>""")
- for file, line, func, text in TB.extract_tb(extb, 20):
- PRINT("<li><b>%s</b>:%d (<b>%s</b>)" % (
- htmlescape(file), line, htmlescape(func)))
- if text is not None:
- PRINT("<br><tt>%s</tt>" % htmlescape(text))
- PRINT("</ol>")
-
- ## Format various useful tables.
- def fmt_dict(d):
- fmt_kvlist(d.iteritems())
- def fmt_kvlist(l):
- for k, v in sorted(l):
- PRINT("<tr><th align=right valign=top>%s<td><tt>%s</tt>" % (
- htmlescape(k), htmlescape(v)))
- def fmt_list(l):
- for i in l:
- PRINT("<tr><tt>%s</tt>" % htmlescape(i))
-
- PRINT("""\
-<h2>Parameters</h2>""")
- for what, thing, how in [('Query', PARAM, fmt_kvlist),
- ('Cookies', COOKIE, fmt_dict),
- ('Path', PATH, fmt_list),
- ('Environment', ENV, fmt_dict)]:
- PRINT("<h3>%s</h3>\n<table>" % what)
- how(thing)
- PRINT("</table>")
-
-def cgi_error():
- """
- Report an exception while in CGI mode.
-
- If we've not produced a header yet, then we can do that, and produce a
- status code and everything; otherwise we'll have to make do with a small
- piece of the page.
- """
- if OUT.headerp:
- PRINT("<div class=exception>")
- cgi_error_guts()
- PRINT("</div>\n</body></html>")
- else:
- with html("chpwd internal error", status = 500):
- PRINT("<h1>chpwd internal error</h1>")
- cgi_error_guts()
- SYS.exit(1)
-