[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/traversing/ Added backward compatibility for traveral components that raise NotFoundError

Jim Fulton jim at zope.com
Wed Oct 27 15:43:14 EDT 2004


Log message for revision 28268:
  Added backward compatibility for traveral components that raise NotFoundError
  
  rather than the newer TraversalError.
  

Changed:
  U   Zope3/trunk/src/zope/app/traversing/adapters.py
  U   Zope3/trunk/src/zope/app/traversing/api.py
  U   Zope3/trunk/src/zope/app/traversing/namespace.py

-=-
Modified: Zope3/trunk/src/zope/app/traversing/adapters.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/adapters.py	2004-10-27 17:05:26 UTC (rev 28267)
+++ Zope3/trunk/src/zope/app/traversing/adapters.py	2004-10-27 19:43:14 UTC (rev 28268)
@@ -28,6 +28,10 @@
 from zope.app.traversing.namespace import UnexpectedParameters
 from zope.app.traversing.namespace import nsParse
 
+# BBB Backward Compatibility (Can go away in 3.3)
+from zope.exceptions import NotFoundError
+import warnings
+
 _marker = object()  # opaque marker that doesn't get security proxied
 
 class DefaultTraversable(object):
@@ -173,5 +177,18 @@
             return default
         else:
             raise
+    except NotFoundError, v: # BBB Backward Compatibility
+        warnings.warn(
+            "A %s instance raised a NotFoundError in "
+            "traverse.  Raising NotFoundError in this "
+            "method is deprecated and will no-longer be supported "
+            "staring in ZopeX3 3.3.  TraversalError should "
+            "be raised instead."
+            % traversable.__class__.__name__,
+            DeprecationWarning)
+        if default != _marker:
+            return default
+        else:
+            raise
 
     return obj

Modified: Zope3/trunk/src/zope/app/traversing/api.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/api.py	2004-10-27 17:05:26 UTC (rev 28267)
+++ Zope3/trunk/src/zope/app/traversing/api.py	2004-10-27 19:43:14 UTC (rev 28268)
@@ -18,8 +18,12 @@
 
 from zope.interface import moduleProvides
 from interfaces import IContainmentRoot, ITraversalAPI
-from interfaces import ITraverser, IPhysicallyLocatable
+from interfaces import ITraverser, IPhysicallyLocatable, TraversalError
 
+# BBB Backward Compatibility (Can go away in 3.3)
+from zope.exceptions import NotFoundError
+import warnings
+
 moduleProvides(ITraversalAPI)
 __all__ = tuple(ITraversalAPI)
 
@@ -83,11 +87,30 @@
           Consider using traverseName instead.
     """
     traverser = ITraverser(object)
-    if default is _marker:
-        return traverser.traverse(path, request=request)
-    else:
-        return traverser.traverse(path, default=default, request=request)
+    try:
+        if default is _marker:
+            return traverser.traverse(path, request=request)
+        else:
+            return traverser.traverse(path, default=default, request=request)
 
+    # BBB Backward Compatibility, can go away in 3.3
+    #
+    except TraversalError:
+        raise
+    except NotFoundError, v: 
+        import pdb; pdb.set_trace()
+        warnings.warn(
+            "A %s instance raised a NotFoundError in "
+            "traverse.  Raising NotFoundError in this "
+            "method is deprecated and will no-longer be supported "
+            "staring in ZopeX3 3.3.  TraversalError should "
+            "be raised instead."
+            % traverser.__class__.__name__,
+            DeprecationWarning)
+        raise TraversalError(*tuple(v))
+    #
+    ###############################################################
+
 def traverseName(obj, name, default=_marker, traversable=None, request=None):
     """Traverse a single step 'name' relative to the given object.
 

Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py	2004-10-27 17:05:26 UTC (rev 28267)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py	2004-10-27 19:43:14 UTC (rev 28268)
@@ -28,6 +28,10 @@
 from zope.app.publisher.browser import applySkin
 from zope.app.traversing.interfaces import ITraversable, IPathAdapter
 
+# BBB Backward Compatibility
+from zope.exceptions import NotFoundError
+import warnings
+
 class UnexpectedParameters(TraversalError):
     "Unexpected namespace parameters were provided."
 
@@ -254,6 +258,16 @@
                         continue
                 except TraversalError:
                     pass
+
+                except NotFoundError, v: # BBB Backward Compatibility
+                    warnings.warn(
+                        "A %s instance raised a NotFoundError in "
+                        "traverse.  Raising NotFoundError in this "
+                        "method is deprecated and will no-longer be supported "
+                        "staring in ZopeX3 3.3.  TraversalError should "
+                        "be raised instead."
+                        % traversable.__class__.__name__,
+                        DeprecationWarning)
                 else:
                     return next
 



More information about the Zope3-Checkins mailing list