summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-20 20:22:39 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-20 20:22:39 (GMT)
commitf85de8a440f56c5e7ac40ff623d6099f34b9e281 (patch)
treed555771549b4eeeb12a4334a9b4f60291d42056b /Lib
parent6ba66d01160ccb5a2dbf0d6a53cdf9fc35e48505 (diff)
downloadcpython-f85de8a440f56c5e7ac40ff623d6099f34b9e281.zip
cpython-f85de8a440f56c5e7ac40ff623d6099f34b9e281.tar.gz
cpython-f85de8a440f56c5e7ac40ff623d6099f34b9e281.tar.bz2
Added print_exception() convenience function.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/cgi.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 9fca4d8..587999c 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -397,7 +397,7 @@ backwards compatible and debugging classes and functions?
"""
-__version__ = "2.0b2"
+__version__ = "2.0b3"
# Imports
@@ -1089,9 +1089,27 @@ def test(environ=os.environ):
print_directory()
print_arguments()
print_environ_usage()
+ def f():
+ exec "testing print_exception() -- <I>italics?</I>"
+ def g(f=f):
+ f()
+ print "<H3>What follows is a test, not an actual exception:</H3>"
+ g()
except:
- print "\n\n<PRE>" # Turn off HTML word wrap
- traceback.print_exc()
+ print_exception()
+
+def print_exception(type=None, value=None, tb=None, limit=None):
+ if type is None:
+ type, value, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
+ import traceback
+ print
+ print "<H3>Traceback (innermost last):</H3>"
+ list = traceback.format_tb(tb, limit) + \
+ traceback.format_exception_only(type, value)
+ print "<PRE>%s<B>%s</B></PRE>" % (
+ escape(string.join(list[:-1], "")),
+ escape(list[-1]),
+ )
def print_environ(environ=os.environ):
"""Dump the shell environment as HTML."""