Skip to content

Commit

Permalink
Merged from old philikon-aq-and-__parent__ branch:
Browse files Browse the repository at this point in the history
Log message for revision 71224:
  Step 3: Make aq_parent aware of __parent__ pointers.
  • Loading branch information
philikon committed Jul 24, 2007
1 parent 23e8cd6 commit 755cb12
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
29 changes: 25 additions & 4 deletions _Acquisition.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
41 changes: 35 additions & 6 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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__():
Expand Down Expand Up @@ -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):
Expand All @@ -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__():
Expand Down Expand Up @@ -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):
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand All @@ -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():
Expand Down

0 comments on commit 755cb12

Please sign in to comment.