[Checkins] SVN: zope.location/trunk/ Split RootPhysicallyLocatable back from LocationPhysicallyLocatable. The IRoot object is not guaranteed to always provide ILocation.
Dan Korostelev
nadako at gmail.com
Mon Feb 2 19:19:20 EST 2009
Log message for revision 96009:
Split RootPhysicallyLocatable back from LocationPhysicallyLocatable. The IRoot object is not guaranteed to always provide ILocation.
Changed:
U zope.location/trunk/CHANGES.txt
U zope.location/trunk/src/zope/location/configure.zcml
U zope.location/trunk/src/zope/location/traversing.py
-=-
Modified: zope.location/trunk/CHANGES.txt
===================================================================
--- zope.location/trunk/CHANGES.txt 2009-02-02 23:55:16 UTC (rev 96008)
+++ zope.location/trunk/CHANGES.txt 2009-02-03 00:19:19 UTC (rev 96009)
@@ -5,7 +5,11 @@
3.5.2 (unreleased)
------------------
-- ...
+- Split RootPhysicallyLocatable adapter back from LocationPhysicallyLocatable,
+ because the IRoot object may not always provide ILocation and the code
+ for the root object is also simplier. It's basically a copy of the
+ RootPhysicallyLocatable adapter from zope.traversing version 3.5.0 and
+ below with ``getParents`` method added (returns an empty list).
3.5.1 (2009-02-02)
------------------
Modified: zope.location/trunk/src/zope/location/configure.zcml
===================================================================
--- zope.location/trunk/src/zope/location/configure.zcml 2009-02-02 23:55:16 UTC (rev 96008)
+++ zope.location/trunk/src/zope/location/configure.zcml 2009-02-03 00:19:19 UTC (rev 96009)
@@ -1,6 +1,7 @@
<configure xmlns="http://namespaces.zope.org/zope">
<adapter factory=".traversing.LocationPhysicallyLocatable" />
+ <adapter factory=".traversing.RootPhysicallyLocatable" />
<adapter factory=".location.LocationProxy" />
</configure>
Modified: zope.location/trunk/src/zope/location/traversing.py
===================================================================
--- zope.location/trunk/src/zope/location/traversing.py 2009-02-02 23:55:16 UTC (rev 96008)
+++ zope.location/trunk/src/zope/location/traversing.py 2009-02-03 00:19:19 UTC (rev 96009)
@@ -170,9 +170,6 @@
>>> root = Location()
>>> zope.interface.directlyProvides(root, IRoot)
- >>> LocationPhysicallyLocatable(root).getParents()
- []
-
>>> o1 = Location()
>>> o2 = Location()
>>> o1.__parent__ = root
@@ -192,9 +189,6 @@
"""
# XXX Merge this implementation with getPath. This was refactored
# from zope.traversing.
- if IRoot.providedBy(self.context):
- return []
-
parents = []
w = self.context
while 1:
@@ -216,15 +210,7 @@
>>> o1 = Location(); o1.__name__ = u'o1'
>>> LocationPhysicallyLocatable(o1).getName()
u'o1'
-
- >>> root = Location()
- >>> zope.interface.directlyProvides(root, IRoot)
- >>> LocationPhysicallyLocatable(root).getName()
- u''
-
"""
- if IRoot.providedBy(self.context):
- return u''
return self.context.__name__
def getNearestSite(self):
@@ -261,3 +247,86 @@
if ISite.providedBy(parent):
return parent
return self.getRoot()
+
+class RootPhysicallyLocatable(object):
+ """Provide location information for the root object
+
+ >>> from zope.interface.verify import verifyObject
+ >>> info = RootPhysicallyLocatable(None)
+ >>> verifyObject(ILocationInfo, info)
+ True
+
+ This adapter is very simple, because there's no places to search
+ for parents and nearest sites, so we are only working with context
+ object, knowing that its the root object already.
+
+ """
+
+ zope.component.adapts(IRoot)
+ zope.interface.implements(ILocationInfo)
+
+ def __init__(self, context):
+ self.context = context
+
+ def getRoot(self):
+ """See ILocationInfo
+
+ No need to search for root when our context is already root :)
+
+ >>> o1 = object()
+ >>> RootPhysicallyLocatable(o1).getRoot() is o1
+ True
+
+ """
+ return self.context
+
+ def getPath(self):
+ """See ILocationInfo
+
+ Root object is at the top of the tree, so always return ``/``.
+
+ >>> o1 = object()
+ >>> RootPhysicallyLocatable(o1).getPath()
+ u'/'
+
+ """
+ return u'/'
+
+ def getName(self):
+ """See ILocationInfo
+
+ Always return empty unicode string for the root object
+
+ >>> o1 = object()
+ >>> RootPhysicallyLocatable(o1).getName()
+ u''
+
+ """
+ return u''
+
+ def getParents(self):
+ """See ILocationInfo
+
+ There's no parents for the root object, return empty list.
+
+ >>> o1 = object()
+ >>> RootPhysicallyLocatable(o1).getParents()
+ []
+
+ """
+ return []
+
+ def getNearestSite(self):
+ """See ILocationInfo
+
+ Return object itself as the nearest site, because there's no
+ other place to look for. It's also usual that the root is the
+ site as well.
+
+
+ >>> o1 = object()
+ >>> RootPhysicallyLocatable(o1).getNearestSite() is o1
+ True
+
+ """
+ return self.context
More information about the Checkins
mailing list