[Zope3-checkins] SVN: Zope3/trunk/src/zope/component/ - Fixed a bug on unregistering handlers. When multiple handlers for one

Christian Theune ct at gocept.com
Thu Aug 17 17:05:47 EDT 2006


Log message for revision 69627:
   - Fixed a bug on unregistering handlers. When multiple handlers for one
     specification where registered, all of them would be removed when only a
     single one was unregistered.
  
  

Changed:
  U   Zope3/trunk/src/zope/component/registry.py
  U   Zope3/trunk/src/zope/component/tests.py

-=-
Modified: Zope3/trunk/src/zope/component/registry.py
===================================================================
--- Zope3/trunk/src/zope/component/registry.py	2006-08-17 20:52:02 UTC (rev 69626)
+++ Zope3/trunk/src/zope/component/registry.py	2006-08-17 21:05:47 UTC (rev 69627)
@@ -336,7 +336,7 @@
             return False
 
         self._handler_registrations[:] = new
-        self.adapters.unsubscribe(required, None)
+        self.adapters.unsubscribe(required, None, factory)
 
         zope.event.notify(interfaces.Unregistered(
             HandlerRegistration(self, required, name, factory, '')

Modified: Zope3/trunk/src/zope/component/tests.py
===================================================================
--- Zope3/trunk/src/zope/component/tests.py	2006-08-17 20:52:02 UTC (rev 69626)
+++ Zope3/trunk/src/zope/component/tests.py	2006-08-17 21:05:47 UTC (rev 69627)
@@ -911,7 +911,7 @@
     >>> r2.lookup((), IFoo, '2')
 
     >>> base.register((), IFoo, '2', Foo('2'))
-    
+
     >>> r1.lookup((), IFoo, '2')
     Foo('2')
 
@@ -925,6 +925,32 @@
 
     """
 
+
+def test_multi_handler_unregistration():
+    """There was a bug where multiple handlers for the same required specification
+    would all be removed when one of them was unregistered:
+
+    >>> class I(zope.interface.Interface):
+    ...     pass
+    >>> def factory1(event):
+    ...     print "| Factory 1 is here" 
+    >>> def factory2(event):
+    ...     print "| Factory 2 is here" 
+    >>> class Event(object):
+    ...     zope.interface.implements(I)
+    >>> from zope.component.registry import Components
+    >>> registry = Components()
+    >>> registry.registerHandler(factory1, [I,])
+    >>> registry.registerHandler(factory2, [I,])
+    >>> registry.handle(Event())
+    | Factory 1 is here
+    | Factory 2 is here
+    >>> registry.unregisterHandler(factory1, [I,])
+    True
+    >>> registry.handle(Event())
+    | Factory 2 is here
+    """
+
 class StandaloneTests(unittest.TestCase):
     def testStandalone(self):
         import subprocess



More information about the Zope3-Checkins mailing list