From: Guido van Rossum Date: Tue, 20 Aug 1996 20:22:39 +0000 (+0000) Subject: Added print_exception() convenience function. X-Git-Tag: v1.4b3~85 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f85de8a440f56c5e7ac40ff623d6099f34b9e281;p=thirdparty%2FPython%2Fcpython.git Added print_exception() convenience function. --- diff --git a/Lib/cgi.py b/Lib/cgi.py index 9fca4d8e7da9..587999c5fe32 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() -- italics?" + def g(f=f): + f() + print "

What follows is a test, not an actual exception:

" + g() except: - print "\n\n
"	# 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 "

Traceback (innermost last):

" + list = traceback.format_tb(tb, limit) + \ + traceback.format_exception_only(type, value) + print "
%s%s
" % ( + escape(string.join(list[:-1], "")), + escape(list[-1]), + ) def print_environ(environ=os.environ): """Dump the shell environment as HTML."""