[Zodb-checkins] CVS: Zope3/src/zope/interface - declarations.py:1.3

Jim Fulton jim at zope.com
Sat May 3 13:36:19 EDT 2003


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

Modified Files:
	declarations.py 
Log Message:
Provided new interface declaration machinery.
See zope.interface.interfaces.IIInterfaceDeclaration.



=== Zope3/src/zope/interface/declarations.py 1.2 => 1.3 === (1155/1255 lines abridged)
--- Zope3/src/zope/interface/declarations.py:1.2	Wed Apr 30 16:13:23 2003
+++ Zope3/src/zope/interface/declarations.py	Sat May  3 12:36:19 2003
@@ -1,87 +1,1200 @@
 ##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2003 Zope Corporation and Contributors.
 # All Rights Reserved.
-#
+# 
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-#
 ##############################################################################
-"""Interfaces declarations, forward comptability versions
+"""Implementation of interface declarations
 
 $Id$
 """
 
 import sys
+import weakref
+from zope.interface.interface import InterfaceClass, mergeOrderings
+import exceptions
 from types import ClassType
-_ClassTypes = ClassType, type
-del ClassType
 
-def directlyProvides(ob, *interfaces):
-    
-    if isinstance(ob, _ClassTypes):
-        ob.__class_implements__ = interfaces
-        return
+DescriptorAwareMetaClasses = ClassType, type
+
+# implementation info for immutable classes (heap flag clear)
+_implements_reg = weakref.WeakKeyDictionary()
+
+__metaclass__ = type
+
+heap = 1 << 9
+
+# Notes:
+#
+# We have 3 implementations of interface specifications:
+#

[-=- -=- -=- 1155 lines omitted -=- -=- -=-]

+        raise exceptions.BadImplements(specs)
+    
+    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:
+            # Try to avoid an infinate loop by getting a string!
+            raise TypeError("Bad interface specification", spec)
+        else:
+            _flattenSpecs(spec, result)
+
+    return result
+
+def _getmro(C, r):
+  if C not in r: r.append(C)
+  for b in C.__bases__:
+    _getmro(b, r)
+  return r
+
+def _gatherSpecs(cls, result):
+    implements = _getImplements(cls)
+    if implements is not None:
+        try:
+            stop = implements.only
+        except AttributeError:
+            # Must be an old-style interface spec
+            implements = OnlyImplementsSpecification(
+                _flattenSpecs([implements], []))
+            stop = 1
+            _setImplements(cls, implements)
+            
+        result.append(implements)
+    else:
+        stop = 0
+        
+    if not stop:
+        for b in cls.__bases__:
+            _gatherSpecs(b, result)
+
+    return result
+
+_empty = InterfaceSpecification()
+
+
+# DocTest:
+if __name__ == "__main__":
+    import doctest, __main__
+    doctest.testmod(__main__, isprivate=lambda *a: False)




More information about the Zodb-checkins mailing list