Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
66dc2027
Commit
66dc2027
authored
Jul 11, 2005
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more tests and minor changes
parent
57c09032
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
16 deletions
+83
-16
lib/python/Interface/bridge.py
lib/python/Interface/bridge.py
+11
-13
lib/python/Interface/tests/bridge.txt
lib/python/Interface/tests/bridge.txt
+72
-3
No files found.
lib/python/Interface/bridge.py
View file @
66dc2027
...
@@ -38,7 +38,7 @@ def fromZ3Interface(z3i):
...
@@ -38,7 +38,7 @@ def fromZ3Interface(z3i):
return
_bridges
[
z3i
]
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
():
...
@@ -48,14 +48,12 @@ def fromZ3Interface(z3i):
...
@@ -48,14 +48,12 @@ def fromZ3Interface(z3i):
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.
z2i
=
Z2_InterfaceClass
(
name
=
name
,
z2i
=
Z2_InterfaceClass
(
name
=
name
,
bases
=
bases
,
bases
=
tuple
(
bases
)
,
attrs
=
attrs
,
attrs
=
attrs
,
__doc__
=
z3i
.
getDoc
(),
__doc__
=
z3i
.
getDoc
(),
__module__
=
z3i
.
__module__
)
__module__
=
z3i
.
__module__
)
...
@@ -73,21 +71,21 @@ def fromZ3Attribute(z3a):
...
@@ -73,21 +71,21 @@ 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 'z3
a
'.
""" Return a Zope 2 interface method corresponding to 'z3
m
'.
o 'z3
a
' must be a Zope 3 interface method.
o 'z3
m
' must be a Zope 3 interface method.
"""
"""
if
not
isinstance
(
z3m
,
Z3_Method
):
if
not
isinstance
(
z3m
,
Z3_Method
):
raise
ValueError
,
'Not a Zope 3 interface method!'
raise
ValueError
,
'Not a Zope 3 interface method!'
m
=
Z2_Method
(
z3m
.
getName
(),
z3m
.
getDoc
())
z2
m
=
Z2_Method
(
z3m
.
getName
(),
z3m
.
getDoc
())
sig
=
z3m
.
getSignatureInfo
()
sig
=
z3m
.
getSignatureInfo
()
m
.
positional
=
sig
[
'positional'
]
z2
m
.
positional
=
sig
[
'positional'
]
m
.
required
=
sig
[
'required'
]
z2
m
.
required
=
sig
[
'required'
]
m
.
optional
=
sig
[
'optional'
]
z2
m
.
optional
=
sig
[
'optional'
]
m
.
varargs
=
sig
[
'varargs'
]
z2
m
.
varargs
=
sig
[
'varargs'
]
m
.
kwargs
=
sig
[
'kwargs'
]
z2
m
.
kwargs
=
sig
[
'kwargs'
]
return
m
return
z2
m
def
createZope3Bridge
(
zope3
,
package
,
name
):
def
createZope3Bridge
(
zope3
,
package
,
name
):
# Map a Zope 3 interface into a Zope2 interface, seated within 'package'
# Map a Zope 3 interface into a Zope2 interface, seated within 'package'
...
...
lib/python/Interface/tests/bridge.txt
View file @
66dc2027
...
@@ -12,6 +12,7 @@ interfaces from the two generations:
...
@@ -12,6 +12,7 @@ interfaces from the two generations:
>>> from zope.interface import Interface as Z3_Interface
>>> from zope.interface import Interface as Z3_Interface
>>> from zope.interface import Attribute as Z3_Attribute
>>> from zope.interface import Attribute as Z3_Attribute
>>> from zope.schema import List, TextLine
An empty interface
An empty interface
...
@@ -21,11 +22,39 @@ An empty interface
...
@@ -21,11 +22,39 @@ An empty interface
... pass
... pass
>>> from Interface.bridge import fromZ3Interface
>>> from Interface.bridge import fromZ3Interface
>>>
c
onverted = fromZ3Interface(IEmpty)
>>>
IEmptyC
onverted = fromZ3Interface(IEmpty)
>>> Z2_Interface.isEqualOrExtendedBy(
c
onverted)
>>> Z2_Interface.isEqualOrExtendedBy(
IEmptyC
onverted)
1
1
>>> len(converted.names())
>>> len(IEmptyConverted.names())
0
Bases
-----
>>> class IBase(Z3_Interface):
... pass
>>> class IDerived(IBase):
... pass
>>> IBase.getBases() == (Z3_Interface,)
True
>>> IDerived.getBases() == (IBase,)
True
>>> IDerived.extends(IBase)
True
>>> IDerived.extends(IEmpty)
False
>>> IBaseConverted = fromZ3Interface(IBase)
>>> IDerivedConverted = fromZ3Interface(IDerived)
>>> IBaseConverted.getBases() == (Z2_Interface,)
True
>>> IDerivedConverted.getBases() == (IBaseConverted,)
True
>>> IDerivedConverted.extends(IBaseConverted)
1
>>> IDerivedConverted.extends(IEmptyConverted)
0
0
...
@@ -64,6 +93,42 @@ Attributes
...
@@ -64,6 +93,42 @@ Attributes
'Another attribute'
'Another attribute'
Fields
------
>>> class IFields(Z3_Interface):
... one = TextLine(title=u'one', description=u'One field')
... another = List(title=u'another', description=u'Another field',
... value_type = TextLine())
>>> converted = fromZ3Interface(IFields)
>>> Z2_Interface.isEqualOrExtendedBy(converted)
1
>>> len(converted.names())
2
>>> 'one' in converted.names()
True
>>> 'another' in converted.names()
True
>>> one = converted.getDescriptionFor('one')
>>> isinstance(one, Z2_Attribute)
True
>>> one.getName()
'one'
>>> one.getDoc()
u'one\n\nOne field'
>>> another = converted.getDescriptionFor('another')
>>> isinstance(another, Z2_Attribute)
True
>>> another.getName()
'another'
>>> another.getDoc()
u'another\n\nAnother field'
Methods
Methods
-------
-------
...
@@ -91,6 +156,8 @@ Methods
...
@@ -91,6 +156,8 @@ Methods
'one'
'one'
>>> one.getDoc()
>>> one.getDoc()
'One method.'
'One method.'
>>> one.getSignatureString()
'()'
>>> another = converted.getDescriptionFor('another')
>>> another = converted.getDescriptionFor('another')
>>> isinstance(another, Z2_Method)
>>> isinstance(another, Z2_Method)
...
@@ -99,6 +166,8 @@ Methods
...
@@ -99,6 +166,8 @@ Methods
'another'
'another'
>>> another.getDoc()
>>> another.getDoc()
'Another method, taking arguments.'
'Another method, taking arguments.'
>>> another.getSignatureString()
'(arg1, arg2)'
Invalid parameters
Invalid parameters
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment