[Checkins] SVN: zope.component/trunk/src/zope/component/registry.
Merge r88761 from wichert-utility-registration branch
Wichert Akkerman
wichert at wiggy.net
Wed Jul 23 10:22:40 EDT 2008
Log message for revision 88763:
Merge r88761 from wichert-utility-registration branch
Changed:
U zope.component/trunk/src/zope/component/registry.py
U zope.component/trunk/src/zope/component/registry.txt
-=-
Modified: zope.component/trunk/src/zope/component/registry.py
===================================================================
--- zope.component/trunk/src/zope/component/registry.py 2008-07-23 14:15:30 UTC (rev 88762)
+++ zope.component/trunk/src/zope/component/registry.py 2008-07-23 14:22:40 UTC (rev 88763)
@@ -44,7 +44,6 @@
def _init_registrations(self):
self._utility_registrations = {}
- self._utility_subscribers = {}
self._adapter_registrations = {}
self._subscription_registrations = []
self._handler_registrations = []
@@ -77,21 +76,15 @@
return
subscribed = False
- if hasattr(self, '_utility_subscribers'):
- subscribed = self._utility_subscribers.get((provided, component),
- False)
- else:
- for ((p, _), (c,_)) in self._utility_registrations.iteritems():
- if p == provided and c == 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
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:
@@ -116,15 +109,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, _), (c,_)) in self._utility_registrations.iteritems():
- if p == provided and c == 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/trunk/src/zope/component/registry.txt
===================================================================
--- zope.component/trunk/src/zope/component/registry.txt 2008-07-23 14:15:30 UTC (rev 88762)
+++ zope.component/trunk/src/zope/component/registry.txt 2008-07-23 14:22:40 UTC (rev 88763)
@@ -176,7 +176,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, u'')
@@ -190,6 +191,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