Step 5: Make aq_chain aware of __parent__ pointers.

parent 69758b07
...@@ -1650,7 +1650,7 @@ module_aq_inner(PyObject *ignored, PyObject *args) ...@@ -1650,7 +1650,7 @@ module_aq_inner(PyObject *ignored, PyObject *args)
static PyObject * static PyObject *
capi_aq_chain(PyObject *self, int containment) capi_aq_chain(PyObject *self, int containment)
{ {
PyObject *result; PyObject *result, *v, *tb;
UNLESS (result=PyList_New(0)) return NULL; UNLESS (result=PyList_New(0)) return NULL;
...@@ -1673,8 +1673,27 @@ capi_aq_chain(PyObject *self, int containment) ...@@ -1673,8 +1673,27 @@ capi_aq_chain(PyObject *self, int containment)
} }
} }
else else
if (PyList_Append(result, self) < 0) {
goto err; if (PyList_Append(result, self) < 0)
goto err;
if ((self=PyObject_GetAttr(self, py__parent__)))
{
Py_DECREF(self); /* don't need our own reference */
if (self!=Py_None)
continue;
}
else
{
PyErr_Fetch(&self,&v,&tb);
if (self && (self != PyExc_AttributeError))
{
PyErr_Restore(self,v,tb);
return NULL;
}
Py_XDECREF(self); Py_XDECREF(v); Py_XDECREF(tb);
}
}
break; break;
} }
......
...@@ -1714,7 +1714,10 @@ def test___parent__no_wrappers(): ...@@ -1714,7 +1714,10 @@ def test___parent__no_wrappers():
>>> Acquisition.aq_parent(y) is z >>> Acquisition.aq_parent(y) is z
True True
TODO aq_chain as well as ``aq_chain``:
>>> Acquisition.aq_chain(x) == [x, y, z]
True
""" """
def test_implicit_wrapper_as___parent__(): def test_implicit_wrapper_as___parent__():
...@@ -1767,6 +1770,11 @@ def test_implicit_wrapper_as___parent__(): ...@@ -1767,6 +1770,11 @@ def test_implicit_wrapper_as___parent__():
>>> Acquisition.aq_parent(y) is z >>> Acquisition.aq_parent(y) is z
True True
as well as ``aq_chain``:
>>> Acquisition.aq_chain(x) == [x, y, z]
True
Note that also the (implicit) acquisition wrapper has a __parent__ Note that also the (implicit) acquisition wrapper has a __parent__
pointer, which is automatically computed from the acquisition pointer, which is automatically computed from the acquisition
container (it's identical to aq_parent): container (it's identical to aq_parent):
...@@ -1791,8 +1799,6 @@ def test_implicit_wrapper_as___parent__(): ...@@ -1791,8 +1799,6 @@ def test_implicit_wrapper_as___parent__():
Traceback (most recent call last): Traceback (most recent call last):
... ...
AttributeError: __parent__ AttributeError: __parent__
TODO aq_chain
""" """
def test_explicit_wrapper_as___parent__(): def test_explicit_wrapper_as___parent__():
...@@ -1843,6 +1849,11 @@ def test_explicit_wrapper_as___parent__(): ...@@ -1843,6 +1849,11 @@ def test_explicit_wrapper_as___parent__():
>>> Acquisition.aq_parent(y) is z >>> Acquisition.aq_parent(y) is z
True True
as well as ``aq_chain``:
>>> Acquisition.aq_chain(x) == [x, y, z]
True
Note that also the (explicit) acquisition wrapper has a __parent__ Note that also the (explicit) acquisition wrapper has a __parent__
pointer, which is automatically computed from the acquisition pointer, which is automatically computed from the acquisition
container (it's identical to aq_parent): container (it's identical to aq_parent):
...@@ -1867,8 +1878,6 @@ def test_explicit_wrapper_as___parent__(): ...@@ -1867,8 +1878,6 @@ def test_explicit_wrapper_as___parent__():
Traceback (most recent call last): Traceback (most recent call last):
... ...
AttributeError: __parent__ AttributeError: __parent__
TODO aq_chain
""" """
def test_implicit_wrapper_has_nonwrapper_as_aq_parent(): def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
...@@ -1917,6 +1926,13 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -1917,6 +1926,13 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
>>> Acquisition.aq_parent(y) is z >>> Acquisition.aq_parent(y) is z
True True
as well as ``aq_chain``:
>>> Acquisition.aq_chain(x) == [x, y, z]
True
>>> x.aq_chain == [x, y, z]
True
Because the outmost object, ``x``, is wrapped in an implicit Because the outmost object, ``x``, is wrapped in an implicit
acquisition wrapper, we can also use direct attribute access: acquisition wrapper, we can also use direct attribute access:
...@@ -1926,8 +1942,6 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -1926,8 +1942,6 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
42 42
>>> x.bar >>> x.bar
3.145 3.145
TODO aq_chain
""" """
def test_explicit_wrapper_has_nonwrapper_as_aq_parent(): def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
...@@ -1976,7 +1990,12 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -1976,7 +1990,12 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
>>> Acquisition.aq_parent(y) is z >>> Acquisition.aq_parent(y) is z
True True
TODO aq_chain as well as ``aq_chain``:
>>> Acquisition.aq_chain(x) == [x, y, z]
True
>>> x.aq_chain == [x, y, z]
True
""" """
import unittest import unittest
......
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