stab at making this work:

  >>> fromZ3Interface(x) is fromZ3Interface(x)
  True
parent 452a9b45
......@@ -14,7 +14,6 @@
$Id$
"""
from Interface._InterfaceClass import Interface as Z2_InterfaceClass
from Interface import Interface as Z2_Interface
from Interface import Attribute as Z2_Attribute
......@@ -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 Method as Z3_Method
_bridges = {Z3_interface: Z2_Interface}
def fromZ3Interface(z3i):
""" Return a Zope 2 interface corresponding to 'z3i'.
o 'z3i' must be a Zope 3 interface.
......@@ -35,36 +34,35 @@ def fromZ3Interface(z3i):
if not isinstance(z3i, Z3_InterfaceClass):
raise ValueError, 'Not a Zope 3 interface!'
if z3i is Z3_Interface: # special case; root in new hierarchy!
return Z2_Interface
if z3i in _bridges:
return _bridges[z3i]
name = z3i.getName()
bases = [ fromZ3Interface(x) for x in z3i.getBases() ]
bases = [fromZ3Interface(x) for x in z3i.getBases()]
attrs = {}
for k, v in z3i.namesAndDescriptions():
if isinstance(v, Z3_Method):
v = fromZ3Method(v)
elif isinstance(v, Z3_Attribute):
v = fromZ3Attribute(v)
#TODO bridge Fields to Attributes?
attrs[k] = v
# XXX: Note that we pass the original interface's __module__;
# we may live to regret that.
return Z2_InterfaceClass(name=name,
bases=bases,
attrs=attrs,
__doc__=z3i.getDoc(),
__module__=z3i.__module__,
)
z2i = Z2_InterfaceClass(name=name,
bases=bases,
attrs=attrs,
__doc__=z3i.getDoc(),
__module__=z3i.__module__)
_bridges[z3i] = z2i
return z2i
def fromZ3Attribute(z3a):
""" Return a Zope 2 interface attribute corresponding to 'z3a'.
o 'z3a' must be a Zope 3 interface attribute.
......@@ -75,7 +73,6 @@ def fromZ3Attribute(z3a):
return Z2_Attribute(z3a.getName(), z3a.getDoc())
def fromZ3Method(z3m):
""" Return a Zope 2 interface method corresponding to 'z3a'.
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