[Zope3-checkins] SVN: Zope3/branches/Zope-3.1/src/zope/interface/ Merged changes from X3.0 branch:

Jim Fulton jim at zope.com
Sat Jul 30 09:32:05 EDT 2005


Log message for revision 37594:
  Merged changes from X3.0 branch:
  
  ------------------------------------------------------------------------
    r28827 | jim | 2005-01-13 12:13:21 -0500 (Thu, 13 Jan 2005) | 3 lines
  
  Added some cleanup code to avoid a spurious memory-leak
    report.
  
  ------------------------------------------------------------------------
    r28828 | jim | 2005-01-13 12:13:22 -0500 (Thu, 13 Jan 2005) | 3 lines
  
  Fixed a bug reported by James Knight.  Adapter registries sometimes
    failed to reflect declaration changes.
  

Changed:
  U   Zope3/branches/Zope-3.1/src/zope/interface/README.txt
  U   Zope3/branches/Zope-3.1/src/zope/interface/adapter.py
  U   Zope3/branches/Zope-3.1/src/zope/interface/tests/test_adapter.py
  U   Zope3/branches/Zope-3.1/src/zope/interface/tests/test_declarations.py

-=-
Modified: Zope3/branches/Zope-3.1/src/zope/interface/README.txt
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/interface/README.txt	2005-07-30 13:03:33 UTC (rev 37593)
+++ Zope3/branches/Zope-3.1/src/zope/interface/README.txt	2005-07-30 13:32:05 UTC (rev 37594)
@@ -668,9 +668,11 @@
   [RangeError(Range(2, 1))]
 
 
+  >>> del errors[:]
 
 
 
+
 .. [#create] The main reason we subclass `Interface` is to cause the
              Python class statement to create an interface, rather
              than a class.

Modified: Zope3/branches/Zope-3.1/src/zope/interface/adapter.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/interface/adapter.py	2005-07-30 13:03:33 UTC (rev 37593)
+++ Zope3/branches/Zope-3.1/src/zope/interface/adapter.py	2005-07-30 13:32:05 UTC (rev 37594)
@@ -123,6 +123,7 @@
 
     def __init__(self, spec, registry):
         self.spec = spec.weakref()
+        self.registry = registry
         spec.subscribe(self)
         self.adapters = {}
         self.dependents = weakref.WeakKeyDictionary()
@@ -138,6 +139,18 @@
             del self.selfImplied
             del self.multImplied
             del self.get
+
+        bases = [self.registry.get(base) for base in self.spec().__bases__]
+        if bases != self.__bases__:
+            # Our bases changed. unsubscribe from the old ones
+            # and subscribe to the new ones
+            for base in self.__bases__:
+                base.unsubscribe(self)
+
+            self.__bases__ = bases
+            for base in bases:
+                base.subscribe(self)
+
         for dependent in self.dependents.keys():
             dependent.dirty()
 

Modified: Zope3/branches/Zope-3.1/src/zope/interface/tests/test_adapter.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/interface/tests/test_adapter.py	2005-07-30 13:03:33 UTC (rev 37593)
+++ Zope3/branches/Zope-3.1/src/zope/interface/tests/test_adapter.py	2005-07-30 13:32:05 UTC (rev 37594)
@@ -284,6 +284,33 @@
     >>> hook = zope.interface.interface.adapter_hooks.pop()
     """
 
+
+def test_changing_declarations():
+    """
+
+    If we change declarations for a class, those adapter lookup should
+    eflect the changes:
+
+    >>> class I1(zope.interface.Interface):
+    ...     pass
+    >>> class I2(zope.interface.Interface):
+    ...     pass
+
+    >>> registry = AdapterRegistry()
+    >>> registry.register([I1], I2, '', 42)
+
+    >>> class C:
+    ...     pass
+
+    >>> registry.lookup([zope.interface.implementedBy(C)], I2, '')
+
+    >>> zope.interface.classImplements(C, I1)
+
+    >>> registry.lookup([zope.interface.implementedBy(C)], I2, '')
+    42
+    """
+
+
 def test_suite():
     from zope.testing import doctest, doctestunit
     return unittest.TestSuite((

Modified: Zope3/branches/Zope-3.1/src/zope/interface/tests/test_declarations.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/interface/tests/test_declarations.py	2005-07-30 13:03:33 UTC (rev 37593)
+++ Zope3/branches/Zope-3.1/src/zope/interface/tests/test_declarations.py	2005-07-30 13:32:05 UTC (rev 37594)
@@ -308,7 +308,12 @@
 
       >>> implementedBy(cls) is impl
       True
-    
+
+    Of course, we don't want to leave it there. :)
+
+      >>> del zope.interface.declarations.BuiltinImplementationSpecifications[
+      ...   cls]
+
     """
 
 def test_declaration_get():
@@ -355,9 +360,9 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(Test))
+    #suite.addTest(unittest.makeSuite(Test))
     suite.addTest(DocTestSuite("zope.interface.declarations"))
-    suite.addTest(DocTestSuite())
+    #suite.addTest(DocTestSuite())
     
     return suite
 



More information about the Zope3-Checkins mailing list