[Checkins] SVN: five.localsitemanager/trunk/ Updated forked registerUtility method to match the zope.component 3.7.1 code base. This fixes the two bugs with the implicit unregistration of utilities for existing interface / name pairs.
Hanno Schlichting
hannosch at hannosch.eu
Sun Sep 27 07:18:23 EDT 2009
Log message for revision 104572:
Updated forked registerUtility method to match the zope.component 3.7.1 code base. This fixes the two bugs with the implicit unregistration of utilities for existing interface / name pairs.
Changed:
U five.localsitemanager/trunk/CHANGES.txt
U five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
U five.localsitemanager/trunk/src/five/localsitemanager/registry.py
-=-
Modified: five.localsitemanager/trunk/CHANGES.txt
===================================================================
--- five.localsitemanager/trunk/CHANGES.txt 2009-09-27 10:30:27 UTC (rev 104571)
+++ five.localsitemanager/trunk/CHANGES.txt 2009-09-27 11:18:22 UTC (rev 104572)
@@ -4,6 +4,11 @@
2.0dev - unreleased
-------------------
+* Updated forked registerUtility method to match the zope.component 3.7.1
+ code base. This fixes the two bugs with the implicit unregistration of
+ utilities for existing interface / name pairs.
+ [hannosch]
+
* Simplified some code, aq_parent now respects __parent__ pointers.
[hannosch]
Modified: five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2009-09-27 10:30:27 UTC (rev 104571)
+++ five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2009-09-27 11:18:22 UTC (rev 104572)
@@ -263,7 +263,7 @@
When we query the utility, it is returned with its original context:
- >>> si_util = sitemanager_a.getUtility(ITestUtility, name='with_aq_chain')
+ >>> si_util = sitemanager_a.getUtility(ITestUtility, name=u'with_aq_chain')
>>> si_util
<SITestUtility at /a/b/si_util>
>>> si_util.getPhysicalPath()
@@ -273,7 +273,7 @@
>>> si_util.absolute_url()
'a/b/si_util'
- >>> zope.component.getUtility(ITestUtility, name='with_aq_chain')
+ >>> zope.component.getUtility(ITestUtility, name=u'with_aq_chain')
<SITestUtility at /a/b/si_util>
If we move a registered component (which has an absolute path) to new
@@ -289,15 +289,15 @@
... self.app.a.b.c.si_util_cped,
... name=u'with_aq_chain',
... provided=ITestUtility)
- >>> zope.component.getUtility(ITestUtility, name='with_aq_chain')
+ >>> zope.component.getUtility(ITestUtility, name=u'with_aq_chain')
<SITestUtility at /a/b/c/si_util_cped>
And just to mix things up a bit. Getting back multiple utilities
should allow us to test aq, non-aq based components and components
-having an absolute aqusition path.
+having an absolute Acquisition path.
First we have to register aq and non-aq based components in our
-registry (a component having an absolute aqusition path already exists):
+registry (a component having an absolute Acquisition path already exists):
>>> sitemanager_a.registerUtility(AQTestUtility('test'),
... name=u'aq_wrapped',
Modified: five.localsitemanager/trunk/src/five/localsitemanager/registry.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2009-09-27 10:30:27 UTC (rev 104571)
+++ five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2009-09-27 11:18:22 UTC (rev 104572)
@@ -233,14 +233,16 @@
provided = _getUtilityProvided(component)
reg = self._utility_registrations.get((provided, name))
- if reg is not None and reg[:2] == (component, info):
- # already registered
- if isinstance(reg[0], ComponentPathWrapper):
- self.utilities.unsubscribe((), provided, reg[0])
- # update path
- reg[0].path = component.getPhysicalPath()
- self.utilities.subscribe((), provided, reg[0])
- return
+ if reg is not None:
+ if reg[:2] == (component, info):
+ # already registered
+ if isinstance(reg[0], ComponentPathWrapper):
+ # update path
+ self.utilities.unsubscribe((), provided, reg[0])
+ reg[0].path = component.getPhysicalPath()
+ self.utilities.subscribe((), provided, reg[0])
+ return
+ self.unregisterUtility(reg[0], provided, name)
subscribed = False
for ((p, _), data) in self._utility_registrations.iteritems():
@@ -249,12 +251,12 @@
break
wrapped_component = component
- if hasattr(component, 'aq_parent'):
+ if getattr(component, 'aq_parent', None) is not None:
# component is acquisition wrapped, so try to store path
- if not hasattr(component, 'getPhysicalPath'):
+ if getattr(component, 'getPhysicalPath', None) is None:
raise AttributeError(
'Component %r does not implement getPhysicalPath, '
- 'so register it unwrapped or implement this method.' %
+ 'so register it unwrapped or implement this method.' %
component)
path = component.getPhysicalPath()
# If the path is relative we can't store it because we
@@ -264,6 +266,7 @@
# We have an absolute path, so we can store it.
wrapped_component = ComponentPathWrapper(
Acquisition.aq_base(component), path)
+
self._utility_registrations[(provided, name)] = (
wrapped_component, info, factory)
self.utilities.register((), provided, name, wrapped_component)
@@ -276,4 +279,3 @@
UtilityRegistration(
self, provided, name, component, info, factory)
))
-
More information about the checkins
mailing list