[Checkins] SVN: five.localsitemanager/trunk/ Merged r105144:105157 from 1.0 branch and adjusted it to trunk
Hanno Schlichting
hannosch at hannosch.eu
Mon Oct 19 13:11:36 EDT 2009
Log message for revision 105158:
Merged r105144:105157 from 1.0 branch and adjusted it to trunk
Changed:
U five.localsitemanager/trunk/CHANGES.txt
U five.localsitemanager/trunk/setup.py
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-10-19 16:24:14 UTC (rev 105157)
+++ five.localsitemanager/trunk/CHANGES.txt 2009-10-19 17:11:35 UTC (rev 105158)
@@ -4,7 +4,11 @@
2.0.1 - Unreleased
------------------
+* Adapt unregistering of components work to work with latest zope.component.
+ [hannosch]
+* Fix unregistering of components which have a physical path.
+ [thefunny42]
2.0 - 2009-09-27
----------------
@@ -50,7 +54,6 @@
* Requiring zope.component >= 3.5.0.
[icemac]
-
1.0 - 2008-11-18
----------------
@@ -59,7 +62,7 @@
look-up is stored in the adapter look-up cache, subsequent utility
look-ups return the utlitiy with the RequestContainer of the first
look-up.
-
+
Solution: For utilities registered with an absolute path the
RequestContainer is now also removed at look-up.
[icemac]
Modified: five.localsitemanager/trunk/setup.py
===================================================================
--- five.localsitemanager/trunk/setup.py 2009-10-19 16:24:14 UTC (rev 105157)
+++ five.localsitemanager/trunk/setup.py 2009-10-19 17:11:35 UTC (rev 105158)
@@ -1,5 +1,3 @@
-"""Setup for five.localsitemanager package
-"""
from setuptools import setup
version = '2.0.1dev'
Modified: five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2009-10-19 16:24:14 UTC (rev 105157)
+++ five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2009-10-19 17:11:35 UTC (rev 105158)
@@ -70,6 +70,25 @@
>>> sitemanager.getUtility(ITestUtility, name=u'factory_test')
<Utility TestUtility "factory_test">
+You can unregister a registered utility:
+
+ >>> sitemanager.registerUtility(TestUtility('test_to_be_removed'),
+ ... name='to_remove',
+ ... provided=ITestUtility)
+
+ >>> utility = sitemanager.getUtility(ITestUtility, name='to_remove')
+ >>> utility
+ <Utility TestUtility "test_to_be_removed">
+
+ >>> sitemanager.unregisterUtility(utility, name='to_remove')
+ True
+
+ >>> sitemanager.getUtility(ITestUtility, name='to_remove')
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: (<InterfaceClass ...ITestUtility>, 'to_remove')
+
+
Adapters
---------
@@ -219,6 +238,27 @@
>>> Acquisition.aq_parent(comp) is site
True
+And finally unregisterUtility():
+
+ >>> sitemanager.registerUtility(AQTestUtility('aq_to_remove'),
+ ... name=u'aq_to_remove',
+ ... provided=ITestUtility)
+
+ >>> utility = sitemanager.getUtility(ITestUtility, name='aq_to_remove')
+ >>> utility
+ <Utility AQTestUtility "aq_to_remove">
+
+ >>> sitemanager.unregisterUtility(utility,
+ ... provided=ITestUtility,
+ ... name='aq_to_remove')
+ True
+
+ >>> sitemanager.getUtility(ITestUtility, name='aq_to_remove')
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: (<InterfaceClass ...ITestUtility>, 'aq_to_remove')
+
+
Absolute Path
~~~~~~~~~~~~~
@@ -323,7 +363,7 @@
>>> len(aqutils)
2
>>> aqutils
- [(u'aq_wrapped', <Utility AQTestUtility "test">),
+ [(u'aq_wrapped', <Utility AQTestUtility "test">),
(u'with_aq_chain', <SITestUtility at /a/b/c/si_util_cped>)]
And then getAllUtilitiesRegisteredFor():
@@ -368,11 +408,36 @@
>>> aqutils = [comp for comp in utils if IAcquirer.providedBy(comp)]
>>> len(aqutils)
2
+
>>> sorted(aqutils, key=lambda x:x.id)
[<SITestUtility at /a/b/c/si_util_cped>,
<Utility AQTestUtility "test">]
+And unregisterUtility():
+ >>> si_to_remove = self.app.a.b._setObject('si_to_remove',
+ ... SITestUtility('si_to_remove'))
+ >>> sitemanager_a.registerUtility(self.app.a.b.si_to_remove,
+ ... name=u'with_aq_chain_to_remove',
+ ... provided=ITestUtility)
+
+ >>> utility = sitemanager_a.getUtility(ITestUtility,
+ ... name=u'with_aq_chain_to_remove')
+ >>> utility
+ <SITestUtility at /a/b/si_to_remove>
+
+ >>> sitemanager_a.unregisterUtility(utility,
+ ... provided=ITestUtility,
+ ... name=u'with_aq_chain_to_remove')
+ True
+
+ >>> sitemanager_a.getUtility(ITestUtility,
+ ... name=u'with_aq_chain_to_remove')
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: (<InterfaceClass ...ITestUtility>, u'with_aq_chain_to_remove')
+
+
Nested Sites
------------
Modified: five.localsitemanager/trunk/src/five/localsitemanager/registry.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2009-10-19 16:24:14 UTC (rev 105157)
+++ five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2009-10-19 17:11:35 UTC (rev 105158)
@@ -196,7 +196,10 @@
def __eq__(self, other):
return self.component == other
+ def __ne__(self, other):
+ return self.component != other
+
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
@@ -282,6 +285,29 @@
if event:
zope.event.notify(zope.component.interfaces.Registered(
- UtilityRegistration(
- self, provided, name, component, info, factory)
- ))
+ UtilityRegistration(
+ self, provided, name, component, info, factory)
+ ))
+
+ def unregisterUtility(self, component=None, provided=None, name=u'',
+ factory=None):
+ if factory:
+ if component:
+ raise TypeError("Can't specify factory and component.")
+ component = factory()
+
+ if provided is None:
+ if component is None:
+ raise TypeError("Must specify one of component, factory and "
+ "provided")
+ provided = _getUtilityProvided(component)
+
+ old = self._utility_registrations.get((provided, name))
+ if isinstance(old[0], ComponentPathWrapper):
+ # If the existing registration is a ComponentPathWrapper, we
+ # convert the component that is to be unregistered to a wrapper.
+ # This ensures that our custom comparision methods are called.
+ component = ComponentPathWrapper(Acquisition.aq_base(component),'')
+
+ return super(PersistentComponents, self).unregisterUtility(
+ component=component, provided=provided, name=name)
More information about the checkins
mailing list