[Zodb-checkins] CVS: Zope3/src/zope/interface - interface.py:1.13.4.3 surrogate.py:1.1.2.2

Jim Fulton jim at zope.com
Sat Oct 11 10:51:50 EDT 2003


Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv12193/src/zope/interface

Modified Files:
      Tag: adaptergeddon-branch
	interface.py surrogate.py 
Log Message:
fixed some tests.

Modified surgates to use declarations directly.


=== Zope3/src/zope/interface/interface.py 1.13.4.2 => 1.13.4.3 ===
--- Zope3/src/zope/interface/interface.py:1.13.4.2	Sat Oct 11 10:19:03 2003
+++ Zope3/src/zope/interface/interface.py	Sat Oct 11 10:51:19 2003
@@ -81,8 +81,6 @@
     >>> from zope.interface import Interface
     >>> class I1(Interface):
     ...     pass
-    >>> class I1(I1):
-    ...     pass
     >>> class I2(I1):
     ...     pass
     >>> class I3(I2):
@@ -94,15 +92,15 @@
     >>> [i.__name__ for i in I2.__bases__]
     ['I1']
 
-    >>> i3.extends(I1)
+    >>> I3.extends(I1)
     1
 
-    >>> i2.__bases__ = (Interface, )
+    >>> I2.__bases__ = (Interface, )
 
     >>> [i.__name__ for i in I2.__bases__]
     ['Interface']
 
-    >>> i3.extends(I1)
+    >>> I3.extends(I1)
     0
     
     
@@ -183,8 +181,8 @@
           ...
           >>> class I4(I3): pass
           ...
-          >>> spec = Specification(I2, I3)
-          >>> spec = Specification(I4, spec)
+          >>> spec = Specification((I2, I3))
+          >>> spec = Specification((I4, spec))
           >>> i = spec.interfaces()
           >>> i.next().getName()
           'I4'
@@ -209,6 +207,7 @@
         Examples::
 
           >>> from zope.interface import Interface
+          >>> from zope.interface.declarations import Declaration
           >>> class I1(Interface): pass
           ...
           >>> class I2(I1): pass


=== Zope3/src/zope/interface/surrogate.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/interface/surrogate.py:1.1.2.1	Fri Oct 10 07:16:38 2003
+++ Zope3/src/zope/interface/surrogate.py	Sat Oct 11 10:51:19 2003
@@ -264,17 +264,15 @@
             return default
         
         interface = surrogate
-    
-        for declaration in providedBy(ob):
-            s = surrogates.get(declaration)
-            if s is None:
-                s = self.get(declaration)
-
-            factories = s._implied.get(interface)
-            if factories is not None:
-                for factory in factories:
-                    ob = factory(ob)
-                return ob
+
+        declaration = providedBy(ob)
+        s = self.get(declaration)
+
+        factories = s._implied.get(interface)
+        if factories is not None:
+            for factory in factories:
+                ob = factory(ob)
+            return ob
 
         return default
 
@@ -337,16 +335,13 @@
             # have an adapter for it.
             return default
     
-        for declaration in providedBy(ob):
-            s = surrogates.get(declaration)
-            if s is None:
-                s = self.get(declaration)
-
-            factories = s._implied.get((interface, name))
-            if factories is not None:
-                for factory in factories:
-                    ob = factory(ob)
-                return ob
+        declaration = providedBy(ob)
+        s = self.get(declaration)
+        factories = s._implied.get((interface, name))
+        if factories is not None:
+            for factory in factories:
+                ob = factory(ob)
+            return ob
 
         return default
 
@@ -416,38 +411,37 @@
         ob = objects[0]
         order = len(objects)
         objects = objects[1:]
-        for declaration in providedBy(ob):
-            s = surrogates.get(declaration)
-            if s is None:
-                s = self.get(declaration)
-
-            adapters = s._implied.get((interface, name, order))
-            if adapters:
-                matched = None
-                matched_factories = None
-                for interfaces, factories in adapters.iteritems():
-                    for iface, ob in zip(interfaces, objects):
-                        if not iface.isImplementedBy(ob):
-                            break # This one is no good
+
+        declaration = providedBy(ob)
+        s = self.get(declaration)
+
+        adapters = s._implied.get((interface, name, order))
+        if adapters:
+            matched = None
+            matched_factories = None
+            for interfaces, factories in adapters.iteritems():
+                for iface, ob in zip(interfaces, objects):
+                    if not iface.isImplementedBy(ob):
+                        break # This one is no good
+                else:
+                    # we didn't break, so we have a match
+                    if matched is None:
+                        matched = interfaces
+                        matched_factories = factories
                     else:
-                        # we didn't break, so we have a match
-                        if matched is None:
-                            matched = interfaces
-                            matched_factories = factories
-                        else:
-                            for iface, m in zip(interfaces, matched):
-                                if iface.extends(m):
-                                    # new is better than old
-                                    matched = interfaces
-                                    matched_factories = factories
-                                    break
-                                elif m.extends(iface):
-                                    # old is better than new
-                                    break                
-
-                for factory in matched_factories:
-                    ob = factory(ob)
-                return ob
+                        for iface, m in zip(interfaces, matched):
+                            if iface.extends(m):
+                                # new is better than old
+                                matched = interfaces
+                                matched_factories = factories
+                                break
+                            elif m.extends(iface):
+                                # old is better than new
+                                break                
+
+            for factory in matched_factories:
+                ob = factory(ob)
+            return ob
 
         return None
         




More information about the Zodb-checkins mailing list