[Zope-Checkins] CVS: Zope3/lib/python/Zope/Exceptions - _duplicate.py:1.2 _forbidden.py:1.2 _notfounderror.py:1.2 _zope_error.py:1.2 ExceptionFormatter.py:1.4 ITracebackSupplement.py:1.3 __init__.py:1.4 unauthorized.py:1.5

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:29:57 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Exceptions
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Exceptions

Modified Files:
	ExceptionFormatter.py ITracebackSupplement.py __init__.py 
	unauthorized.py 
Added Files:
	_duplicate.py _forbidden.py _notfounderror.py _zope_error.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.

=== Zope3/lib/python/Zope/Exceptions/_duplicate.py 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.
+# 
+##############################################################################
+"""
+$Id$
+"""
+from Zope.Exceptions import ZopeError
+
+class DuplicationError(ZopeError):
+    """A duplicate registration was attempted"""


=== Zope3/lib/python/Zope/Exceptions/_forbidden.py 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.
+# 
+##############################################################################
+"""
+$Id$
+"""
+from Zope.Exceptions import ZopeError
+
+class Forbidden(ZopeError):
+    """A resource cannot be accessed under any circumstances
+    """
+
+class ForbiddenAttribute(Forbidden, AttributeError):
+    """An attribute is unavailable because it is forbidden (private)
+    """
+
+    


=== Zope3/lib/python/Zope/Exceptions/_notfounderror.py 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.
+# 
+##############################################################################
+"""
+$Id$
+"""
+from Zope.Exceptions import ZopeError
+
+class NotFoundError(ZopeError, KeyError):
+    """A resource could not be found.
+    """


=== Zope3/lib/python/Zope/Exceptions/_zope_error.py 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.
+# 
+##############################################################################
+"""Base class for Zope application errors.
+
+$Id$
+"""
+
+class ZopeError( Exception ):
+    """ Generic base class for Zope errors."""


=== Zope3/lib/python/Zope/Exceptions/ExceptionFormatter.py 1.3 => 1.4 ===
         return revision
 
+    def getObjectPath(self, o):
+        """Returns an informal path to an object.
+        """
+        try:
+            from Zope.ContextWrapper import wrapper
+        except ImportError:
+            # Not available.
+            return None
+
+        res = []
+        while o is not None:
+            d = wrapper.getdict(o)
+            if d:
+                name = d.get('name', None)
+                if name:
+                    res.append(name)
+            o = wrapper.getcontext(o)
+
+        res.reverse()
+        return res
+
     def formatSupplementLine(self, line):
         return '   - %s' % line
 
-    def formatObject(self, object):
-        return [self.formatSupplementLine(repr(object))]
-
     def formatSourceURL(self, url):
-        return [self.formatSupplementLine('URL: %s' % url)]
+        return [self.formatSupplementLine(url)]
 
     def formatSupplement(self, supplement, tb):
         result = []
         fmtLine = self.formatSupplementLine
 
-        object = getattr(supplement, 'object', None)
-        if object is not None:
-            result.extend(self.formatObject(object))
-
         url = getattr(supplement, 'source_url', None)
         if url is not None:
             result.extend(self.formatSourceURL(url))
@@ -102,21 +116,21 @@
             for warning in warnings:
                 result.append(fmtLine('Warning: %s' % warning))
 
-        extra = self.formatExtraInfo(supplement)
-        if extra:
-            result.append(extra)
-        return result
-
-    def formatExtraInfo(self, supplement):
         getInfo = getattr(supplement, 'getInfo', None)
         if getInfo is not None:
-            extra = getInfo()
-            if extra:
-                return extra
-        return None        
+            try:
+                extra = getInfo()
+                if extra:
+                    result.append(extra)
+            except:
+                if DEBUG_EXCEPTION_FORMATTER:
+                    import traceback
+                    traceback.print_exc()
+                # else just swallow the exception.
+        return result
 
     def formatTracebackInfo(self, tbi):
-        return self.formatSupplementLine('__traceback_info__: %s' % (tbi,))
+        return self.formatSupplementLine('__traceback_info__: %s' % tbi)
 
     def formatLine(self, tb):
         f = tb.tb_frame
@@ -140,10 +154,10 @@
         result.append(self.escape(s))
 
         # Output a traceback supplement, if any.
-        if locals.has_key('__traceback_supplement__'):
+        if '__traceback_supplement__' in locals:
             # Use the supplement defined in the function.
             tbs = locals['__traceback_supplement__']
-        elif globals.has_key('__traceback_supplement__'):
+        elif '__traceback_supplement__' in globals:
             # Use the supplement defined in the module.
             # This is used by Scripts (Python).
             tbs = globals['__traceback_supplement__']
@@ -166,7 +180,10 @@
             if tbi is not None:
                 result.append(self.formatTracebackInfo(tbi))
         except:
-            pass
+            if DEBUG_EXCEPTION_FORMATTER:
+                import traceback
+                traceback.print_exc()
+            # else just swallow the exception.
 
         return self.line_sep.join(result)
 
@@ -178,12 +195,11 @@
     def formatLastLine(self, exc_line):
         return self.escape(exc_line)
 
-    def formatException(self, etype, value, tb, limit=None):
+    def formatException(self, etype, value, tb):
         # The next line provides a way to detect recursion.
         __exception_formatter__ = 1
         result = [self.getPrefix() + '\n']
-        if limit is None:
-            limit = self.getLimit()
+        limit = self.getLimit()
         n = 0
         while tb is not None and (limit is None or n < limit):
             if tb.tb_frame.f_locals.get('__exception_formatter__'):
@@ -225,14 +241,6 @@
     def formatLastLine(self, exc_line):
         return '</ul>%s</p>' % self.escape(exc_line)
 
-    def formatExtraInfo(self, supplement):
-        getInfo = getattr(supplement, 'getInfo', None)
-        if getInfo is not None:
-            extra = getInfo(1)
-            if extra:
-                return extra
-        return None        
-
 
 
 limit = 200
@@ -249,5 +257,5 @@
         fmt = html_formatter
     else:
         fmt = text_formatter
-    return fmt.formatException(t, v, tb, limit=limit)
+    return fmt.formatException(t, v, tb)
 


=== Zope3/lib/python/Zope/Exceptions/ITracebackSupplement.py 1.2 => 1.3 ===
         )
 
-    object = Attribute(
-        'object',
-        """Optional.  Set to the script or template where the exception
-        occurred.
-
-        Set to None if unknown or not available.
-        """
-        )
-
     line = Attribute(
         'line',
         """Optional.  Set to the line number (>=1) where the exception


=== Zope3/lib/python/Zope/Exceptions/__init__.py 1.3 => 1.4 ===
 #
-# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# 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
+# FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
 """General exceptions that wish they were standard exceptions
@@ -18,4 +19,9 @@
 $Id$
 """
 
+from _zope_error import ZopeError
 from unauthorized import Unauthorized
+from _notfounderror import NotFoundError
+from _forbidden import Forbidden, ForbiddenAttribute
+from _duplicate import DuplicationError
+


=== Zope3/lib/python/Zope/Exceptions/unauthorized.py 1.4 => 1.5 ===
 #
-# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# 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
+# FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
 """
@@ -15,8 +16,9 @@
 """
 
 from types import StringType
+from Zope.Exceptions import ZopeError
 
-class Unauthorized(Exception):
+class Unauthorized(ZopeError):
     """Some user wasn't allowed to access a resource"""
 
     def __init__(self, message=None, value=None, needed=None, name=None, **kw):