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
17d8bdae
Commit
17d8bdae
authored
Mar 31, 2015
by
Tres Seaver
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pypy-py3k' of
git://github.com/NextThought/Acquisition
into NextThought-pypy-py3k
parents
8a77d12c
c4fa7e8e
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
450 additions
and
32 deletions
+450
-32
src/Acquisition/__init__.py
src/Acquisition/__init__.py
+47
-30
src/Acquisition/tests.py
src/Acquisition/tests.py
+403
-2
No files found.
src/Acquisition/__init__.py
View file @
17d8bdae
...
@@ -44,7 +44,7 @@ if sys.version_info < (3,):
...
@@ -44,7 +44,7 @@ if sys.version_info < (3,):
if
isinstance
(
method
,
types
.
MethodType
):
if
isinstance
(
method
,
types
.
MethodType
):
method
=
types
.
MethodType
(
method
.
im_func
,
wrapper
,
method
.
im_class
)
method
=
types
.
MethodType
(
method
.
im_func
,
wrapper
,
method
.
im_class
)
return
method
return
method
else
:
else
:
# pragma: no cover (python 2 is currently our reference)
def
_rebound_method
(
method
,
wrapper
):
def
_rebound_method
(
method
,
wrapper
):
"""Returns a version of the method with self bound to `wrapper`"""
"""Returns a version of the method with self bound to `wrapper`"""
if
isinstance
(
method
,
types
.
MethodType
):
if
isinstance
(
method
,
types
.
MethodType
):
...
@@ -166,9 +166,7 @@ def _Wrapper_acquire(wrapper, name,
...
@@ -166,9 +166,7 @@ def _Wrapper_acquire(wrapper, name,
if
result
is
not
Acquired
:
if
result
is
not
Acquired
:
if
predicate
:
if
predicate
:
if
_apply_filter
(
predicate
,
wrapper
.
_container
,
name
,
result
,
predicate_extra
,
orig_object
):
if
_apply_filter
(
predicate
,
wrapper
.
_container
,
name
,
result
,
predicate_extra
,
orig_object
):
if
_has__of__
(
result
):
return
result
.
__of__
(
wrapper
)
if
_has__of__
(
result
)
else
result
result
=
result
.
__of__
(
wrapper
)
return
result
else
:
else
:
raise
AttributeError
(
name
)
raise
AttributeError
(
name
)
else
:
else
:
...
@@ -176,7 +174,7 @@ def _Wrapper_acquire(wrapper, name,
...
@@ -176,7 +174,7 @@ def _Wrapper_acquire(wrapper, name,
result
=
result
.
__of__
(
wrapper
)
result
=
result
.
__of__
(
wrapper
)
return
result
return
result
raise
AttributeError
(
name
)
raise
AttributeError
(
name
)
# pragma: no cover (this line cannot be reached)
def
_Wrapper_findattr
(
wrapper
,
name
,
def
_Wrapper_findattr
(
wrapper
,
name
,
...
@@ -194,6 +192,7 @@ def _Wrapper_findattr(wrapper, name,
...
@@ -194,6 +192,7 @@ def _Wrapper_findattr(wrapper, name,
:param bool containment: Use the innermost wrapper (`aq_inner`) for looking up
:param bool containment: Use the innermost wrapper (`aq_inner`) for looking up
the attribute.
the attribute.
"""
"""
orig_name
=
name
orig_name
=
name
if
orig_object
is
None
:
if
orig_object
is
None
:
orig_object
=
wrapper
orig_object
=
wrapper
...
@@ -209,7 +208,10 @@ def _Wrapper_findattr(wrapper, name,
...
@@ -209,7 +208,10 @@ def _Wrapper_findattr(wrapper, name,
result
=
_Wrapper_findspecial
(
wrapper
,
name
)
result
=
_Wrapper_findspecial
(
wrapper
,
name
)
if
result
is
not
_NOT_FOUND
:
if
result
is
not
_NOT_FOUND
:
if
predicate
:
if
predicate
:
return
result
if
_apply_filter
(
predicate
,
wrapper
,
orig_name
,
result
,
predicate_extra
,
orig_object
)
else
None
if
_apply_filter
(
predicate
,
wrapper
,
orig_name
,
result
,
predicate_extra
,
orig_object
):
return
result
else
:
raise
AttributeError
(
orig_name
)
return
result
return
result
elif
name
in
(
'__reduce__'
,
'__reduce_ex__'
,
'__getstate__'
,
elif
name
in
(
'__reduce__'
,
'__reduce_ex__'
,
'__getstate__'
,
'__of__'
,
'__cmp__'
,
'__eq__'
,
'__ne__'
,
'__lt__'
,
'__of__'
,
'__cmp__'
,
'__eq__'
,
'__ne__'
,
'__lt__'
,
...
@@ -347,6 +349,8 @@ class _Wrapper(ExtensionClass.Base):
...
@@ -347,6 +349,8 @@ class _Wrapper(ExtensionClass.Base):
while
isinstance
(
wrapper
.
_obj
,
_Wrapper
)
\
while
isinstance
(
wrapper
.
_obj
,
_Wrapper
)
\
and
(
wrapper
.
_obj
.
_container
is
wrapper
.
_container
.
_obj
):
and
(
wrapper
.
_obj
.
_container
is
wrapper
.
_container
.
_obj
):
# Since we mutate the wrapper as we walk up, we must copy
# Since we mutate the wrapper as we walk up, we must copy
# XXX: This comes from the C implementation. Do we really need to
# copy?
wrapper
=
type
(
wrapper
)(
wrapper
.
_obj
,
wrapper
.
_container
)
wrapper
=
type
(
wrapper
)(
wrapper
.
_obj
,
wrapper
.
_container
)
wrapper
.
_obj
=
wrapper
.
_obj
.
_obj
wrapper
.
_obj
=
wrapper
.
_obj
.
_obj
return
wrapper
return
wrapper
...
@@ -410,7 +414,7 @@ class _Wrapper(ExtensionClass.Base):
...
@@ -410,7 +414,7 @@ class _Wrapper(ExtensionClass.Base):
def
__cmp__
(
self
,
other
):
def
__cmp__
(
self
,
other
):
aq_self
=
self
.
_obj
aq_self
=
self
.
_obj
if
hasattr
(
type
(
aq_self
),
'__cmp__'
):
if
hasattr
(
type
(
aq_self
),
'__cmp__'
):
return
_rebound_method
(
type
(
aq_self
)
,
self
)(
other
)
return
_rebound_method
(
aq_self
.
__cmp__
,
self
)(
other
)
my_base
=
aq_base
(
self
)
my_base
=
aq_base
(
self
)
other_base
=
aq_base
(
other
)
other_base
=
aq_base
(
other
)
...
@@ -462,11 +466,17 @@ class _Wrapper(ExtensionClass.Base):
...
@@ -462,11 +466,17 @@ class _Wrapper(ExtensionClass.Base):
def
__repr__
(
self
):
def
__repr__
(
self
):
aq_self
=
self
.
_obj
aq_self
=
self
.
_obj
return
type
(
aq_self
).
__repr__
(
aq_self
)
try
:
return
_rebound_method
(
aq_self
.
__repr__
,
self
)()
except
(
AttributeError
,
TypeError
):
return
repr
(
aq_self
)
def
__str__
(
self
):
def
__str__
(
self
):
aq_self
=
self
.
_obj
aq_self
=
self
.
_obj
return
type
(
aq_self
).
__str__
(
aq_self
)
try
:
return
_rebound_method
(
aq_self
.
__str__
,
self
)()
except
(
AttributeError
,
TypeError
):
# pragma: no cover (Hits under Py3)
return
str
(
aq_self
)
__binary_special_methods__
=
[
__binary_special_methods__
=
[
# general numeric
# general numeric
...
@@ -617,32 +627,37 @@ class _Wrapper(ExtensionClass.Base):
...
@@ -617,32 +627,37 @@ class _Wrapper(ExtensionClass.Base):
def
__setitem__
(
self
,
key
,
value
):
def
__setitem__
(
self
,
key
,
value
):
aq_self
=
self
.
_obj
aq_self
=
self
.
_obj
_rebound_method
(
getattr
(
type
(
aq_self
),
'__setitem__'
),
self
)(
key
,
value
)
try
:
setter
=
type
(
aq_self
).
__setitem__
except
AttributeError
:
raise
AttributeError
(
"__setitem__"
)
# doctests care about the name
else
:
setter
(
self
,
key
,
value
)
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
if
isinstance
(
key
,
slice
):
if
isinstance
(
key
,
slice
)
and
hasattr
(
operator
,
'getslice'
)
:
if
isinstance
(
self
.
_obj
,
(
list
,
tuple
)):
# Only on Python 2
return
self
.
_obj
[
key
]
# XXX: This is probably not proxying correctly, but the existing
start
,
stop
=
key
.
start
,
key
.
stop
# tests pass with this behaviour
if
start
is
None
:
return
operator
.
getslice
(
self
.
_obj
,
start
=
0
key
.
start
if
key
.
start
is
not
None
else
0
,
if
start
<
0
:
key
.
stop
if
key
.
stop
is
not
None
else
sys
.
maxint
)
start
+=
len
(
self
.
_obj
)
if
stop
is
None
:
aq_self
=
self
.
_obj
stop
=
getattr
(
sys
,
'maxint'
,
None
)
# PY2
try
:
elif
stop
<
0
:
getter
=
type
(
aq_self
).
__getitem__
stop
+=
len
(
self
.
_obj
)
except
AttributeError
:
if
hasattr
(
operator
,
'getslice'
):
# PY2
raise
AttributeError
(
"__getitem__"
)
# doctests care about the name
return
operator
.
getslice
(
self
.
_obj
,
start
,
stop
)
else
:
return
self
.
_obj
[
start
:
stop
]
return
getter
(
self
,
key
)
return
self
.
_obj
[
key
]
def
__call__
(
self
,
*
args
,
**
kwargs
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
try
:
try
:
# Note we look this up on the completely unwrapped
# Note we look this up on the completely unwrapped
# object, so as not to get a class
# object, so as not to get a class
call
=
getattr
(
self
.
aq_base
,
'__call__'
)
call
=
getattr
(
self
.
aq_base
,
'__call__'
)
except
AttributeError
:
except
AttributeError
:
# pragma: no cover
# A TypeError is what the interpreter raises;
# A TypeError is what the interpreter raises;
# AttributeError is allowed to percolate through the
# AttributeError is allowed to percolate through the
# C proxy
# C proxy
...
@@ -761,7 +776,7 @@ def aq_chain(obj, containment=False):
...
@@ -761,7 +776,7 @@ def aq_chain(obj, containment=False):
def
aq_base
(
obj
):
def
aq_base
(
obj
):
result
=
obj
result
=
obj
while
isinstance
(
result
,
_Wrapper
):
while
isinstance
(
result
,
_Wrapper
):
result
=
result
.
aq_self
result
=
result
.
_obj
return
result
return
result
...
@@ -813,7 +828,9 @@ def aq_inContextOf(self, o, inner=True):
...
@@ -813,7 +828,9 @@ def aq_inContextOf(self, o, inner=True):
if
inner
:
if
inner
:
self
=
aq_inner
(
next
)
self
=
aq_inner
(
next
)
if
self
is
None
:
if
self
is
None
:
# pragma: no cover
# This branch is normally impossible to hit,
# it just mirrors a check in C
break
break
else
:
else
:
self
=
next
self
=
next
...
@@ -825,7 +842,7 @@ def aq_inContextOf(self, o, inner=True):
...
@@ -825,7 +842,7 @@ def aq_inContextOf(self, o, inner=True):
return
0
return
0
if
'PURE_PYTHON'
not
in
os
.
environ
:
# pragma no cover
if
'PURE_PYTHON'
not
in
os
.
environ
:
# pragma
:
no cover
try
:
try
:
from
._Acquisition
import
*
from
._Acquisition
import
*
except
ImportError
:
except
ImportError
:
...
...
src/Acquisition/tests.py
View file @
17d8bdae
This diff is collapsed.
Click to expand it.
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