Merged from old philikon-aq-and-__parent__ branch:

Log message for revision 71224:
  Step 3: Make aq_parent aware of __parent__ pointers.
parent 50768a62
......@@ -1555,13 +1555,34 @@ module_aq_base(PyObject *ignored, PyObject *args)
static PyObject *
capi_aq_parent(PyObject *self)
{
PyObject *result=Py_None;
PyObject *result, *v, *tb;
if (isWrapper(self) && WRAPPER(self)->container)
result=WRAPPER(self)->container;
{
result=WRAPPER(self)->container;
Py_INCREF(result);
return result;
}
else if ((result=PyObject_GetAttr(self, py__parent__)))
/* We already own the reference to result (PyObject_GetAttr gives
it to us), no need to INCREF here */
return result;
else
{
/* We need to clean up the AttributeError from the previous
getattr (because it has clearly failed) */
PyErr_Fetch(&result,&v,&tb);
if (result && (result != PyExc_AttributeError))
{
PyErr_Restore(result,v,tb);
return NULL;
}
Py_XDECREF(result); Py_XDECREF(v); Py_XDECREF(tb);
Py_INCREF(result);
return result;
result=Py_None;
Py_INCREF(result);
return result;
}
}
static PyObject *
......
......@@ -1715,7 +1715,8 @@ def test___parent__no_wrappers():
>>> z.foo = 43 # this should not be found
>>> z.bar = 3.145
``aq_acquire`` works we know it from implicit/acquisition wrappers:
``aq_acquire`` works as we know it from implicit/acquisition
wrappers:
>>> Acquisition.aq_acquire(x, 'hello')
'world'
......@@ -1724,7 +1725,14 @@ def test___parent__no_wrappers():
>>> Acquisition.aq_acquire(x, 'bar')
3.145
TODO aq_parent, aq_chain
as does ``aq_parent``:
>>> Acquisition.aq_parent(x) is y
True
>>> Acquisition.aq_parent(y) is z
True
TODO aq_chain
"""
def test_implicit_wrapper_as___parent__():
......@@ -1761,6 +1769,13 @@ def test_implicit_wrapper_as___parent__():
>>> Acquisition.aq_acquire(x, 'bar')
3.145
as does ``aq_parent``:
>>> Acquisition.aq_parent(x) is y
True
>>> Acquisition.aq_parent(y) is z
True
Note that also the (implicit) acquisition wrapper has a __parent__
pointer, which is automatically computed from the acquisition
container (it's identical to aq_parent):
......@@ -1786,7 +1801,7 @@ def test_implicit_wrapper_as___parent__():
...
AttributeError: __parent__
TODO aq_parent, aq_chain
TODO aq_chain
"""
def test_explicit_wrapper_as___parent__():
......@@ -1821,6 +1836,13 @@ def test_explicit_wrapper_as___parent__():
>>> Acquisition.aq_acquire(x, 'bar')
3.145
as does ``aq_parent``:
>>> Acquisition.aq_parent(x) is y
True
>>> Acquisition.aq_parent(y) is z
True
Note that also the (explicit) acquisition wrapper has a __parent__
pointer, which is automatically computed from the acquisition
container (it's identical to aq_parent):
......@@ -1846,7 +1868,7 @@ def test_explicit_wrapper_as___parent__():
...
AttributeError: __parent__
TODO aq_parent, aq_chain
TODO aq_chain
"""
def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
......@@ -1875,6 +1897,13 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
>>> Acquisition.aq_acquire(x, 'bar')
3.145
as does ``aq_parent``:
>>> Acquisition.aq_parent(x) == y
True
>>> Acquisition.aq_parent(y) is z
True
Because the outmost object, ``x``, is wrapped in an implicit
acquisition wrapper, we can also use direct attribute access:
......@@ -1905,7 +1934,7 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
... hello = 'world'
>>> x = Expl().__of__(y)
Again, acquiring objects work as usual:
Again, acquiring objects works as usual:
>>> Acquisition.aq_acquire(x, 'hello')
'world'
......@@ -1914,7 +1943,7 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
>>> Acquisition.aq_acquire(x, 'bar')
3.145
TODO aq_parent, aq_chain
TODO aq_chain
"""
def test___parent__aq_parent_circles():
......
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