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
aaf2edf1
Commit
aaf2edf1
authored
Dec 05, 2000
by
Michel Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes into trunk
parent
35697378
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
130 additions
and
31 deletions
+130
-31
lib/python/Interface/Exceptions.py
lib/python/Interface/Exceptions.py
+1
-1
lib/python/Interface/InterfaceBase.py
lib/python/Interface/InterfaceBase.py
+9
-9
lib/python/Interface/Util.py
lib/python/Interface/Util.py
+2
-2
lib/python/Interface/__init__.py
lib/python/Interface/__init__.py
+3
-2
lib/python/Interface/iclass.py
lib/python/Interface/iclass.py
+79
-2
lib/python/Interface/pprint.py
lib/python/Interface/pprint.py
+24
-3
lib/python/Interface/test.py
lib/python/Interface/test.py
+10
-10
lib/python/Interface/verify.py
lib/python/Interface/verify.py
+2
-2
No files found.
lib/python/Interface/Exceptions.py
View file @
aaf2edf1
...
...
@@ -23,7 +23,7 @@ class BrokenImplementation(Exception):
The %(name)s attribute was not provided.
"""
%
self
.
__dict__
class
BrokenMethodImplementation
(
BrokenImplementa
tion
):
class
BrokenMethodImplementation
(
Excep
tion
):
"""An method is not completely implemented.
"""
...
...
lib/python/Interface/InterfaceBase.py
View file @
aaf2edf1
class
InterfaceBase
:
__
tagged_values
=
{}
__
meta_data
=
{}
def
getName
(
self
):
""" Returns the name of the object. """
...
...
@@ -11,17 +11,17 @@ class InterfaceBase:
""" Returns the documentation for the object. """
return
self
.
__doc__
def
get
TaggedValue
(
self
,
tag
):
""" Returns the value associated with '
tag
'. """
return
self
.
__
tagged_values
[
tag
]
def
get
Data
(
self
,
key
):
""" Returns the value associated with '
key
'. """
return
self
.
__
meta_data
[
key
]
def
get
TaggedValueTag
s
(
self
):
""" Returns a list of all
tag
s. """
return
self
.
__
tagged_values
.
keys
()
def
get
DataKey
s
(
self
):
""" Returns a list of all
key
s. """
return
self
.
__
meta_data
.
keys
()
def
set
TaggedValue
(
self
,
tag
,
value
):
def
set
Data
(
self
,
key
,
value
):
""" Associates 'value' with 'key'. """
self
.
__
tagged_values
[
tag
]
=
value
self
.
__
meta_data
[
key
]
=
value
...
...
lib/python/Interface/Util.py
View file @
aaf2edf1
...
...
@@ -20,7 +20,7 @@ def _ii(klass, items):
for
b
in
klass
.
__bases__
:
_ii
(
b
,
items
)
return
items
def
implementedBy
(
object
):
def
objectImplements
(
object
):
"""Return the interfaces implemented by the object
"""
r
=
[]
...
...
@@ -43,7 +43,7 @@ def implementedBy(object):
return
r
def
i
mplementedByInstancesOf
(
klass
):
def
i
nstancesOfObjectImplements
(
klass
):
"""Return the interfaces that instanced implement (by default)
"""
r
=
[]
...
...
lib/python/Interface/__init__.py
View file @
aaf2edf1
...
...
@@ -3,10 +3,11 @@ from Standard import Base
import
iclass
new
=
iclass
.
Interface
del
iclass
InterfaceInterface
=
iclass
.
InterfaceInterface
# del iclass
from
Util
import
impliedInterface
from
Util
import
assertTypeImplements
,
implementedBy
,
implementedByInstancesOf
from
Util
import
assertTypeImplements
,
objectImplements
,
instancesOfObjectImplements
from
Attr
import
Attribute
from
Method
import
Method
...
...
lib/python/Interface/iclass.py
View file @
aaf2edf1
...
...
@@ -63,7 +63,7 @@ class Interface(InterfaceBase):
if
b
.
extends
(
other
):
return
1
return
0
def
implementedBy
(
self
,
object
,
def
i
sI
mplementedBy
(
self
,
object
,
tiget
=
_typeImplements
.
get
):
"""Does the given object implement the interface?
"""
...
...
@@ -83,7 +83,7 @@ class Interface(InterfaceBase):
else
:
return
self
.
__any
(
implements
)
def
implementedByInstancesOf
(
self
,
klass
,
def
i
sI
mplementedByInstancesOf
(
self
,
klass
,
tiget
=
_typeImplements
.
get
):
"""Do instances of the given class implement the interface?
"""
...
...
@@ -181,3 +181,80 @@ def assertTypeImplements(type, interfaces):
"""Return the interfaces implemented by objects of the given type
"""
_typeImplements
[
type
]
=
interfaces
class
InterfaceBaseInterface
(
Base
):
"""
A base class that defines a common Interface inteface.
"""
def
getName
(
self
):
"""
Returns the name of the current interface object.
"""
def
getDoc
(
self
):
"""
Returns the documentation for the current interface object.
"""
class
InterfaceInterface
(
InterfaceBaseInterface
):
"""
Interface objects describe the behavior of an object by containing
useful information about the object. This information includes:
o Prose documentation about the object. In Python terms, this
is called the "doc string" of the interface. In this element,
you describe how the object works in prose language and any
other useful information about the object.
o Descriptions of attributes. Attribute descriptions include
the name of the attribute and prose documentation describing
the attributes usage.
o Descriptions of methods. Method descriptions can include:
o Prose "doc string" documentation about the method and its
usage.
o A description of the methods arguments; how many arguments
are expected, optional arguments and their default values,
the position or arguments in the signature, whether the
method accepts arbitrary arguments and whether the method
accepts arbitrary keyword arguments.
o Optional tagged data. Interface objects (and their attributes and
methods) can have optional, application specific tagged data
associated with them. Examples uses for this are examples,
security assertions, pre/post conditions, and other possible
information you may want to associate with an Interface or its
attributes.
Not all of this information is mandatory. For example, you may
only want the methods of your interface to have prose
documentation and not describe the arguments of the method in
exact detail. Interface objects are flexible and let you give or
take any of these components.
"""
def
getBases
(
self
):
"""
Returns a sequence of base interfaces this interface extends.
"""
def
extends
(
self
,
other
):
"""
"""
Interface
.
__implements__
=
(
InterfaceInterface
,)
lib/python/Interface/pprint.py
View file @
aaf2edf1
...
...
@@ -3,6 +3,27 @@ import string
""" Pretty-Print an Interface object as structured text (Yum) """
def
trim_doc_string
(
text
):
"""
Trims a doc string to make it format
correctly with structured text.
"""
text
=
string
.
strip
(
text
)
text
=
string
.
replace
(
text
,
'
\
r
\
n
'
,
'
\
n
'
)
lines
=
string
.
split
(
text
,
'
\
n
'
)
nlines
=
[
lines
[
0
]]
if
len
(
lines
)
>
1
:
min_indent
=
None
for
line
in
lines
[
1
:]:
indent
=
len
(
line
)
-
len
(
string
.
lstrip
(
line
))
if
indent
<
min_indent
or
min_indent
is
None
:
min_indent
=
indent
for
line
in
lines
[
1
:]:
nlines
.
append
(
line
[
min_indent
:])
return
string
.
join
(
nlines
,
'
\
n
'
)
def
justify_and_indent
(
text
,
level
,
munge
=
0
,
width
=
72
):
""" indent and justify text, rejustify (munge) if specified """
...
...
@@ -39,14 +60,14 @@ def interface_as_stx(I, munge=0):
level
=
1
if
I
.
getDoc
():
outp
=
outp
+
justify_and_indent
(
I
.
getDoc
(
),
level
)
+
"
\
n
\
n
"
outp
=
outp
+
justify_and_indent
(
trim_doc_string
(
I
.
getDoc
()
),
level
)
+
"
\
n
\
n
"
if
I
.
getBases
():
outp
=
outp
+
(
" "
*
level
)
+
"This interface extends:
\
n
\
n
"
level
=
level
+
1
for
b
in
I
.
getBases
():
item
=
"o %s"
%
b
.
getName
()
outp
=
outp
+
justify_and_indent
(
item
,
level
,
munge
)
+
"
\
n
\
n
"
outp
=
outp
+
justify_and_indent
(
trim_doc_string
(
item
)
,
level
,
munge
)
+
"
\
n
\
n
"
level
=
level
-
1
level
=
level
+
1
...
...
@@ -56,7 +77,7 @@ def interface_as_stx(I, munge=0):
else
:
item
=
"%s -- %s"
%
(
desc
.
getName
(),
desc
.
getDoc
())
outp
=
outp
+
justify_and_indent
(
item
,
level
,
munge
)
+
"
\
n
\
n
"
outp
=
outp
+
justify_and_indent
(
trim_doc_string
(
item
)
,
level
,
munge
)
+
"
\
n
\
n
"
return
outp
...
...
lib/python/Interface/test.py
View file @
aaf2edf1
...
...
@@ -12,11 +12,11 @@ class C:
IC
=
Interface
.
impliedInterface
(
C
)
print
"should be 0:"
,
IC
.
implementedByInstancesOf
(
C
)
print
"should be 0:"
,
IC
.
i
sI
mplementedByInstancesOf
(
C
)
C
.
__implements__
=
IC
print
"should be 1:"
,
IC
.
implementedByInstancesOf
(
C
)
print
"should be 1:"
,
IC
.
i
sI
mplementedByInstancesOf
(
C
)
class
I1
(
Interface
.
Base
):
def
ma
(
self
):
...
...
@@ -42,25 +42,25 @@ class E(A, B):
print
for
c
in
A
,
B
,
C
,
D
,
E
:
print
"%s implements: %s"
%
(
c
.
__name__
,
Interface
.
i
mplementedByInstancesOf
(
c
))
c
.
__name__
,
Interface
.
i
nstancesOfObjectImplements
(
c
))
print
for
c
in
A
,
B
,
C
,
D
,
E
:
print
"an instance of %s implements: %s"
%
(
c
.
__name__
,
Interface
.
implementedBy
(
c
()))
Interface
.
objectImplements
(
c
()))
for
i
in
I1
,
I2
,
I3
,
I4
,
IC
:
print
for
c
in
A
,
B
,
C
,
D
,
E
:
print
"%s is implemented by instances of %s? %s"
%
(
i
.
__name__
,
c
.
__name__
,
i
.
implementedByInstancesOf
(
c
))
i
.
i
sI
mplementedByInstancesOf
(
c
))
print
for
c
in
A
,
B
,
C
,
D
,
E
:
print
"%s is implemented by an instance of %s? %s"
%
(
i
.
__name__
,
c
.
__name__
,
i
.
implementedBy
(
c
()))
i
.
i
sI
mplementedBy
(
c
()))
a
=
A
()
try
:
...
...
@@ -151,16 +151,16 @@ class Blah:
blah_instance
=
Blah
()
if
AnABCInterface
.
implementedBy
(
concrete_instance
):
if
AnABCInterface
.
i
sI
mplementedBy
(
concrete_instance
):
print
"%s is an instance that implements %s"
%
(
concrete_instance
,
AnABCInterface
.
__name__
)
if
AnABCInterface
.
implementedByInstancesOf
(
AConcreteClass
):
if
AnABCInterface
.
i
sI
mplementedByInstancesOf
(
AConcreteClass
):
print
"%s is a class that implements %s"
%
(
AConcreteClass
,
AnABCInterface
.
__name__
)
if
not
AnABCInterface
.
implementedBy
(
blah_instance
):
if
not
AnABCInterface
.
i
sI
mplementedBy
(
blah_instance
):
print
"%s is NOT an instance that implements %s"
%
(
blah_instance
,
AnABCInterface
.
__name__
)
if
not
AnABCInterface
.
implementedByInstancesOf
(
Blah
):
if
not
AnABCInterface
.
i
sI
mplementedByInstancesOf
(
Blah
):
print
"%s is NOT a class that implements %s"
%
(
Blah
,
AnABCInterface
.
__name__
)
...
...
lib/python/Interface/verify.py
View file @
aaf2edf1
...
...
@@ -16,7 +16,7 @@ def verify_class_implementation(iface, klass):
"""
if
not
iface
.
implementedByInstancesOf
(
klass
):
if
not
iface
.
i
sI
mplementedByInstancesOf
(
klass
):
raise
DoesNotImplement
(
iface
)
for
n
,
d
in
iface
.
namesAndDescriptions
():
...
...
@@ -29,7 +29,7 @@ def verify_class_implementation(iface, klass):
elif
type
(
attr
)
is
types
.
MethodType
:
meth
=
Method
().
fromMethod
(
attr
,
n
)
else
:
pass
# must be an attribute...
break
# must be an attribute...
if
d
.
getSignatureInfo
()
!=
meth
.
getSignatureInfo
():
raise
BrokenMethodImplementation
(
n
)
...
...
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