Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zope.proxy
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
Boxiang Sun
zope.proxy
Commits
9e244f27
Commit
9e244f27
authored
May 07, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getting methods as attributes.
parent
a1932756
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
src/zope/proxy/__init__.py
src/zope/proxy/__init__.py
+6
-2
src/zope/proxy/tests/test_proxy.py
src/zope/proxy/tests/test_proxy.py
+12
-0
No files found.
src/zope/proxy/__init__.py
View file @
9e244f27
...
...
@@ -117,6 +117,11 @@ class PyProxyBase(object):
# __class__ is special cased in the C implementation
return
wrapped
.
__class__
if
name
in
(
'__reduce__'
,
'__reduce_ex__'
):
# These things we specifically override and no one
# can stop us, not even a subclass
return
object
.
__getattribute__
(
self
,
name
)
# First, look for descriptors in this object's type
type_self
=
type
(
self
)
descriptor
=
_WrapperType_Lookup
(
type_self
,
name
)
...
...
@@ -124,7 +129,6 @@ class PyProxyBase(object):
# Nothing in the class, go straight to the wrapped object
return
getattr
(
wrapped
,
name
)
if
hasattr
(
descriptor
,
'__get__'
):
if
not
hasattr
(
descriptor
,
'__set__'
):
# Non-data-descriptor: call through to the wrapped object
...
...
@@ -132,7 +136,7 @@ class PyProxyBase(object):
try
:
return
getattr
(
wrapped
,
name
)
except
AttributeError
:
raise
pass
# Data-descriptor on this type. Call it
return
descriptor
.
__get__
(
self
,
type_self
)
return
descriptor
...
...
src/zope/proxy/tests/test_proxy.py
View file @
9e244f27
...
...
@@ -642,6 +642,18 @@ class PyProxyBaseTestCase(unittest.TestCase):
self
.
assertRaises
(
AttributeError
,
setattr
,
proxy
,
'attr'
,
42
)
self
.
assertEqual
(
proxy
.
attr
,
"constant value"
)
def
test_method_in_proxy_subclass
(
self
):
class
Proxy
(
self
.
_getTargetClass
()):
def
__getitem__
(
self
,
k
):
return
k
proxy
=
Proxy
(
object
())
# Both when called by the interpreter, which bypasses
# __getattribute__
self
.
assertEquals
(
proxy
[
42
],
42
)
# And when asked for as an attribute
self
.
assertNotEqual
(
getattr
(
proxy
,
'__getitem__'
),
self
)
def
test_string_to_int
(
self
):
# XXX Implementation difference: This works in the
# Pure-Python version, but fails in CPython.
...
...
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