Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Acquisition
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
Acquisition
Commits
91c8b797
Commit
91c8b797
authored
Mar 20, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore python 2.6 and 3.4 compatibility.
parent
0fadb843
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
src/Acquisition/__init__.py
src/Acquisition/__init__.py
+16
-5
src/Acquisition/tests.py
src/Acquisition/tests.py
+14
-7
No files found.
src/Acquisition/__init__.py
View file @
91c8b797
...
...
@@ -450,10 +450,10 @@ class _Wrapper(ExtensionClass.Base):
# a len?
nonzero
=
getattr
(
type_aq_self
,
'__len__'
,
None
)
if
nonzero
:
return
_rebound_method
(
nonzero
,
self
)()
return
bool
(
nonzero
(
self
))
# Py3 is strict about the return type
# If nothing was defined, then it's true
return
True
__bool__
=
__nonzero__
def
__unicode__
(
self
):
f
=
getattr
(
self
.
aq_self
,
'__unicode__'
,
...
...
@@ -541,9 +541,9 @@ class _Wrapper(ExtensionClass.Base):
'__oct__'
,
'__hex__'
,
'__index__'
,
'__len__'
,
#
'__len__',
# strings
# strings
are special
#'__repr__',
#'__str__',
]
...
...
@@ -569,6 +569,17 @@ class _Wrapper(ExtensionClass.Base):
# Container protocol
def
__len__
(
self
):
# if len is missing, it should raise TypeError
# (AttributeError is acceptable under Py2, but Py3
# breaks list conversion if AttributeError is raised)
try
:
l
=
getattr
(
type
(
self
.
_obj
),
'__len__'
)
except
AttributeError
:
raise
TypeError
(
'object has no len()'
)
else
:
return
l
(
self
)
def
__iter__
(
self
):
# For things that provide either __iter__ or just __getitem__,
# we need to be sure that the wrapper is provided as self
...
...
@@ -598,7 +609,7 @@ class _Wrapper(ExtensionClass.Base):
aq_self
=
self
.
_obj
aq_contains
=
getattr
(
type
(
aq_self
),
'__contains__'
,
None
)
if
aq_contains
:
return
_rebound_method
(
aq_contains
,
self
)(
item
)
return
aq_contains
(
self
,
item
)
# Next, we should attempt to iterate like the interpreter; but the C code doesn't
# do this, so we don't either.
#return item in iter(self)
...
...
src/Acquisition/tests.py
View file @
91c8b797
...
...
@@ -348,6 +348,7 @@ if sys.version_info >= (3,):
except
AttributeError
as
e
:
return
type
(
self
).
__str__
(
self
)
long
=
int
else
:
PY2
=
True
PY3
=
False
...
...
@@ -2760,21 +2761,25 @@ class TestProxying(unittest.TestCase):
def
unary_acquired_func
(
self
):
return
self
.
value
acquire_meths
=
{
k
:
binary_acquired_func
for
k
in
self
.
__binary_numeric_methods__
}
acquire_meths
=
{}
for
k
in
self
.
__binary_numeric_methods__
:
acquire_meths
[
k
]
=
binary_acquired_func
for
k
in
self
.
__unary_special_methods__
:
acquire_meths
[
k
]
=
unary_acquired_func
acquire_meths
.
update
(
{
k
:
unary_acquired_func
for
k
in
self
.
__unary_special_methods__
}
)
def
make_converter
(
f
):
def
converter
(
self
,
*
args
):
return
f
(
self
.
value
)
return
converter
acquire_meths
.
update
(
{
k
:
make_converter
(
convert
)
for
k
,
convert
in
self
.
__unary_conversion_methods__
.
items
()})
for
k
,
convert
in
self
.
__unary_conversion_methods__
.
items
():
acquire_meths
[
k
]
=
make_converter
(
convert
)
acquire_meths
[
'__len__'
]
=
lambda
self
:
self
.
value
if
PY3
:
# Under Python 3, oct() and hex() call __index__ directly
acquire_meths
[
'__index__'
]
=
acquire_meths
[
'__int__'
]
if
base_class
==
Acquisition
.
Explicit
:
acquire_meths
[
'value'
]
=
Acquisition
.
Acquired
AcquireValue
=
type
(
'AcquireValue'
,
(
base_class
,),
acquire_meths
)
...
...
@@ -2827,6 +2832,7 @@ class TestProxying(unittest.TestCase):
continue
self
.
assertEqual
(
converter
(
base
.
value
),
getattr
(
base
.
derived
,
meth
)())
self
.
assertEqual
(
converter
(
base
.
value
),
converter
(
base
.
derived
))
...
...
@@ -2992,6 +2998,7 @@ class TestProxying(unittest.TestCase):
def
__nonzero__
(
self
):
return
bool
(
self
.
value
)
__bool__
=
__nonzero__
class
WithLen
(
base_class
):
if
base_class
is
Acquisition
.
Explicit
:
...
...
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