stab at making this work:

  >>> fromZ3Interface(x) is fromZ3Interface(x)
  True
parent 452a9b45
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
$Id$ $Id$
""" """
from Interface._InterfaceClass import Interface as Z2_InterfaceClass from Interface._InterfaceClass import Interface as Z2_InterfaceClass
from Interface import Interface as Z2_Interface from Interface import Interface as Z2_Interface
from Interface import Attribute as Z2_Attribute from Interface import Attribute as Z2_Attribute
...@@ -25,9 +24,9 @@ from zope.interface.interface import Interface as Z3_Interface ...@@ -25,9 +24,9 @@ from zope.interface.interface import Interface as Z3_Interface
from zope.interface.interface import Attribute as Z3_Attribute from zope.interface.interface import Attribute as Z3_Attribute
from zope.interface.interface import Method as Z3_Method from zope.interface.interface import Method as Z3_Method
_bridges = {Z3_interface: Z2_Interface}
def fromZ3Interface(z3i): def fromZ3Interface(z3i):
""" Return a Zope 2 interface corresponding to 'z3i'. """ Return a Zope 2 interface corresponding to 'z3i'.
o 'z3i' must be a Zope 3 interface. o 'z3i' must be a Zope 3 interface.
...@@ -35,36 +34,35 @@ def fromZ3Interface(z3i): ...@@ -35,36 +34,35 @@ def fromZ3Interface(z3i):
if not isinstance(z3i, Z3_InterfaceClass): if not isinstance(z3i, Z3_InterfaceClass):
raise ValueError, 'Not a Zope 3 interface!' raise ValueError, 'Not a Zope 3 interface!'
if z3i is Z3_Interface: # special case; root in new hierarchy! if z3i in _bridges:
return Z2_Interface return _bridges[z3i]
name = z3i.getName() name = z3i.getName()
bases = [fromZ3Interface(x) for x in z3i.getBases()]
bases = [ fromZ3Interface(x) for x in z3i.getBases() ]
attrs = {} attrs = {}
for k, v in z3i.namesAndDescriptions(): for k, v in z3i.namesAndDescriptions():
if isinstance(v, Z3_Method): if isinstance(v, Z3_Method):
v = fromZ3Method(v) v = fromZ3Method(v)
elif isinstance(v, Z3_Attribute): elif isinstance(v, Z3_Attribute):
v = fromZ3Attribute(v) v = fromZ3Attribute(v)
#TODO bridge Fields to Attributes?
attrs[k] = v attrs[k] = v
# XXX: Note that we pass the original interface's __module__; # XXX: Note that we pass the original interface's __module__;
# we may live to regret that. # we may live to regret that.
return Z2_InterfaceClass(name=name, z2i = Z2_InterfaceClass(name=name,
bases=bases, bases=bases,
attrs=attrs, attrs=attrs,
__doc__=z3i.getDoc(), __doc__=z3i.getDoc(),
__module__=z3i.__module__, __module__=z3i.__module__)
) _bridges[z3i] = z2i
return z2i
def fromZ3Attribute(z3a): def fromZ3Attribute(z3a):
""" Return a Zope 2 interface attribute corresponding to 'z3a'. """ Return a Zope 2 interface attribute corresponding to 'z3a'.
o 'z3a' must be a Zope 3 interface attribute. o 'z3a' must be a Zope 3 interface attribute.
...@@ -75,7 +73,6 @@ def fromZ3Attribute(z3a): ...@@ -75,7 +73,6 @@ def fromZ3Attribute(z3a):
return Z2_Attribute(z3a.getName(), z3a.getDoc()) return Z2_Attribute(z3a.getName(), z3a.getDoc())
def fromZ3Method(z3m): def fromZ3Method(z3m):
""" Return a Zope 2 interface method corresponding to 'z3a'. """ Return a Zope 2 interface method corresponding to 'z3a'.
o 'z3a' must be a Zope 3 interface method. o 'z3a' must be a Zope 3 interface method.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment