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
47341875
Commit
47341875
authored
Nov 30, 2000
by
Michel Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code that verifies an implementation is valid given an interface
parent
a1e042db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
lib/python/Interface/verify.py
lib/python/Interface/verify.py
+41
-0
No files found.
lib/python/Interface/verify.py
0 → 100644
View file @
47341875
from
Exceptions
import
BrokenImplementation
,
DoesNotImplement
,
BrokenMethodImplementation
from
Method
import
Method
import
types
def
verify_class_implementation
(
iface
,
klass
):
"""
Verify that 'klass' correctly implements 'iface'. This involves:
o Making sure the klass defines all the necessary methods
o Making sure the methods have the correct signature
o Making sure the klass asserts that it implements the interface
"""
if
not
iface
.
implementedByInstancesOf
(
klass
):
raise
DoesNotImplement
(
iface
)
for
n
,
d
in
iface
.
namesAndDescriptions
():
if
not
hasattr
(
klass
,
n
):
raise
BrokenImplementation
(
iface
,
n
)
attr
=
getattr
(
klass
,
n
)
if
type
(
attr
)
is
types
.
FunctionType
:
meth
=
Method
().
fromFunction
(
attr
,
n
)
elif
type
(
attr
)
is
types
.
MethodType
:
meth
=
Method
().
fromMethod
(
attr
,
n
)
else
:
raise
"NotAMethod"
,
"%s is not a method or function"
%
attr
methinfo
=
meth
.
getSignatureInfo
()
attrinfo
=
meth
.
getSignatureInfo
()
for
k
in
d
.
getSignatureInfo
().
keys
():
if
not
(
methinfo
[
k
]
is
attrinfo
[
k
]
or
methinfo
[
k
]
==
attrinfo
[
k
]):
raise
BrokenMethodImplementation
(
n
,
k
)
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