[Zope3-checkins]
SVN: Zope3/branches/jim-adapter/src/zope/component/site.py
Fixed a bug in the management of registrations to account for
Jim Fulton
jim at zope.com
Tue Jan 24 07:08:17 EST 2006
Log message for revision 41422:
Fixed a bug in the management of registrations to account for
registrations being overridden.
Changed:
U Zope3/branches/jim-adapter/src/zope/component/site.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/component/site.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/site.py 2006-01-24 04:57:23 UTC (rev 41421)
+++ Zope3/branches/jim-adapter/src/zope/component/site.py 2006-01-24 12:08:16 UTC (rev 41422)
@@ -107,7 +107,12 @@
def __init__(self, name=None):
self.__name__ = name
- self._registrations = []
+
+ # we use a dict for registrations so that overriding
+ # registrations for adapters and utilities make us forget
+ # overridden registrations
+ self._registrations = {}
+
self.adapters = GlobalAdapterRegistry(self, 'adapters')
self.utilities = GlobalAdapterRegistry(self, 'utilities')
@@ -161,9 +166,8 @@
raise TypeError('the required argument should be a list of'
' interfaces, not a single interface')
required = tuple(map(_spec, required))
- self._registrations.append(
- AdapterRegistration(required, provided, name, factory, info),
- )
+ self._registrations[(required, provided, name)] = AdapterRegistration(
+ required, provided, name, factory, info)
self.adapters.register(required, provided, name, factory)
def subscribe(self, required, provided, factory, info=''):
@@ -201,9 +205,11 @@
required = tuple(map(_spec, required))
- self._registrations.append(
- SubscriptionRegistration(required, provided, factory, info),
- )
+ # Note that subscriptions of the same time can be repeated
+ # so we just use the rgistration itself as the key.
+ registration = SubscriptionRegistration(
+ required, provided, factory, info)
+ self._registrations[registration] = registration
self.adapters.subscribe(required, provided, factory)
@@ -219,12 +225,11 @@
# Also subscribe to support getAllUtilitiesRegisteredFor:
self.utilities.subscribe((), providedInterface, component)
- self._registrations.append(
- UtilityRegistration(providedInterface, name, component, info),
- )
+ self._registrations[(providedInterface, name)] = UtilityRegistration(
+ providedInterface, name, component, info)
def registrations(self):
- return iter(self._registrations)
+ return self._registrations.itervalues()
def __reduce__(self):
# Global site managers are pickled as global objects
More information about the Zope3-Checkins
mailing list