[Checkins] SVN: five.localsitemanager/trunk/ Simplified some code, aq_parent now respects __parent__ pointers.
Hanno Schlichting
hannosch at hannosch.eu
Sun Sep 27 06:30:27 EDT 2009
Log message for revision 104571:
Simplified some code, aq_parent now respects __parent__ pointers.
Changed:
U five.localsitemanager/trunk/CHANGES.txt
U five.localsitemanager/trunk/src/five/localsitemanager/__init__.py
U five.localsitemanager/trunk/src/five/localsitemanager/registry.py
U five.localsitemanager/trunk/src/five/localsitemanager/utils.py
-=-
Modified: five.localsitemanager/trunk/CHANGES.txt
===================================================================
--- five.localsitemanager/trunk/CHANGES.txt 2009-09-27 10:10:19 UTC (rev 104570)
+++ five.localsitemanager/trunk/CHANGES.txt 2009-09-27 10:30:27 UTC (rev 104571)
@@ -4,6 +4,8 @@
2.0dev - unreleased
-------------------
+* Simplified some code, aq_parent now respects __parent__ pointers.
+ [hannosch]
2.0a1 - 2009-05-27
------------------
Modified: five.localsitemanager/trunk/src/five/localsitemanager/__init__.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/__init__.py 2009-09-27 10:10:19 UTC (rev 104570)
+++ five.localsitemanager/trunk/src/five/localsitemanager/__init__.py 2009-09-27 10:30:27 UTC (rev 104571)
@@ -17,7 +17,6 @@
from Acquisition import aq_base
from zope.component.globalregistry import base
-from zope.traversing.interfaces import IContainmentRoot
from zope.location.interfaces import ISite
from five.localsitemanager.registry import PersistentComponents
from five.localsitemanager.utils import get_parent
@@ -54,16 +53,10 @@
sitemanager.
"""
while True:
- if IContainmentRoot.providedBy(site):
- # we're the root site, return None
+ site = get_parent(site, default=None)
+ if site is None:
return None
- try:
- site = get_parent(site)
- except TypeError:
- # there was not enough context; probably run from a test
- return None
-
if ISite.providedBy(site):
return site.getSiteManager()
Modified: five.localsitemanager/trunk/src/five/localsitemanager/registry.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2009-09-27 10:10:19 UTC (rev 104570)
+++ five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2009-09-27 10:30:27 UTC (rev 104571)
@@ -17,10 +17,9 @@
import Acquisition
import persistent
-import OFS.ObjectManager
from Acquisition.interfaces import IAcquirer
+from OFS.ObjectManager import ObjectManager
from zope.location.interfaces import ISite
-from zope.component.persistentregistry import PersistentAdapterRegistry
from zope.component.persistentregistry import PersistentComponents
from zope.component.registry import UtilityRegistration, _getUtilityProvided
from zope.interface.adapter import VerifyingAdapterLookup
@@ -114,6 +113,7 @@
current = _recurse_to_site(get_parent(current), wanted)
return current
+
def _wrap(comp, registry):
"""Return an aq wrapped component with the site as the parent but
only if the comp has an aq wrapper to begin with.
@@ -182,18 +182,16 @@
class ComponentPathWrapper(persistent.Persistent):
-
+
def __init__(self, component, path):
self.component = component
self.path = path
def __eq__(self, other):
return self.component == other
-
-class PersistentComponents \
- (PersistentComponents,
- OFS.ObjectManager.ObjectManager):
+
+class PersistentComponents(PersistentComponents, ObjectManager):
"""An implementation of a component registry that can be persisted
and looks like a standard ObjectManager. It also ensures that all
utilities have the the parent of this site manager (which should be
Modified: five.localsitemanager/trunk/src/five/localsitemanager/utils.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/utils.py 2009-09-27 10:10:19 UTC (rev 104570)
+++ five.localsitemanager/trunk/src/five/localsitemanager/utils.py 2009-09-27 10:30:27 UTC (rev 104571)
@@ -2,26 +2,23 @@
from Acquisition import aq_parent, aq_inner
+_marker = object()
-def get_parent(obj):
- """Returns the container the object was traversed via. This
- is a version of zope.traversing.api.getParent that is designed to
- handle acquisition as well.
+def get_parent(obj, default=_marker):
+ """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.
"""
-
if IContainmentRoot.providedBy(obj):
return None
-
- parent = getattr(obj, '__parent__', None)
- if parent is not None:
- return parent
parent = aq_parent(aq_inner(obj))
if parent is not None:
return parent
+ if default != _marker:
+ return default
+
raise TypeError("Not enough context information to get parent", obj)
More information about the checkins
mailing list