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
e9c24932
Commit
e9c24932
authored
Nov 21, 2006
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow assignment to a wrapper's __parent__.
parent
f9a846a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
6 deletions
+42
-6
_Acquisition.c
_Acquisition.c
+2
-2
tests.py
tests.py
+40
-4
No files found.
_Acquisition.c
View file @
e9c24932
...
...
@@ -663,8 +663,8 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v)
/* Allow assignment to parent, to change context. */
if
(
PyString_Check
(
oname
))
name
=
PyString_AS_STRING
(
oname
);
if
(
*
name
==
'a'
&&
name
[
1
]
==
'q'
&&
name
[
2
]
==
'_'
&&
strcmp
(
name
+
3
,
"parent"
)
==
0
)
if
(
(
*
name
==
'a'
&&
name
[
1
]
==
'q'
&&
name
[
2
]
==
'_'
&&
strcmp
(
name
+
3
,
"parent"
)
==
0
)
||
(
strcmp
(
name
,
"__parent__"
)
==
0
)
)
{
Py_XINCREF
(
v
);
ASSIGN
(
self
->
container
,
v
);
...
...
tests.py
View file @
e9c24932
...
...
@@ -1713,9 +1713,9 @@ def test_implicit_wrapper_as___parent__():
The intermediate parent is an object that supports implicit
acquisition. We bind it to the root via the __of__ protocol:
>>> class Impl
Wrapper
(Acquisition.Implicit):
>>> class Impl(Acquisition.Implicit):
... foo = 42
>>> y = Impl
Wrapper
().__of__(z)
>>> y = Impl().__of__(z)
The child object is again a simple object with a simple __parent__
pointer:
...
...
@@ -1741,6 +1741,24 @@ def test_implicit_wrapper_as___parent__():
>>> y.__parent__ is z
True
Just as much as you can assign to aq_parent, you can also assign
to __parent__ to change the acquisition context of the wrapper:
>>> newroot = Root()
>>> y.__parent__ = newroot
>>> y.__parent__ is z
False
>>> y.__parent__ is newroot
True
Note that messing with the wrapper won't in any way affect the
wrapped object:
>>> Acquisition.aq_base(y).__parent__
Traceback (most recent call last):
...
AttributeError: __parent__
TODO aq_parent, aq_chain
"""
...
...
@@ -1755,9 +1773,9 @@ def test_explicit_wrapper_as___parent__():
The intermediate parent is an object that supports implicit
acquisition. We bind it to the root via the __of__ protocol:
>>> class Expl
Wrapper
(Acquisition.Explicit):
>>> class Expl(Acquisition.Explicit):
... foo = 42
>>> y = Expl
Wrapper
().__of__(z)
>>> y = Expl().__of__(z)
The child object is again a simple object with a simple __parent__
pointer:
...
...
@@ -1783,6 +1801,24 @@ def test_explicit_wrapper_as___parent__():
>>> y.__parent__ is z
True
Just as much as you can assign to aq_parent, you can also assign
to __parent__ to change the acquisition context of the wrapper:
>>> newroot = Root()
>>> y.__parent__ = newroot
>>> y.__parent__ is z
False
>>> y.__parent__ is newroot
True
Note that messing with the wrapper won't in any way affect the
wrapped object:
>>> Acquisition.aq_base(y).__parent__
Traceback (most recent call last):
...
AttributeError: __parent__
TODO aq_parent, aq_chain
"""
...
...
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