[Zodb-checkins] CVS: Zope3/src/zope/interface - _flatten.py:1.5

Jim Fulton jim at zope.com
Sat May 3 13:35:30 EDT 2003


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

Modified Files:
	_flatten.py 
Log Message:
Updated the old _flatten module to use the new declaration machinery.
We really should get rid of this though.



=== Zope3/src/zope/interface/_flatten.py 1.4 => 1.5 ===
--- Zope3/src/zope/interface/_flatten.py:1.4	Thu May  1 15:35:44 2003
+++ Zope3/src/zope/interface/_flatten.py	Sat May  3 12:35:29 2003
@@ -19,40 +19,21 @@
 """
 __metaclass__ = type # All classes are new style when run with Python 2.2+
 
-def _flatten(implements, include_None=0):
-    """Flatten an implements spec to a list of interfaces
-
-    The list includes all base interfaces of the interface(s) in
-    implements. Each interface is listed only once and more
-    specific interfaces are listed before less specific
-    interfaces. This is similar to Python 2.2's MRO.
-    """
-    interfaces = []
-    _flatten_recurse(implements, interfaces)
-    interfaces.reverse()
-    seen = {}
-    flattened = []
-    for interface in interfaces:
-        if interface not in seen:
-            seen[interface] = 1
-            flattened.append(interface)
-    flattened.reverse()
+from zope.interface import Interface, InterfaceSpecification
 
-    if include_None and None not in flattened:
-        flattened.append(None)
+def _flatten(implements, include_None=0):
 
-    return flattened
+    try:
+        r = implements.flattened()
+    except AttributeError:
+        if implements is None:
+            r=()
+        else:
+            r = InterfaceSpecification(implements).flattened()
 
-def _flatten_recurse(implements, list):
-    if implements.__class__ == tuple:
-        for i in implements:
-            _flatten_recurse(i, list)
-    else:
-        _flatten_recurse_interface(implements, list)
+    if not include_None:
+        return r
 
-def _flatten_recurse_interface(interface, list):
-    list.append(interface)
-    if interface is None:
-        return
-    for i in interface.__bases__:
-        _flatten_recurse_interface(i, list)
+    r = list(r)
+    r.append(None)
+    return r




More information about the Zodb-checkins mailing list