[Zodb-checkins] CVS: Zope3/src/zope/interface - _callableimplements.py:1.1.2.2 adapter.py:1.3.16.2 declarations.py:1.1.2.2 implements.py:1.4.4.2 interface.py:1.8.4.2 interfaces.py:1.12.4.2

Jim Fulton jim at zope.com
Fri May 2 15:56:14 EDT 2003


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

Modified Files:
      Tag: interfacegeddon-branch
	_callableimplements.py adapter.py declarations.py 
	implements.py interface.py interfaces.py 
Log Message:
Got unit tests to pass (and made this branch a full branch).

I'll make detailed comments when I merge.


=== Zope3/src/zope/interface/_callableimplements.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/interface/_callableimplements.py:1.1.2.1	Fri Apr 18 22:46:19 2003
+++ Zope3/src/zope/interface/_callableimplements.py	Fri May  2 14:55:43 2003
@@ -21,10 +21,9 @@
 
 Module = sys.__class__
 
-class ImplementsModule(Module):
+class ImplementsModule:
 
     def __init__(self):
-        Module.__init__(self)
         self.__dict__.update(sys.modules['zope.interface.implements'].__dict__)
 
     def __call__(self, *interfaces):


=== Zope3/src/zope/interface/adapter.py 1.3.16.1 => 1.3.16.2 ===
--- Zope3/src/zope/interface/adapter.py:1.3.16.1	Fri Apr 18 22:46:19 2003
+++ Zope3/src/zope/interface/adapter.py	Fri May  2 14:55:43 2003
@@ -117,7 +117,7 @@
 
         try:
             flattened = ob_interface.flattened
-        except:
+        except AttributeError:
             # Somebodey (probably a test) passed us a bare interface
             if ob_interface is not None:
                 flattened = InterfaceSpecification(ob_interface).flattened()
@@ -126,8 +126,9 @@
         else:
             flattened = flattened()
         
-        
-        for interface in flattened:
+
+        try:
+         for interface in flattened:
             c = self._reg.get((interface, provide))
             if c:
                 c = c[1]
@@ -135,6 +136,8 @@
                     return c
                 if filter(c):
                     return c
+        except AttributeError:
+            import pdb; pdb.set_trace()
 
         c = self._reg.get((None, provide))
         if c:


=== Zope3/src/zope/interface/declarations.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/interface/declarations.py:1.1.2.1	Fri Apr 18 22:46:19 2003
+++ Zope3/src/zope/interface/declarations.py	Fri May  2 14:55:43 2003
@@ -452,11 +452,11 @@
         1
         >>> int(I3 in providedBy(c))
         0
-        >>> providedBy(c).extends(I3)
+        >>> int(providedBy(c).extends(I3))
         1
-        >>> providedBy(c).extends(I31)
+        >>> int(providedBy(c).extends(I31))
         1
-        >>> providedBy(c).extends(I5)
+        >>> int(providedBy(c).extends(I5))
         0
         >>> class COnly(A, B): implementsOnly(I31)
         ...
@@ -472,13 +472,13 @@
         0
         >>> int(I3 in providedBy(c))
         0
-        >>> providedBy(c).extends(I3)
+        >>> int(providedBy(c).extends(I3))
         1
-        >>> providedBy(c).extends(I1)
+        >>> int(providedBy(c).extends(I1))
         0
-        >>> providedBy(c).extends(I31)
+        >>> int(providedBy(c).extends(I31))
         1
-        >>> providedBy(c).extends(I5)
+        >>> int(providedBy(c).extends(I5))
         1
     """
 
@@ -510,18 +510,42 @@
                 except AttributeError: flags = heap
                 
                 if flags & heap:
-                    implements = c.__dict__.get('__implements__')
-                    if implements is not None:
-                        try:
-                            sig = implements.__signature__
-                        except AttributeError:
-                            # Old-style implements!  Fix it up.
-                            implements = OnlyImplementsSpecification(
-                                implements)
-                            c.__implements__ = implements
-                            sig = implements.__signature__
+                    try:
+                        dict = c.__dict__
+                    except AttributeError:
+
+                        # XXX If we got here, we must have a
+                        # security-proxied class. This introduces an
+                        # indirect dependency on security proxies,
+                        # which we don't want. This is necessary to
+                        # support old-style __implements__ interface
+                        # declarations.
+
+                        # If we got here, we must have an old-style
+                        # declaration, so we'll just look for an
+                        # __implements__.
+
+                        implements = getattr(c, '__implements__', None)
+                        if implements is not None:
+                            result.append(`implements`)
+                        
+                    else:
+
+                        # Normal case
+                        
+                        implements = dict.get('__implements__')
+
+                        if implements is not None:
+                            try:
+                                sig = implements.__signature__
+                            except AttributeError:
+                                # Old-style implements!  Fix it up.
+                                implements = OnlyImplementsSpecification(
+                                    implements)
+                                _setImplements(c, implements)
+                                sig = implements.__signature__
 
-                        result.append(sig)
+                            result.append(sig)
                 else:
                     # Look in reg
                     implements = _implements_reg.get(c)
@@ -574,8 +598,11 @@
         return self._v_spec - other
 
 def providedBy(ob):
+
+    # Here we have either a special object, an old-style declaration
+    # or a descriptor
+
     try:
-        # Here we have either an old-style declaration or a descriptor
         r = ob.__providedBy__        
     except AttributeError:
         # No descriptor, so fall back to a plain object spec
@@ -1047,7 +1074,28 @@
     except AttributeError: flags = heap
 
     if flags & heap:
-        d = cls.__dict__
+        try:
+            d = cls.__dict__
+
+        except AttributeError:
+
+            # XXX If we got here, we must have a
+            # security-proxied class. This introduces an
+            # indirect dependency on security proxies,
+            # which we don't want. This is necessary to
+            # support old-style __implements__ interface
+            # declarations.
+
+            # If we got here, we must have an old-style
+            # declaration, so we'll just look for an
+            # __implements__.
+
+            implements = getattr(cls, '__implements__', None)
+            if implements is not None:
+                implements = OnlyImplementsSpecification(implements)
+                
+            return implements
+
         k = '__implements__'
     else:
         d = _implements_reg
@@ -1057,8 +1105,10 @@
 
 def _setImplements(cls, v):
 
-    try: flags = cls.__flags__
-    except AttributeError: flags = heap
+    try:
+        flags = cls.__flags__
+    except AttributeError:
+        flags = heap
 
     if flags & heap:
         cls.__implements__ = v
@@ -1074,17 +1124,20 @@
     >>> I3 = InterfaceClass('I3', (), {})
     >>> spec = InterfaceSpecification(I1, I2)
     >>> r = _flattenSpecs((I3, spec), [])
-    >>> r == [I3, I1, I2]
+    >>> int(r == [I3, I1, I2])
     1
     
     """
-    try: specs = list(specs)
+    try:
+        # catch bad spec by seeing if we can iterate over it
+        ispecs = iter(specs)
     except TypeError:
         # Must be a bad spec
         raise exceptions.BadImplements(specs)
     
-    for spec in specs:
-        if isinstance(spec, InterfaceClass):
+    for spec in ispecs:
+        # We do this rather than isinstance because it works w proxies classes
+        if InterfaceClass in spec.__class__.__mro__:
             if spec not in result:
                 result.append(spec)
         elif spec is specs:
@@ -1111,7 +1164,7 @@
             implements = OnlyImplementsSpecification(
                 _flattenSpecs([implements], []))
             stop = 1
-            cls.__implements__ = implements
+            _setImplements(cls, implements)
             
         result.append(implements)
     else:


=== Zope3/src/zope/interface/implements.py 1.4.4.1 => 1.4.4.2 ===
--- Zope3/src/zope/interface/implements.py:1.4.4.1	Fri Apr 18 22:46:19 2003
+++ Zope3/src/zope/interface/implements.py	Fri May  2 14:55:43 2003
@@ -50,15 +50,15 @@
 instancesOfObjectImplements = implementedBy
 
 def _flatten(i, append):
-    if isinstance(i, (list, tuple)):
-        for iface in i:
-            _flatten(iface, append)
-    else:
+    if InterfaceClass in i.__class__.__mro__:
         append(i)
         bases = i.getBases()
         if bases:
             for b in bases:
                 _flatten(b, append)
+    else:
+        for iface in i:
+            _flatten(iface, append)
 
 def flattenInterfaces(interfaces, remove_duplicates=1):
     res = []


=== Zope3/src/zope/interface/interface.py 1.8.4.1 => 1.8.4.2 ===
--- Zope3/src/zope/interface/interface.py:1.8.4.1	Fri Apr 18 22:46:19 2003
+++ Zope3/src/zope/interface/interface.py	Fri May  2 14:55:43 2003
@@ -76,15 +76,19 @@
                  __module__=None):
 
         if __module__ is None:
-            if attrs is not None and ('__module__' in attrs):
+            if (attrs is not None and
+                ('__module__' in attrs) and
+                isinstance(attrs['__module__'], str)
+                ):
                 __module__ = attrs['__module__']
                 del attrs['__module__']
             else:
+
                 try:
                     # Figure out what module defined the interface.
                     # This is how cPython figures out the module of
                     # a class, but of course it does it in C. :-/
-                    __module__ = sys._getFrame(1).f_globals['__name__']
+                    __module__ = sys._getframe(1).f_globals['__name__']
                 except (AttributeError, KeyError):
                     pass
 
@@ -96,8 +100,6 @@
         # Python expects __bases__ to be a tuple.
         self.__bases__ = tuple(bases)
 
-        self.__iro__ = mergeOrderings([_flattenInterface(self, [])])
-
         if attrs is None:
             attrs = {}
         if '__doc__' in attrs:
@@ -112,6 +114,8 @@
 
         Element.__init__(self, name, __doc__)
 
+        self.__iro__ = mergeOrderings([_flattenInterface(self, [])])
+
         for k, v in attrs.items():
             if isinstance(v, Attribute):
                 v.interface = name
@@ -368,7 +372,7 @@
 
     return result
 
-Interface = InterfaceClass("Interface")
+Interface = InterfaceClass("Interface", __module__ = 'zope.interface')
 
 class Attribute(Element):
     """Attribute descriptions


=== Zope3/src/zope/interface/interfaces.py 1.12.4.1 => 1.12.4.2 ===
--- Zope3/src/zope/interface/interfaces.py:1.12.4.1	Fri Apr 18 22:46:19 2003
+++ Zope3/src/zope/interface/interfaces.py	Fri May  2 14:55:43 2003
@@ -235,6 +235,8 @@
         interface directly and indirectly by base interfaces.
         """
 
+    __module__ = Attribute("""The name of the module defining the interface""")
+
     __bases__ = Attribute("""A tuple of base interfaces""")
     __iro__ = Attribute(
         """A tuple of all interfaces extended by the interface




More information about the Zodb-checkins mailing list