[Checkins] SVN: zope.location/trunk/ Added getParent() to ILocationInfo and moved the actual implementation here
Thomas Lotze
tl at gocept.com
Tue Sep 15 08:55:51 EDT 2009
Log message for revision 104058:
Added getParent() to ILocationInfo and moved the actual implementation here
from zope.traversal.api, analogous to getParents().
Changed:
U zope.location/trunk/CHANGES.txt
U zope.location/trunk/src/zope/location/interfaces.py
U zope.location/trunk/src/zope/location/traversing.py
-=-
Modified: zope.location/trunk/CHANGES.txt
===================================================================
--- zope.location/trunk/CHANGES.txt 2009-09-15 12:54:29 UTC (rev 104057)
+++ zope.location/trunk/CHANGES.txt 2009-09-15 12:55:51 UTC (rev 104058)
@@ -2,10 +2,11 @@
CHANGES
=======
-3.6.1 (unreleased)
+3.7.0 (unreleased)
------------------
-- ...
+- Added getParent() to ILocationInfo and moved the actual implementation here
+ from zope.traversal.api, analogous to getParents().
3.6.0 (2009-08-27)
------------------
Modified: zope.location/trunk/src/zope/location/interfaces.py
===================================================================
--- zope.location/trunk/src/zope/location/interfaces.py 2009-09-15 12:54:29 UTC (rev 104057)
+++ zope.location/trunk/src/zope/location/interfaces.py 2009-09-15 12:55:51 UTC (rev 104058)
@@ -75,6 +75,15 @@
"""
+ def getParent():
+ """Returns the container the object was traversed via.
+
+ Returns None if the object is a containment root.
+ Raises TypeError if the object doesn't have enough context to get the
+ parent.
+
+ """
+
def getParents():
"""Returns a list starting with the object's parent followed by
each of its parents.
Modified: zope.location/trunk/src/zope/location/traversing.py
===================================================================
--- zope.location/trunk/src/zope/location/traversing.py 2009-09-15 12:54:29 UTC (rev 104057)
+++ zope.location/trunk/src/zope/location/traversing.py 2009-09-15 12:55:51 UTC (rev 104058)
@@ -160,6 +160,38 @@
raise TypeError("Not enough context to determine location root")
+ def getParent(self):
+ """Returns the container the object was traversed via.
+
+ Returns None if the object is a containment root.
+ Raises TypeError if the object doesn't have enough context to get the
+ parent.
+
+ >>> root = Location()
+ >>> zope.interface.directlyProvides(root, IRoot)
+ >>> o1 = Location()
+ >>> o2 = Location()
+
+ >>> LocationPhysicallyLocatable(o2).getParent() # doctest: +ELLIPSIS
+ Traceback (most recent call last):
+ TypeError: ('Not enough context information to get parent', <zope.location.location.Location object at 0x...>)
+
+ >>> o1.__parent__ = root
+ >>> LocationPhysicallyLocatable(o1).getParent() == root
+ True
+
+ >>> o2.__parent__ = o1
+ >>> LocationPhysicallyLocatable(o2).getParent() == o1
+ True
+
+ """
+ parent = getattr(self.context, '__parent__', None)
+ if parent is not None:
+ return parent
+
+ raise TypeError('Not enough context information to get parent',
+ self.context)
+
def getParents(self):
"""Returns a list starting with the object's parent followed by
each of its parents.
@@ -303,6 +335,19 @@
"""
return u''
+ def getParent(self):
+ """Returns the container the object was traversed via.
+
+ Returns None if the object is a containment root.
+ Raises TypeError if the object doesn't have enough context to get the
+ parent.
+
+ >>> o1 = object()
+ >>> RootPhysicallyLocatable(o1).getParent()
+
+ """
+ return None
+
def getParents(self):
"""See ILocationInfo
More information about the checkins
mailing list