[Checkins] SVN: zope.traversing/trunk/ In zope.traversing.api.getParent(), try to delegate to

Thomas Lotze tl at gocept.com
Tue Sep 29 10:36:16 EDT 2009


Log message for revision 104608:
  In zope.traversing.api.getParent(), try to delegate to
  zope.location.interfaces.ILocationInfo.getParent(), analogous to
  getParents(). Keep returning the traversal parent as a fallback.
  

Changed:
  U   zope.traversing/trunk/CHANGES.txt
  U   zope.traversing/trunk/src/zope/traversing/api.py

-=-
Modified: zope.traversing/trunk/CHANGES.txt
===================================================================
--- zope.traversing/trunk/CHANGES.txt	2009-09-29 14:35:28 UTC (rev 104607)
+++ zope.traversing/trunk/CHANGES.txt	2009-09-29 14:36:16 UTC (rev 104608)
@@ -5,6 +5,9 @@
 3.8.0 (unreleased)
 ------------------
 
+- In zope.traversing.api.getParent(), try to delegate to
+  zope.location.interfaces.ILocationInfo.getParent(), analogous to
+  getParents(). Keep returning the traversal parent as a fallback.
 
 - Brought ITraverser back from zope.location where it had been moved to invert
   the package interdependency, but is no longer used now.

Modified: zope.traversing/trunk/src/zope/traversing/api.py
===================================================================
--- zope.traversing/trunk/src/zope/traversing/api.py	2009-09-29 14:35:28 UTC (rev 104607)
+++ zope.traversing/trunk/src/zope/traversing/api.py	2009-09-29 14:36:16 UTC (rev 104608)
@@ -19,6 +19,7 @@
 from zope.location.interfaces import ILocationInfo, IRoot, LocationError
 from zope.traversing.interfaces import ITraversalAPI, ITraverser
 
+
 moduleProvides(ITraversalAPI)
 __all__ = tuple(ITraversalAPI)
 
@@ -128,10 +129,21 @@
     Raises TypeError if the object doesn't have enough context to get the
     parent.
     """
-    
+    try:
+        location_info = ILocationInfo(obj)
+    except TypeError:
+        pass
+    else:
+        return location_info.getParent()
+
+    # XXX Keep the old implementation as the fallback behaviour in the case
+    # that obj doesn't have a location parent. This seems advisable as the
+    # 'parent' is sometimes taken to mean the traversal parent, and the
+    # __parent__ attribute is used for both.
+
     if IRoot.providedBy(obj):
         return None
-    
+
     parent = getattr(obj, '__parent__', None)
     if parent is not None:
         return parent
@@ -139,7 +151,6 @@
     raise TypeError("Not enough context information to get parent", obj)
 
 
-
 def getParents(obj):
     """Returns a list starting with the given object's parent followed by
     each of its parents.



More information about the checkins mailing list