AGITB

Example

To enable this module, do:

import asterisk.agitb, asterisk.agi
asterisk.agitb.enable(display = False, logdir = '/var/log/asterisk/')

agi = asterisk.agi.AGI()
asterisk.agitb.enable(agi, False, '/var/log/asterisk')

at the top of your script. The optional arguments to enable() are:

  • agi - the agi handle to write verbose messages to
  • display - if true, tracebacks are displayed on the asterisk console (used with the agi option)
  • logdir - if set, tracebacks are written to files in this directory
  • context - number of lines of source code to show for each stack frame

By default, tracebacks are displayed but not saved, and the context is 5 lines.

You may want to add a logdir if you call agitb.enable() before you have an agi.AGI() handle.

Alternatively, if you have caught an exception and want agitb to display it for you, call agitb.handler(). The optional argument to handler() is a 3-item tuple (etype, evalue, etb) just like the value of sys.exc_info(). If you do not pass anything to handler() it will use sys.exc_info().

This script was adapted from Ka-Ping Yee’s cgitb.

Specification

class asterisk.agitb.Hook(display=1, logdir=None, context=5, file=None, agi=None)[source]

A hook to replace sys.excepthook that shows tracebacks in HTML.

asterisk.agitb.enable(agi=None, display=1, logdir=None, context=5)[source]

Install an exception handler that formats tracebacks as HTML.

The optional argument ‘display’ can be set to 0 to suppress sending the traceback to the browser, and ‘logdir’ can be set to a directory to cause tracebacks to be written to files there.

asterisk.agitb.lookup(name, frame, locals)[source]

Find the value for a given name in the given environment.

asterisk.agitb.scanvars(reader, frame, locals)[source]

Scan one logical line of Python and look up values of variables used.

asterisk.agitb.text(eparams, context=5)[source]

Return a plain text document describing a given traceback.