[Checkins] SVN: Zope3/branches/3.3/src/zope/app/interface/ Fix other persistent interface attributes that require conversion

Ross Patterson me at rpatterson.net
Mon Feb 26 22:04:42 EST 2007


Log message for revision 72868:
  Fix other persistent interface attributes that require conversion
  

Changed:
  U   Zope3/branches/3.3/src/zope/app/interface/__init__.py
  U   Zope3/branches/3.3/src/zope/app/interface/tests/test_interface.py

-=-
Modified: Zope3/branches/3.3/src/zope/app/interface/__init__.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/interface/__init__.py	2007-02-27 02:56:25 UTC (rev 72867)
+++ Zope3/branches/3.3/src/zope/app/interface/__init__.py	2007-02-27 03:04:41 UTC (rev 72868)
@@ -30,9 +30,13 @@
 
 persistentFactories = {}
 def getPersistentKey(v_key):
-    if not hasattr(v_key, '__reduce__'):
+    try:
+        reduce = v_key.__reduce__()
+    except AttributeError:
         return
-    reduce = v_key.__reduce__()
+    except TypeError:
+        return
+        
     lookups = reduce[0], type(v_key), getattr(v_key, '__class__')
     for lookup in lookups:
         p_factory = persistentFactories.get(lookup, None)
@@ -122,11 +126,19 @@
 
 
 def getInterfaceStateForPersistentInterfaceCreation(iface):
-    # Need to convert the dependents weakref dict to a persistent dict
     dict = iface.__dict__.copy()
+
+    deps = dict['dependents']
     dependents = DependentsDict()
-    for k, v in dict['dependents'].iteritems():
+    for k, v in deps.iteritems():
         dependents[k] = v
+    del dict['dependents']
+
+    for key, value in dict.iteritems():
+        p_value = getPersistentKey(value)
+        if p_value is not None:
+            dict[key] = p_value
+    
     dict['dependents'] = dependents
     return dict
 

Modified: Zope3/branches/3.3/src/zope/app/interface/tests/test_interface.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/interface/tests/test_interface.py	2007-02-27 02:56:25 UTC (rev 72867)
+++ Zope3/branches/3.3/src/zope/app/interface/tests/test_interface.py	2007-02-27 03:04:41 UTC (rev 72868)
@@ -29,6 +29,8 @@
 from zodbcode.module import ManagedRegistry
 
 from zope.interface import Interface, implements, directlyProvides
+from zope.interface.interfaces import IInterface
+from zope.component.interface import provideInterface
 from zope.app.interface import PersistentInterface
 
 # TODO: for some reason changing this code to use implements() does not
@@ -63,6 +65,8 @@
 
 class IQux(Interface): pass
 
+class IBarInterface(IInterface): pass
+
 class PersistentInterfaceTest(unittest.TestCase):
 
     def setUp(self):
@@ -182,6 +186,19 @@
             Baz.__implemented__.__bases__,
             barmodule.IBar.dependents.keys()[1].__bases__
             )
+
+    def test_persistentProvides(self):
+        """Verify that provideInterface works."""
+
+        self.registry.newModule("barmodule", bar_code)
+        barmodule = self.registry.findModule("barmodule")
+        provideInterface('', barmodule.IBar, iface_type=IBarInterface)
+        self.assertTrue(IBarInterface.providedBy(barmodule.IBar))
+
+        self.registry.updateModule('barmodule',
+                                   bar_code + '\nfoo = 1')
+        barmodule = self.registry.findModule("barmodule")
+        self.assertTrue(IBarInterface.providedBy(barmodule.IBar))
         
 def test_suite():
     return unittest.makeSuite(PersistentInterfaceTest)



More information about the Checkins mailing list