[Zope3-checkins] SVN: Zope3/trunk/ Fixed bug in handling multiple bases that led to adapter-registry

Jim Fulton jim at zope.com
Sun Nov 27 16:58:29 EST 2005


Log message for revision 40385:
  Fixed bug in handling multiple bases that led to adapter-registry
  failures.
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/interface/adapter.py
  U   Zope3/trunk/src/zope/interface/interface.py
  U   Zope3/trunk/src/zope/interface/tests/test_adapter.py
  U   Zope3/trunk/src/zope/interface/tests/test_interface.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-11-27 21:12:24 UTC (rev 40384)
+++ Zope3/trunk/doc/CHANGES.txt	2005-11-27 21:58:28 UTC (rev 40385)
@@ -162,6 +162,10 @@
 
     Bug Fixes
 
+      - Fixed a bug in adapter registrations that caused errors and
+        lookup failures when specifications had multiple base
+        specifications.
+
       - Made OrderedContainer.updateOrder send an IContainerModifiedEvent.
 
       - Fixed bug 451, http://www.zope.org/Collectors/Zope3-dev/451

Modified: Zope3/trunk/src/zope/interface/adapter.py
===================================================================
--- Zope3/trunk/src/zope/interface/adapter.py	2005-11-27 21:12:24 UTC (rev 40384)
+++ Zope3/trunk/src/zope/interface/adapter.py	2005-11-27 21:58:28 UTC (rev 40385)
@@ -268,10 +268,16 @@
     multiImplied = ReadProperty(multiImplied)
 
     def subscribe(self, dependent):
-        self.dependents[dependent] = 1
+        self.dependents[dependent] = self.dependents.get(dependent, 0) + 1
 
     def unsubscribe(self, dependent):
-        del self.dependents[dependent]
+        n = self.dependents.get(dependent, 0) - 1
+        if not n:
+            del self.dependents[dependent]
+        elif n > 0:
+            self.dependents[dependent] = n
+        else:
+            raise KeyError(dependent)
 
     def _adaptTo(self, specification, object, name='', with=()):
         if object is None:

Modified: Zope3/trunk/src/zope/interface/interface.py
===================================================================
--- Zope3/trunk/src/zope/interface/interface.py	2005-11-27 21:12:24 UTC (rev 40384)
+++ Zope3/trunk/src/zope/interface/interface.py	2005-11-27 21:58:28 UTC (rev 40385)
@@ -228,10 +228,16 @@
         self.__bases__ = tuple(bases)
 
     def subscribe(self, dependent):
-        self.dependents[dependent] = 1
+        self.dependents[dependent] = self.dependents.get(dependent, 0) + 1
 
     def unsubscribe(self, dependent):
-        del self.dependents[dependent]
+        n = self.dependents.get(dependent, 0) - 1
+        if not n:
+            del self.dependents[dependent]
+        elif n > 0:
+            self.dependents[dependent] = n
+        else:
+            raise KeyError(dependent)
 
     def __setBases(self, bases):
         # Register ourselves as a dependent of our old bases

Modified: Zope3/trunk/src/zope/interface/tests/test_adapter.py
===================================================================
--- Zope3/trunk/src/zope/interface/tests/test_adapter.py	2005-11-27 21:12:24 UTC (rev 40384)
+++ Zope3/trunk/src/zope/interface/tests/test_adapter.py	2005-11-27 21:58:28 UTC (rev 40385)
@@ -300,7 +300,29 @@
     >>> registry.lookup((IF1, IB1), IR0, '')
     'A10'
     """
+
+def test_duplicate_bases():
+    """
+There was a bug that caused problems if a spec had multiple bases:
+
+    >>> class I(zope.interface.Interface):
+    ...     pass
+    >>> class I2(I, I):
+    ...     pass
+    >>> registry = AdapterRegistry()
+    >>> registry.register([I2], IR0, 'x', 'X')
+    >>> registry.lookup((I2, ), IR0, 'x')
+    'X'
+    >>> registry.register([I2], IR0, 'y', 'Y')
+    >>> registry.lookup((I2, ), IR0, 'x')
+    'X'
+    >>> registry.lookup((I2, ), IR0, 'y')
+    'Y'
+
     
+
+"""
+    
 def test_suite():
     from zope.testing import doctest, doctestunit
     return unittest.TestSuite((

Modified: Zope3/trunk/src/zope/interface/tests/test_interface.py
===================================================================
--- Zope3/trunk/src/zope/interface/tests/test_interface.py	2005-11-27 21:12:24 UTC (rev 40384)
+++ Zope3/trunk/src/zope/interface/tests/test_interface.py	2005-11-27 21:58:28 UTC (rev 40385)
@@ -311,7 +311,23 @@
 
         """
 
+def duplicate_bases_management():
+    """
+There was a bug that surfaced when an interface was repeated in
+a set of bases and the bases were changed:
 
+    >>> class I(interface.Interface):
+    ...     pass
+
+    >>> class I2(I, I):
+    ...     pass
+
+    >>> I2.__bases__ = (I,)
+    
+
+"""
+
+
 def test_suite():
     from zope.testing import doctest
     suite = unittest.makeSuite(InterfaceTests)



More information about the Zope3-Checkins mailing list