[Python-checkins] CVS: python/dist/src/Lib cgitb.py,1.2,1.3

Ka-Ping Yee ping@users.sourceforge.net
2001年12月04日 10:45:19 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv25525
Modified Files:
	cgitb.py 
Log Message:
Add "file" argument to Hook constructor.
By default, save sys.stdout in self.file when a Hook instance is created
 (e.g. when cgitb.enable() is called).
Index: cgitb.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cgitb.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** cgitb.py	2001年08月21日 06:53:01	1.2
--- cgitb.py	2001年12月04日 18:45:17	1.3
***************
*** 20,23 ****
--- 20,25 ----
 __version__ = '$Revision$'
 
+ import sys
+ 
 def reset():
 """Return a string that resets the CGI and browser to a known state."""
***************
*** 67,71 ****
 def html((etype, evalue, etb), context=5):
 """Return a nice HTML document describing a given traceback."""
! import sys, os, types, time, traceback, linecache, inspect, pydoc
 
 if type(etype) is types.ClassType:
--- 69,73 ----
 def html((etype, evalue, etb), context=5):
 """Return a nice HTML document describing a given traceback."""
! import os, types, time, traceback, linecache, inspect, pydoc
 
 if type(etype) is types.ClassType:
***************
*** 150,157 ****
 """A hook to replace sys.excepthook that shows tracebacks in HTML."""
 
! def __init__(self, display=1, logdir=None, context=5):
 self.display = display # send tracebacks to browser if true
 self.logdir = logdir # log tracebacks to files if not None
 self.context = context # number of source code lines per frame
 
 def __call__(self, etype, evalue, etb):
--- 152,160 ----
 """A hook to replace sys.excepthook that shows tracebacks in HTML."""
 
! def __init__(self, display=1, logdir=None, context=5, file=None):
 self.display = display # send tracebacks to browser if true
 self.logdir = logdir # log tracebacks to files if not None
 self.context = context # number of source code lines per frame
+ self.file = file or sys.stdout # place to send the output
 
 def __call__(self, etype, evalue, etb):
***************
*** 159,165 ****
 
 def handle(self, info=None):
- import sys
 info = info or sys.exc_info()
! print reset()
 
 try:
--- 162,167 ----
 
 def handle(self, info=None):
 info = info or sys.exc_info()
! self.file.write(reset())
 
 try:
***************
*** 172,180 ****
 if text:
 doc = doc.replace('&', '&amp;').replace('<', '&lt;')
! print '<pre>' + doc + '</pre>'
 else:
! print doc
 else:
! print '<p>A problem occurred in a Python script.'
 
 if self.logdir is not None:
--- 174,182 ----
 if text:
 doc = doc.replace('&', '&amp;').replace('<', '&lt;')
! self.file.write('<pre>' + doc + '</pre>\n')
 else:
! self.file.write(doc + '\n')
 else:
! self.file.write('<p>A problem occurred in a Python script.\n')
 
 if self.logdir is not None:
***************
*** 186,192 ****
 file.write(doc)
 file.close()
! print '<p> %s contains the description of this error.' % path
 except:
! print '<p> Tried to save traceback to %s, but failed.' % path
 
 handler = Hook().handle
--- 188,198 ----
 file.write(doc)
 file.close()
! msg = '<p> %s contains the description of this error.' % path
 except:
! msg = '<p> Tried to save traceback to %s, but failed.' % path
! self.file.write(msg + '\n')
! try:
! self.file.flush()
! except: pass
 
 handler = Hook().handle
***************
*** 197,200 ****
 traceback to the browser, and 'logdir' can be set to a directory to cause
 tracebacks to be written to files there."""
- import sys
 sys.excepthook = Hook(display, logdir, context)
--- 203,205 ----

AltStyle によって変換されたページ (->オリジナル) /