More comprehensive traceback formatting for Python scripts.
To enable this module, do:
import cgitb; cgitb.enable()
at the top of your script. The optional arguments to enable() are:
display - if true, tracebacks are displayed in the web browser
logdir - if set, tracebacks are written to files in this directory
context - number of lines of source code to show for each stack frame
format - 'text' or 'html' controls the output format
viewClass - sub class of View. Create this if you want to customize the
layout of the traceback.
debug - may be used by viewClass to decide on level of detail
By default, tracebacks are displayed but not saved, the context is 5 lines
and the output format is 'html' (for backwards compatibility with the
original use of this module).
Alternatively, if you have caught an exception and want cgitb to display it
for you, call cgitb.handler(). The optional argument to handler() is a
3-item tuple (etype, evalue, etb) just like the value of sys.exc_info().
The default handler displays output as HTML.
2005-04-22 Nir Soffer <nirs@freeshell.org>
Rewrite:
- Refactor html and text functions to View class, HTMLFormatter and
TextFormatter. No more duplicate formating code.
- Layout is done with minimal html and css, in a way it can't be
affected by surrounding code.
- Built to be easy to subclass and modify without duplicating code.
- Change layout, important details come first.
- Factor frame analyzing and formatting into separate class.
- Add debug argument, can be used to change error display e.g. user
error view, developer error view.
- Add viewClass argument, make it easy to customize the traceback view.
- Easy to customize system details and application details.
The main goal of this rewrite was to have a traceback that can render
few tracebacks combined. It's needed when you wrap an expection and want
to print both the traceback up to the wrapper exception, and the
original traceback. There is no code to support this here, but it's easy
to add by using your own View sub class.