[Zope-CVS] CVS: Products/ErrorReporter - ExceptionFormatter.py:1.4
Shane Hathaway
shane@cvs.zope.org
Fri, 8 Mar 2002 12:34:53 -0500
Update of /cvs-repository/Products/ErrorReporter
In directory cvs.zope.org:/tmp/cvs-serv22143
Modified Files:
ExceptionFormatter.py
Log Message:
- Show the context of a script or template if it's applied to anything other
than its container.
- Use the __revision__ global, if available, instead of __version__.
=== Products/ErrorReporter/ExceptionFormatter.py 1.3 => 1.4 ===
return path, url
+ def getAppliedPaths(self, mo):
+ """Returns the path and URL of the object the method is applied to.
+
+ This only returns something if the object is being applied to
+ something other than its container."""
+ try:
+ from Acquisition import aq_base, aq_inner, aq_parent
+ except ImportError:
+ return None, None
+ context = aq_parent(mo)
+ if aq_base(context) is not aq_base(aq_parent(aq_inner(mo))):
+ return self.getObjectPaths(context)
+
def formatSupplement(self, supplement, tb):
result = []
mo = getattr(supplement, 'manageable_object', None)
if mo is not None:
+ class_ = getattr(mo, '__class__', None)
+ ob_type = getattr(class_, '__name__', 'Object')
path, url = self.getObjectPaths(mo)
if path is not None:
- result.append(' - Object: %s (%s)' % (
- self.escape(path), self.escape(url)))
+ result.append(' - %s: %s (%s)' % (
+ ob_type, self.escape(path), self.escape(url)))
+ path, url = self.getAppliedPaths(mo)
+ if path is not None:
+ result.append(' - Applied to: %s (%s)' % (
+ self.escape(path), self.escape(url)))
line = getattr(supplement, 'line', 0)
if line == -1:
@@ -94,7 +113,13 @@
locals = f.f_locals
globals = f.f_globals
modname = globals.get('__name__', filename)
- revision = globals.get('__version__', None)
+
+ # Correct spelling
+ revision = globals.get('__revision__', None)
+ if revision is None:
+ # Incorrect but commonly used spelling
+ revision = globals.get('__version__', None)
+
if revision is not None:
try:
revision = str(revision).strip()[:10]
@@ -155,9 +180,10 @@
limit = self.getLimit()
n = 0
while tb is not None and (limit is None or n < limit):
- result.append(self.formatLine(tb))
+ line = self.formatLine(tb)
+ result.append(line)
tb = tb.tb_next
- n = n+1
+ n = n + 1
exc_line = self.formatExceptionOnly(etype, value)
result.append(self.formatLastLine(exc_line))
return '\n'.join(result)
@@ -178,10 +204,16 @@
result = []
mo = getattr(supplement, 'manageable_object', None)
if mo is not None:
+ class_ = getattr(mo, '__class__', None)
+ ob_type = getattr(class_, '__name__', 'Object')
path, url = self.getObjectPaths(mo)
if path is not None:
- result.append('<b>Object: <a href="%s">%s</a></b>' % (
- url, path))
+ result.append('<b>%s: <a href="%s">%s</a></b>' % (
+ ob_type, url, path))
+ path, url = self.getAppliedPaths(mo)
+ if path is not None:
+ result.append('<b>Applied to: <a href="%s">%s</a></b>' % (
+ url, path))
line = getattr(supplement, 'line', 0)
if line == -1: