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
201f3133
Commit
201f3133
authored
Nov 25, 1998
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial
parent
c1ce70b0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
341 additions
and
0 deletions
+341
-0
lib/python/Interface/Basic.py
lib/python/Interface/Basic.py
+23
-0
lib/python/Interface/Mapping.py
lib/python/Interface/Mapping.py
+22
-0
lib/python/Interface/Number.py
lib/python/Interface/Number.py
+95
-0
lib/python/Interface/README
lib/python/Interface/README
+1
-0
lib/python/Interface/Standard.py
lib/python/Interface/Standard.py
+22
-0
lib/python/Interface/Util.py
lib/python/Interface/Util.py
+62
-0
lib/python/Interface/__init__.py
lib/python/Interface/__init__.py
+6
-0
lib/python/Interface/iclass.py
lib/python/Interface/iclass.py
+110
-0
No files found.
lib/python/Interface/Basic.py
0 → 100644
View file @
201f3133
from
iclass
import
Base
class
Mutable
(
Base
):
"""Mutable objects
"""
class
Comparable
(
Base
):
"""Objects that can be tested for equality
"""
class
Orderable
(
Comparable
):
"""Objects that can be compared with < > == <= >= !="""
class
Hashable
(
Base
):
"""Objects that support hash"""
class
Key
(
Comparable
,
Hashable
):
"""Objects that are immutable with respect to state that
influences comparisons or hash values"""
lib/python/Interface/Mapping.py
0 → 100644
View file @
201f3133
import
Basic
,
Util
class
Mapping
(
Basic
.
Base
):
"anything supporting __getitem__"
class
Sized
(
Basic
.
Base
):
"anything supporting __len"
class
MutableMapping
(
Basic
.
Mutable
):
"Has __setitem__ and __delitem__"
class
Sequence
(
Mapping
):
"Keys must be integers in a sequence starting at 0."
class
Sequential
(
Sequence
):
"Keys must be used in order"
Util
.
assertTypeImplements
(
type
(()),
(
Sequence
,
Sized
,
Basic
.
Key
))
Util
.
assertTypeImplements
(
type
([]),
(
Sequence
,
Sized
,
MutableMapping
))
Util
.
assertTypeImplements
(
type
({}),
(
Mapping
,
Sized
,
MutableMapping
))
lib/python/Interface/Number.py
0 → 100644
View file @
201f3133
import
Basic
,
Util
class
BitNumber
(
Basic
.
Base
):
"""Numbers that can be interpreted as strings of bits
they support & | ~ ^ << >>
"""
class
Number
(
Basic
.
Base
):
"""Numeric interface
it is assumed that numeric types are embedded in each other in some
way (this is the Scheme numerical tower I think); they support
operators + - *, usually / and %, perhaps **
"""
class
Offsetable
(
Basic
.
Base
):
"""Things that you can subtract and add numbers too
e.g. Date-Time values.
"""
class
Real
(
Number
):
"""any subset of the real numbers (this includes ints and rationals)
"""
class
Complex
(
Number
):
"""has re and im fields (which are themselves real)
"""
class
Exact
(
Number
):
"""e.g. integers and rationals; also fixed point
"""
class
AbritraryPrecision
(
Exact
):
"""e.g. long, rationals
"""
class
FixedPrecisionInt
(
Exact
):
"""Fixed precision integers
"""
class
FP64
(
FixedPrecisionInt
):
"""int() applied to these returns an integer that fits in 32 bits
"""
class
FP32
(
FP64
):
"""int() applied to these returns an integer that fits in 32 bits
"""
class
FP16
(
FP32
):
"""int() applied to these returns an integer that fits in 16 bits
"""
class
FP8
(
FP16
):
"""int() applied to these returns an integer that fits in 16 bits
"""
class
FP1
(
FP8
):
"""int() applied to these returns an integer that fits in 16 bits
"""
class
Signed
(
FixedPrecisionInt
):
"""These can be < 0
"""
class
Unsigned
(
FixedPrecisionInt
):
"""These can not be < 0
"""
class
CheckedOverflow
(
FixedPrecisionInt
):
"""raises OverflowError when results don't fit
"""
class
UncheckedOverflow
(
FixedPrecisionInt
):
"""take results module 2**N (for example)
"""
class
FD
(
Exact
):
"""fixed_decimal<n+m>
a signed fixed decimal number with n digits
before and m digits after the decimal point
"""
class
Inexact
(
Number
):
"""floating point arithmetic
"""
Util
.
assertTypeImplements
(
type
(
1
),
(
FP32
,
BitNumber
,
Signed
))
Util
.
assertTypeImplements
(
type
(
1L
),
(
AbritraryPrecision
,
BitNumber
,
Signed
))
Util
.
assertTypeImplements
(
type
(
1.0
),
(
Inexact
,
BitNumber
,
Signed
))
lib/python/Interface/README
0 → 100644
View file @
201f3133
Scarecrow interface implementation
lib/python/Interface/Standard.py
0 → 100644
View file @
201f3133
import
iclass
,
Util
Interface
=
Util
.
impliedInterface
(
iclass
.
Interface
,
"Interface"
,
"""Interface of Interface objects
"""
)
iclass
.
Interface
.
__implements__
=
Interface
from
Basic
import
*
class
Class
(
Base
):
"""Implement shared instance behavior and create instances
Classes can be called to create an instance. This interface does
not specify what if any arguments are required.
"""
Util
.
assertTypeImplements
(
iclass
.
ClassType
,
Class
)
from
Number
import
*
from
Mapping
import
*
lib/python/Interface/Util.py
0 → 100644
View file @
201f3133
from
iclass
import
Interface
,
ClassType
,
Base
,
assertTypeImplements
def
impliedInterface
(
klass
,
__name__
=
None
,
__doc__
=
None
):
"""Create an interface object from a class
The interface will contain only objects with doc strings and with names
that begin and end with '__' or names that don't begin with '_'.
"""
if
__name__
is
None
:
name
=
"%sInterface"
%
klass
.
__name__
return
Interface
(
__name__
,
(),
_ii
(
klass
,
{}),
__doc__
)
def
_ii
(
klass
,
items
):
for
k
,
v
in
klass
.
__dict__
.
items
():
if
k
[:
1
]
==
'_'
and
not
(
len
(
k
)
>
4
and
k
[:
2
]
==
'__'
and
k
[
-
2
:]
==
'__'
):
continue
items
[
k
]
=
v
for
b
in
klass
.
__bases__
:
_ii
(
b
)
return
items
def
implementedBy
(
object
):
"""Return the interfaces implemented by the object
"""
r
=
[]
implements
=
tiget
(
type
(
object
),
None
)
if
implements
is
None
:
if
hasattr
(
object
,
'__implements__'
):
implements
=
object
.
__implements__
else
:
return
r
if
isinstance
(
implements
,
Interface
):
r
.
append
(
i
)
else
:
_wi
(
implements
,
r
.
append
)
return
r
def
implementedByInstances
(
object
):
"""Return the interfaces that instanced implement (by default)
"""
r
=
[]
if
type
(
klass
)
is
ClassType
:
if
hasattr
(
klass
,
'__implements__'
):
implements
=
klass
.
__implements__
else
:
return
r
elif
hasattr
(
klass
,
'instancesImplements'
):
# Hook for ExtensionClass. :)
implements
=
klass
.
instancesImplements
()
else
:
implements
=
tiget
(
klass
,
None
)
if
implements
is
not
None
:
if
isinstance
(
implements
,
Interface
):
r
.
append
(
i
)
else
:
_wi
(
implements
,
r
.
append
)
return
r
def
_wi
(
interfaces
,
append
):
for
i
in
interfaces
:
if
isinstance
(
i
,
Interface
):
append
(
i
)
else
:
_wi
(
i
,
append
)
lib/python/Interface/__init__.py
0 → 100644
View file @
201f3133
from
Standard
import
Base
from
Util
import
impliedInterface
from
Util
import
assertTypeImplements
,
implementedBy
,
implementedByInstances
lib/python/Interface/iclass.py
0 → 100644
View file @
201f3133
"""Python Interfaces
Scarecrow version:
Classes or objects can implement an __implements__ attribute that
names a sequence of interface objects.
An interface is defined using the class statement and one or more base
interfaces.
"""
_typeImplements
=
{}
class
Interface
:
"""Prototype (scarecrow) Interfaces Implementation
"""
def
__init__
(
self
,
name
,
bases
=
(),
attrs
=
None
,
__doc__
=
None
):
"""Create a new interface
"""
for
b
in
bases
:
if
not
isinstance
(
b
,
Interface
):
raise
TypeError
,
'Expected base interfaces'
self
.
__bases__
=
bases
self
.
__name__
=
name
if
attrs
is
None
:
attrs
=
{}
if
attrs
.
has_key
(
'__doc__'
):
if
__doc__
is
None
:
__doc__
=
attrs
[
'__doc__'
]
del
attrs
[
'__doc__'
]
self
.
__attrs
=
attrs
if
__doc__
is
not
None
:
self
.
__doc__
=
__doc__
def
extends
(
self
,
other
):
"""Does an interface extend another?
"""
for
b
in
self
.
__bases__
:
if
b
is
other
:
return
1
if
b
.
extends
(
other
):
return
1
return
0
def
implementedBy
(
self
,
object
,
tiget
=
_typeImplements
.
get
):
"""Does the given object implement the interface?
"""
implements
=
tiget
(
type
(
object
),
None
)
if
implements
is
None
:
if
hasattr
(
object
,
'__implements__'
):
implements
=
object
.
__implements__
else
:
return
0
if
isinstance
(
implements
,
Interface
):
return
implements
is
self
or
implements
.
extends
(
self
)
else
:
return
self
.
__any
(
implements
)
def
implementedByInstancesOf
(
self
,
klass
,
tiget
=
_typeImplements
.
get
):
"""Do instances of the given class implement the interface?
"""
if
type
(
klass
)
is
ClassType
:
if
hasattr
(
klass
,
'__implements__'
):
implements
=
klass
.
__implements__
else
:
return
0
elif
hasattr
(
klass
,
'instancesImplements'
):
# Hook for ExtensionClass. :)
implements
=
klass
.
instancesImplements
()
else
:
implements
=
tiget
(
klass
,
None
)
if
implements
is
None
:
return
0
if
isinstance
(
implements
,
Interface
):
return
implements
is
self
or
implements
.
extends
(
self
)
else
:
return
self
.
__any
(
implements
)
def
names
(
self
):
"""Return the attribute names defined by the interface
"""
return
self
.
__attrs
.
keys
()
def
namesAndDescriptions
(
self
):
"""Return the attribute names and descriptions defined by the interface
"""
return
self
.
__attrs
.
items
()
def
getDescriptionFor
(
self
,
name
,
default
=
None
):
"""Return the attribute description for the given name
"""
return
self
.
__attrs
.
get
(
name
,
default
)
def
__any
(
self
,
interfaces
):
for
i
in
interfaces
:
if
isinstance
(
i
,
Interface
):
return
i
is
self
or
i
.
extends
(
self
)
else
:
return
self
.
__any
(
i
)
ClassType
=
type
(
Interface
)
Base
=
Interface
(
"Interface"
)
def
assertTypeImplements
(
type
,
interfaces
):
"""Return the interfaces implemented by objects of the given type
"""
_typeImplements
[
type
]
=
interfaces
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