[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/component/components.py Fix a bug in utility registrations. Utilities were not getting

Jim Fulton jim at zope.com
Tue Feb 28 18:26:49 EST 2006


Log message for revision 65624:
  Fix a bug in utility registrations. Utilities were not getting
  subscribed.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/component/components.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/component/components.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/components.py	2006-02-28 23:26:46 UTC (rev 65623)
+++ Zope3/branches/jim-adapter/src/zope/component/components.py	2006-02-28 23:26:48 UTC (rev 65624)
@@ -57,9 +57,20 @@
     def registerUtility(self, component, provided=None, name=u'', info=u''):
         if provided is None:
             provided = _getUtilityProvided(component)
-        self._utility_registrations[(provided, name)] = component, info
+
+
+        subscribed = [
+            1
+            for ((p, _), (c,_)) in self._utility_registrations.iteritems()
+            if p == provided and c == component
+            ]
+
+        self._utility_registrations[(provided, name)] = component, info        
         self.utilities.register((), provided, name, component)
 
+        if not subscribed:
+            self.utilities.subscribe((), provided, component)
+
     def unregisterUtility(self, component=None, provided=None, name=u''):
         if provided is None:
             if component is None:
@@ -70,9 +81,21 @@
         if (old is None) or ((component is not None) and
                              (component != old[0])):
             return False
-        
+
+        if component is None:
+            component = old[0]
         del self._utility_registrations[(provided, name)]
         self.utilities.unregister((), provided, name)
+
+        subscribed = [
+            1
+            for ((p, _), (c,_)) in self._utility_registrations.iteritems()
+            if p == provided and c == component
+            ]
+
+        if not subscribed:
+            self.utilities.unsubscribe((), provided, component)
+        
         return True
 
     def registeredUtilities(self):



More information about the Zope3-Checkins mailing list