Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
cgitb.Hook Class Reference

List of all members.

Public Member Functions

def __init__
def __call__
def handle

Public Attributes

 display
 logdir
 context
 file
 format

Detailed Description

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

Definition at line 257 of file cgitb.py.


Constructor & Destructor Documentation

def cgitb.Hook.__init__ (   self,
  display = 1,
  logdir = None,
  context = 5,
  file = None,
  format = "html" 
)

Definition at line 261 of file cgitb.py.

00261 
00262                  format="html"):
00263         self.display = display          # send tracebacks to browser if true
00264         self.logdir = logdir            # log tracebacks to files if not None
00265         self.context = context          # number of source code lines per frame
00266         self.file = file or sys.stdout  # place to send the output
00267         self.format = format

Here is the caller graph for this function:


Member Function Documentation

def cgitb.Hook.__call__ (   self,
  etype,
  evalue,
  etb 
)

Definition at line 268 of file cgitb.py.

00268 
00269     def __call__(self, etype, evalue, etb):
00270         self.handle((etype, evalue, etb))

Here is the call graph for this function:

def cgitb.Hook.handle (   self,
  info = None 
)

Definition at line 271 of file cgitb.py.

00271 
00272     def handle(self, info=None):
00273         info = info or sys.exc_info()
00274         if self.format == "html":
00275             self.file.write(reset())
00276 
00277         formatter = (self.format=="html") and html or text
00278         plain = False
00279         try:
00280             doc = formatter(info, self.context)
00281         except:                         # just in case something goes wrong
00282             doc = ''.join(traceback.format_exception(*info))
00283             plain = True
00284 
00285         if self.display:
00286             if plain:
00287                 doc = doc.replace('&', '&amp;').replace('<', '&lt;')
00288                 self.file.write('<pre>' + doc + '</pre>\n')
00289             else:
00290                 self.file.write(doc + '\n')
00291         else:
00292             self.file.write('<p>A problem occurred in a Python script.\n')
00293 
00294         if self.logdir is not None:
00295             suffix = ['.txt', '.html'][self.format=="html"]
00296             (fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir)
00297             try:
00298                 file = os.fdopen(fd, 'w')
00299                 file.write(doc)
00300                 file.close()
00301                 msg = '<p> %s contains the description of this error.' % path
00302             except:
00303                 msg = '<p> Tried to save traceback to %s, but failed.' % path
00304             self.file.write(msg + '\n')
00305         try:
00306             self.file.flush()
00307         except: pass

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 264 of file cgitb.py.

Definition at line 262 of file cgitb.py.

Definition at line 265 of file cgitb.py.

Definition at line 266 of file cgitb.py.

Definition at line 263 of file cgitb.py.


The documentation for this class was generated from the following file: