Merge r71222 from old branch:

  Allow assignment to a wrapper's __parent__.
parent 387924bb
...@@ -627,8 +627,8 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v) ...@@ -627,8 +627,8 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v)
/* Allow assignment to parent, to change context. */ /* Allow assignment to parent, to change context. */
if (PyString_Check(oname)) name=PyString_AS_STRING(oname); if (PyString_Check(oname)) name=PyString_AS_STRING(oname);
if (*name=='a' && name[1]=='q' && name[2]=='_' if ((*name=='a' && name[1]=='q' && name[2]=='_'
&& strcmp(name+3,"parent")==0) && strcmp(name+3,"parent")==0) || (strcmp(name, "__parent__")==0))
{ {
Py_XINCREF(v); Py_XINCREF(v);
ASSIGN(self->container, v); ASSIGN(self->container, v);
......
...@@ -1401,7 +1401,7 @@ def test_creating_wrappers_directly(): ...@@ -1401,7 +1401,7 @@ def test_creating_wrappers_directly():
... ...
TypeError: __init__() takes exactly 2 arguments (1 given) TypeError: __init__() takes exactly 2 arguments (1 given)
We can reassign aq_parent We can reassign aq_parent / __parent__ on a wrapper:
>>> x = B() >>> x = B()
>>> x.color = 'green' >>> x.color = 'green'
...@@ -1409,6 +1409,20 @@ def test_creating_wrappers_directly(): ...@@ -1409,6 +1409,20 @@ def test_creating_wrappers_directly():
>>> w.color >>> w.color
'green' 'green'
>>> y = B()
>>> y.color = 'blue'
>>> w.__parent__ = y
>>> w.color
'blue'
Note that messing with the wrapper won't in any way affect the
wrapped object:
>>> Acquisition.aq_base(w).__parent__
Traceback (most recent call last):
...
AttributeError: __parent__
>>> w = ImplicitAcquisitionWrapper() >>> w = ImplicitAcquisitionWrapper()
Traceback (most recent call last): Traceback (most recent call last):
... ...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment