[Zope3-checkins] CVS: Zope3/src/zope/interface - declarations.py:1.2.6.2
   
    Jim Fulton
     
    jim@zope.com
       
    Sat, 3 May 2003 11:41:07 -0400
    
    
  
Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv13110
Modified Files:
      Tag: interfacegeddon2-branch
	declarations.py 
Log Message:
Added some support for ExtensionClass instances.
Old style declarations like:
  class C(ExtensionClass.Base):
     __implements__ = IFoo
work.
Also:
  class C(ExtensionClass.Base):
     pass
  classImplements(IFoo)
works.
But use of implements and classprovides will produce incorrect
behavior.  I'll be able to fix this in the next iteration.
Note, however, that we need to disallow declarations of interface
declarations for ExtensionClasses themselves until ExtensionClass is
rewritten to support descriptors.
=== Zope3/src/zope/interface/declarations.py 1.2.6.1 => 1.2.6.2 ===
--- Zope3/src/zope/interface/declarations.py:1.2.6.1	Fri May  2 15:42:53 2003
+++ Zope3/src/zope/interface/declarations.py	Sat May  3 11:40:36 2003
@@ -18,6 +18,9 @@
 import weakref
 from zope.interface.interface import InterfaceClass, mergeOrderings
 import exceptions
+from types import ClassType
+
+DescriptorAwareMetaClasses = ClassType, type
 
 # implementation info for immutable classes (heap flag clear)
 _implements_reg = weakref.WeakKeyDictionary()
@@ -438,7 +441,7 @@
         ...
         >>> class A: implements(I1)
         ...
-        >>> class B: implements(I2)
+        >>> class B: __implements__ = I2
         ...
         >>> class C(A, B): implements(I31)
         ...
@@ -490,7 +493,7 @@
         
         provides = getattr(ob, '__provides__', None)
         if provides is not None:
-            result = [provides]
+            result = [provides.__signature__]
         else:
             result = []
 
@@ -775,6 +778,16 @@
 
     """
 
+    # We need to avoid setting this attribute on meta classes that
+    # don't support descriptors.
+    # We can do away with this check when we get rid of the old EC
+    cls = getattr(object, '__class__', None)
+    if cls is not None and getattr(cls,  '__class__', None) is cls:
+        # It's a meta class (well, at least it it could be an extension class)
+        if not isinstance(object, DescriptorAwareMetaClasses):
+            raise TypeError("Attempt to make an interface declaration on a "
+                            "non-descriptor-aware class")
+
     object.__provides__ = ProvidesSpecification(*interfaces)
 
 def implementedBy(class_):
@@ -1111,7 +1124,10 @@
 
     if flags & heap:
         cls.__implements__ = v
-        cls.__providedBy__ = _objectSpecificationDescriptor
+
+        # Only set up the descriptor if the class supports descriptors
+        if isinstance(cls, DescriptorAwareMetaClasses):
+            cls.__providedBy__ = _objectSpecificationDescriptor
     else:
         _implements_reg[cls] = v