[Zope3-checkins] CVS: Zope3/src/zope/interface - declarations.py:1.17.10.3 interface.py:1.13.4.4 surrogate.py:1.1.2.3

Jim Fulton jim at zope.com
Sun Oct 12 16:40:43 EDT 2003


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

Modified Files:
      Tag: adaptergeddon-branch
	declarations.py interface.py surrogate.py 
Log Message:
Got tests to pass on branch.


=== Zope3/src/zope/interface/declarations.py 1.17.10.2 => 1.17.10.3 ===
--- Zope3/src/zope/interface/declarations.py:1.17.10.2	Sat Oct 11 10:19:03 2003
+++ Zope3/src/zope/interface/declarations.py	Sun Oct 12 16:40:12 2003
@@ -284,7 +284,30 @@
 
     # This also manages storage of implementation specifications
 
-    spec = cls.__dict__.get('__implements__')
+    try:
+        spec = cls.__dict__.get('__implements__')
+    except AttributeError:
+        
+        # we can't get the class dict. This is probably due to a
+        # security proxy.  If this is the case, then probably no
+        # descriptor was installed for the class.
+
+        # We don't want to depend directly on zope.secury in
+        # zope.interface, but we'll try to make reasonable
+        # accomidations in an indirect way.
+
+        # We'll check to see if there's an implements:
+
+        spec = getattr(cls, '__implements__', _empty)
+        if isinstance(spec, Implements):
+            # we defaulted to _empty or there was a spec. Good enough.
+            # Return it.
+            return spec
+
+        # Hm, there's an __implements__, but it's not a spec. Must be
+        # an old-style declaration. Just compute a spec for it
+        return Declaration(*_normalizeargs((spec, )))
+        
     if isinstance(spec, Implements):
         return spec
 
@@ -306,7 +329,8 @@
 
     try:
         cls.__implements__ = spec
-        cls.__providedBy__ = objectSpecificationDescriptor
+        if not hasattr(cls, '__providedBy__'):
+            cls.__providedBy__ = objectSpecificationDescriptor
     except TypeError:
         if not isinstance(cls, type):
             raise TypeError("ImplementedBy called for non-type", cls)


=== Zope3/src/zope/interface/interface.py 1.13.4.3 => 1.13.4.4 ===
--- Zope3/src/zope/interface/interface.py:1.13.4.3	Sat Oct 11 10:51:19 2003
+++ Zope3/src/zope/interface/interface.py	Sun Oct 12 16:40:12 2003
@@ -116,9 +116,6 @@
         self.dependents = weakref.WeakKeyDictionary()
         self.__bases__ = tuple(bases)
 
-    def addDependent(self, ob):
-        self.dependents[ob] = 1
-
     def __setBases(self, bases):
         # Register ourselves as a dependent of our old bases
         for b in self.__bases__:
@@ -141,8 +138,7 @@
         """We, or something we depend on, have changed
         """
         
-        implied = self._implied
-        implied.clear()
+        implied = self._implied = {}
 
         ancestors = ro(self)
         self.__iro__ = tuple([ancestor for ancestor in ancestors
@@ -193,9 +189,12 @@
           >>> list(i)
           []
         """
+        seen = {}
         for base in self.__bases__:
             for interface in base.interfaces():
-                yield interface
+                if interface not in seen:
+                    seen[interface] = 1
+                    yield interface
         
 
     def extends(self, interface, strict=True):
@@ -267,12 +266,6 @@
 
         self.__module__ = __module__
 
-        for b in bases:
-            if not isinstance(b, InterfaceClass):
-                raise TypeError, 'Expected base interfaces'
-
-        Specification.__init__(self, bases)
-
         if attrs is None:
             attrs = {}
 
@@ -287,6 +280,12 @@
             __doc__ = ''
 
         Element.__init__(self, name, __doc__)
+
+        for b in bases:
+            if not isinstance(b, InterfaceClass):
+                raise TypeError, 'Expected base interfaces'
+
+        Specification.__init__(self, bases)
 
         for k, v in attrs.items():
             if isinstance(v, Attribute):


=== Zope3/src/zope/interface/surrogate.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/interface/surrogate.py:1.1.2.2	Sat Oct 11 10:51:19 2003
+++ Zope3/src/zope/interface/surrogate.py	Sun Oct 12 16:40:12 2003
@@ -64,8 +64,8 @@
     def __init__(self, interface, registry):
         self._adapters = {}
         self._implied = {}
-        self._interface = interface
-        interface.addDependent(self)
+        self._interface = weakref.ref(interface)
+        interface.dependents[self] = 1
 
         self._registry = registry
         self.dependents = weakref.WeakKeyDictionary()
@@ -84,7 +84,7 @@
         return False
 
     def isImplementedBy(self, ob):
-        return self._interface.isImplementedBy(ob)
+        return self._interface().isImplementedBy(ob)
 
     def _adaptTo(self, specification, factory, name=None, with=()):
         self._adapters[with, name, specification] = factory




More information about the Zope3-Checkins mailing list