[Zope-Checkins] CVS: Zope/lib/python/Interface - Standard.py:1.2.140.1 Util.py:1.7.20.2 __init__.py:1.5.96.2 iclass.py:1.11.20.2 test.py:NONE unitfixtures.py:NONE unittests.py:NONE

Shane Hathaway shane@digicool.com
Wed, 12 Sep 2001 14:55:15 -0400


Update of /cvs-repository/Zope/lib/python/Interface
In directory cvs.zope.org:/tmp/cvs-serv26908

Modified Files:
      Tag: ComponentArchitecture-branch
	Standard.py Util.py __init__.py iclass.py 
Removed Files:
      Tag: ComponentArchitecture-branch
	test.py unitfixtures.py unittests.py 
Log Message:
- Used visitor pattern in Util, which enables the same code to both
  search for interfaces and create a list of interfaces.

- Brought unit tests in sync with common Zope practice

- Removed implied interface of interface objects since interface objects
  already have an explicit interface.


=== Zope/lib/python/Interface/Standard.py 1.2 => 1.2.140.1 ===
 import iclass, Util
 
-Interface=Util.impliedInterface(
-    iclass.Interface, "Interface",
-    """Interface of Interface objects
-    """)
-iclass.Interface.__implements__=Interface
-
-from iclass import Named, Class
+from iclass import Named, Class, InterfaceInterface
 
 from Basic import *
 


=== Zope/lib/python/Interface/Util.py 1.7.20.1 => 1.7.20.2 ===
     for b in klass.__bases__: _ii(b, items)
     return items
-    
-def _listInterfaces(object, implements, getInterface, append):
+
+
+def _visitRecursively(object, implements, visitor, getInterface):
     if isinstance(implements, Interface):
-        append(implements)
+        r = visitor(implements)
     elif implements == CLASS_INTERFACES:
         klass = getattr(object, '__class__', None)
         if klass is not None:
-            lst = instancesOfObjectImplements(klass, getInterface)
-            for i in lst:
-                append(i)
+            r = visitInterfacesOfInstances(klass, visitor, getInterface)
     elif type(implements) is StringType:
         if getInterface is not None:
-            # Look up the interface.
-            real = getInterface(object, implements, None)
+            # Look up a named interface.
+            real = getInterface(object, implements)
             if real is not None:
-                append(real)
+                r = _visitRecursively(object, real, visitor, getInterface)
     else:
         # A sequence of interfaces.
         for i in implements:
-            _listInterfaces(object, i, getInterface, append)
+            r = _visitRecursively(object, i, visitor, getInterface)
+            if r:
+                break
+    return r
 
-def objectImplements(object, getInterface=None,
-                     tiget=_typeImplements.get):
-    """Return the interfaces implemented by the object
-    """
-    r = []
-    t=type(object)
+
+def visitInterfaces(object, visitor, getInterface=None):
+    t = type(object)
     if t in ClassTypes:
         if hasattr(object, '__class_implements__'):
             implements=object.__class_implements__
         else:
             implements=Class
     elif hasattr(object, '__implements__'):
-        implements=object.__implements__
+        implements = object.__implements__
     else:
-        implements=tiget(t, None)
+        implements = _typeImplements.get(t, None)
         if implements is None:
-            return r
-    _listInterfaces(object, implements, getInterface, r.append)
-    return r
+            return None
+    return _visitRecursively(object, implements, visitor, getInterface)
     
-def instancesOfObjectImplements(klass, getInterface=None,
-                                tiget=_typeImplements.get):
-    """Return the interfaces that instanced implement (by default)
-    """
-    r = []
+    
+    
+def visitInterfacesOfInstances(klass, visitor, getInterface=None):
     if type(klass) in ClassTypes:
         if hasattr(klass, '__implements__'):
-            implements=klass.__implements__
-        else: return r
+            implements = klass.__implements__
+        else:
+            return None
     elif hasattr(klass, 'instancesImplements'):
         # Hook for ExtensionClass. :)
-        implements=klass.instancesImplements()
+        # XXX Potential security problem since "instancesImplements"
+        # is a valid Zope identifier.
+        implements = klass.instancesImplements()
     else:
-        implements=tiget(klass,None)
+        implements = _typeImplements.get(klass, None)
     if implements is None:
-        return r
-    _listInterfaces(klass, implements, getInterface, r.append)
+        return None
+    return _visitRecursively(klass, implements, visitor, getInterface)
+
+
+def objectImplements(object, getInterface=None):
+    r = []
+    visitInterfaces(object, r.append, getInterface)
+    return r
+
+
+def instancesOfObjectImplements(klass, getInterface=None):
+    r = []
+    visitInterfacesOfInstances(klass, r.append, getInterface)
     return r
+
+


=== Zope/lib/python/Interface/__init__.py 1.5.96.1 => 1.5.96.2 ===
-from Standard import Base
+from Standard import Base, InterfaceInterface
 
 import iclass
 new=iclass.Interface
-InterfaceInterface=iclass.InterfaceInterface
 CLASS_INTERFACES = iclass.CLASS_INTERFACES
 # del iclass
 


=== Zope/lib/python/Interface/iclass.py 1.11.20.1 => 1.11.20.2 ===
     """Prototype (scarecrow) Interfaces Implementation
     """
-
     def __init__(self, name, bases=(), attrs=None, __doc__=None):
         """Create a new interface
         """
@@ -345,4 +344,5 @@
 
         """
 
-Interface.__implements__ = (InterfaceInterface,)
+Interface.__implements__ = InterfaceInterface
+

=== Removed File Zope/lib/python/Interface/test.py ===

=== Removed File Zope/lib/python/Interface/unitfixtures.py ===

=== Removed File Zope/lib/python/Interface/unittests.py ===