[Checkins]
SVN: zope.component/branches/wichert-utility-factories/src/zope/component/registry.
Fix handling of utility (un)registration.
Wichert Akkerman
wichert at wiggy.net
Wed Jul 23 10:11:00 EDT 2008
Log message for revision 88761:
Fix handling of utility (un)registration.
Changed:
U zope.component/branches/wichert-utility-factories/src/zope/component/registry.py
U zope.component/branches/wichert-utility-factories/src/zope/component/registry.txt
-=-
Modified: zope.component/branches/wichert-utility-factories/src/zope/component/registry.py
===================================================================
--- zope.component/branches/wichert-utility-factories/src/zope/component/registry.py 2008-07-23 12:58:40 UTC (rev 88760)
+++ zope.component/branches/wichert-utility-factories/src/zope/component/registry.py 2008-07-23 14:10:57 UTC (rev 88761)
@@ -44,7 +44,6 @@
def _init_registrations(self):
self._utility_registrations = {}
- self._utility_subscribers = {}
self._adapter_registrations = {}
self._subscription_registrations = []
self._handler_registrations = []
@@ -82,21 +81,15 @@
return
subscribed = False
- if hasattr(self, '_utility_subscribers'):
- subscribed = self._utility_subscribers.get((provided, component),
- False)
- else:
- for ((p, _), data) in self._utility_registrations.iteritems():
- if p == provided and data[0] == component:
- subscribed = True
- break
+ for ((p, _), data) in self._utility_registrations.iteritems():
+ if p == provided and data[0] == component:
+ subscribed = True
+ break
self._utility_registrations[(provided, name)] = component, info, factory
self.utilities.register((), provided, name, component)
if not subscribed:
- if hasattr(self, '_utility_subscribers'):
- self._utility_subscribers[(provided, component)] = True
self.utilities.subscribe((), provided, component)
if event:
@@ -126,15 +119,10 @@
self.utilities.unregister((), provided, name)
subscribed = False
- if hasattr(self, '_utility_subscribers'):
- subscribed = self._utility_subscribers.get((provided, component),
- False)
- del self._utility_subscribers[(provided, component)]
- else:
- for ((p, _), data) in self._utility_registrations.iteritems():
- if p == provided and data[0] == component:
- subscribed = True
- break
+ for ((p, _), data) in self._utility_registrations.iteritems():
+ if p == provided and data[0] == component:
+ subscribed = True
+ break
if not subscribed:
self.utilities.unsubscribe((), provided, component)
Modified: zope.component/branches/wichert-utility-factories/src/zope/component/registry.txt
===================================================================
--- zope.component/branches/wichert-utility-factories/src/zope/component/registry.txt 2008-07-23 12:58:40 UTC (rev 88760)
+++ zope.component/branches/wichert-utility-factories/src/zope/component/registry.txt 2008-07-23 14:10:57 UTC (rev 88761)
@@ -185,7 +185,8 @@
it includes utilities that are overridden. For example, we'll
register a utility that for an extending interface of I2:
- >>> components.registerUtility(tests.U('ext'), tests.I2e)
+ >>> util = tests.U('ext')
+ >>> components.registerUtility(util, tests.I2e)
Registered event:
UtilityRegistration(<Components comps>, I2e, u'', ext, None, u'')
@@ -199,6 +200,15 @@
>>> sorted(map(str, components.getAllUtilitiesRegisteredFor(tests.I2)))
['U(ext)', 'U12(2)', 'U12(3)']
+Removing a utility also makes it disappear from getUtilitiesFor:
+
+ >>> components.unregisterUtility(util, tests.I2e)
+ Unregistered event:
+ UtilityRegistration(<Components comps>, I2e, u'', ext, None, u'')
+ True
+ >>> list(components.getAllUtilitiesRegisteredFor(tests.I2e))
+ []
+
Adapters
--------
More information about the Checkins
mailing list