[Zope-CVS] CVS: Products/ErrorReporter - ExceptionFormatter.py:1.2
Shane Hathaway
shane@cvs.zope.org
Mon, 4 Mar 2002 18:25:52 -0500
Update of /cvs-repository/Products/ErrorReporter
In directory cvs.zope.org:/tmp/cvs-serv23545
Modified Files:
ExceptionFormatter.py
Log Message:
- License
- Better formatting of line / column
- Look for __traceback_supplement__ in globals if not found in locals,
that way compiled Python scripts can use the machinery relatively
easily.
=== Products/ErrorReporter/ExceptionFormatter.py 1.1.1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
import sys
import cgi
@@ -35,7 +48,7 @@
else:
return path, url
- def formatSupplement(self, supplement):
+ def formatSupplement(self, supplement, tb):
result = []
mo = supplement.getManageableObject()
if mo is not None:
@@ -43,12 +56,20 @@
if path is not None:
result.append(' - Object: %s (%s)' % (
self.escape(path), self.escape(url)))
+
line = supplement.getLine()
- if line:
- result.append(' - Line: %s' % self.escape(str(line)))
+ if line == -1:
+ line = tb.tb_lineno
col = supplement.getColumn()
- if col:
- result.append(' - Column: %s' % self.escape(str(col)))
+ if line:
+ if col:
+ result.append(' - Line %s, Column %s' % (
+ self.escape(str(line)), self.escape(str(col))))
+ else:
+ result.append(' - Line %s' % self.escape(str(line)))
+ elif col:
+ result.append(' - Column %s' % self.escape(str(col)))
+
expr = supplement.getExpression()
if expr:
result.append(' - Expression: %s' % self.escape(str(expr)))
@@ -84,12 +105,20 @@
' Module %s, line %d, in %s' % (modname,lineno,name)))
try:
- tbs = locals.get('__traceback_supplement__', None)
+ if locals.has_key('__traceback_supplement__'):
+ # Use the supplement defined in the function.
+ tbs = locals['__traceback_supplement__']
+ elif globals.has_key('__traceback_supplement__'):
+ # Use the supplement defined in the module.
+ # This is used by Scripts (Python).
+ tbs = globals['__traceback_supplement__']
+ else:
+ tbs = None
if tbs is not None:
factory = tbs[0]
args = tbs[1:]
supp = factory(*args)
- result.append(self.formatSupplement(supp))
+ result.append(self.formatSupplement(supp, tb))
except:
# XXX temporary.
import traceback
@@ -142,7 +171,7 @@
def getPrefix(self):
return '<p>Traceback (innermost last):\r\n<ul>'
- def formatSupplement(self, supplement):
+ def formatSupplement(self, supplement, tb):
result = []
mo = supplement.getManageableObject()
if mo is not None:
@@ -150,12 +179,20 @@
if path is not None:
result.append('<b>Object: <a href="%s">%s</a></b>' % (
url, path))
+
line = supplement.getLine()
- if line:
- result.append('<b>Line: %s</b>' % self.escape(str(line)))
+ if line == -1:
+ line = tb.tb_lineno
col = supplement.getColumn()
- if col:
- result.append('<b>Column: %s</b>' % self.escape(str(col)))
+ if line:
+ if col:
+ result.append('<b>Line %s, Column %s</b>' % (
+ self.escape(str(line)), self.escape(str(col))))
+ else:
+ result.append('<b>Line %s</b>' % self.escape(str(line)))
+ elif col:
+ result.append('<b>Column %s</b>' % self.escape(str(col)))
+
expr = supplement.getExpression()
if expr:
result.append('<b>Expression: %s</b>' % self.escape(str(expr)))