Step 4: Make aq_get aware of __parent__ pointers.

(Also some comment cosmetics in _Acquisition.c)
parent 398463fa
...@@ -1391,9 +1391,8 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter, ...@@ -1391,9 +1391,8 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter,
explicit || explicit ||
WRAPPER(self)->ob_type==(PyTypeObject*)&Wrappertype, WRAPPER(self)->ob_type==(PyTypeObject*)&Wrappertype,
explicit, containment); explicit, containment);
/* Not wrapped; check if we have a __parent__ pointer. If that's /* Not wrapped; check if we have a __parent__ pointer. In that
the case, we create a wrapper and pretend it's business as case, create a wrapper and pretend it's business as usual */
usual */
else if ((result = PyObject_GetAttr(self, py__parent__))) else if ((result = PyObject_GetAttr(self, py__parent__)))
{ {
self = newWrapper(self, result, (PyTypeObject*)&Wrappertype); self = newWrapper(self, result, (PyTypeObject*)&Wrappertype);
...@@ -1408,8 +1407,8 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter, ...@@ -1408,8 +1407,8 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter,
/* No filter, and no __parent__, so just getattr */ /* No filter, and no __parent__, so just getattr */
else else
{ {
/* we need to clean up the AttributeError from the previous /* clean up the AttributeError from the previous getattr
getattr (because it has clearly failed) */ (because it has clearly failed) */
PyErr_Fetch(&result,&v,&tb); PyErr_Fetch(&result,&v,&tb);
if (result && (result != PyExc_AttributeError)) if (result && (result != PyExc_AttributeError))
{ {
...@@ -1457,13 +1456,35 @@ module_aq_acquire(PyObject *ignored, PyObject *args, PyObject *kw) ...@@ -1457,13 +1456,35 @@ module_aq_acquire(PyObject *ignored, PyObject *args, PyObject *kw)
static PyObject * static PyObject *
capi_aq_get(PyObject *self, PyObject *name, PyObject *defalt, int containment) capi_aq_get(PyObject *self, PyObject *name, PyObject *defalt, int containment)
{ {
PyObject *result = NULL; PyObject *result = NULL, *v, *tb;
/* We got a wrapped object, so business as usual */ /* We got a wrapped object, so business as usual */
if (isWrapper(self)) if (isWrapper(self))
result=Wrapper_findattr(WRAPPER(self), name, 0, 0, OBJECT(self), 1, 1, 1, result=Wrapper_findattr(WRAPPER(self), name, 0, 0, OBJECT(self), 1, 1, 1,
containment); containment);
/* Not wrapped; check if we have a __parent__ pointer. In that
case, create a wrapper and pretend it's business as usual */
else if ((result = PyObject_GetAttr(self, py__parent__)))
{
self=newWrapper(self, result, (PyTypeObject*)&Wrappertype);
Py_DECREF(result); /* don't need __parent__ anymore */
result=Wrapper_findattr(WRAPPER(self), name, 0, 0, OBJECT(self),
1, 1, 1, containment);
Py_DECREF(self); /* get rid of temp wrapper */
}
else else
result=PyObject_GetAttr(self, name); {
/* 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);
result=PyObject_GetAttr(self, name);
}
if (! result && defalt) if (! result && defalt)
{ {
......
...@@ -1688,7 +1688,8 @@ def test___parent__no_wrappers(): ...@@ -1688,7 +1688,8 @@ def test___parent__no_wrappers():
>>> z.foo = 43 # this should not be found >>> z.foo = 43 # this should not be found
>>> z.bar = 3.145 >>> 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') >>> Acquisition.aq_acquire(x, 'hello')
'world' 'world'
...@@ -1697,7 +1698,16 @@ def test___parent__no_wrappers(): ...@@ -1697,7 +1698,16 @@ def test___parent__no_wrappers():
>>> Acquisition.aq_acquire(x, 'bar') >>> Acquisition.aq_acquire(x, 'bar')
3.145 3.145
as does ``aq_parent``: as does ``aq_get``:
>>> Acquisition.aq_get(x, 'hello')
'world'
>>> Acquisition.aq_get(x, 'foo')
42
>>> Acquisition.aq_get(x, 'bar')
3.145
and ``aq_parent``:
>>> Acquisition.aq_parent(x) is y >>> Acquisition.aq_parent(x) is y
True True
...@@ -1741,7 +1751,16 @@ def test_implicit_wrapper_as___parent__(): ...@@ -1741,7 +1751,16 @@ def test_implicit_wrapper_as___parent__():
>>> Acquisition.aq_acquire(x, 'bar') >>> Acquisition.aq_acquire(x, 'bar')
3.145 3.145
as does ``aq_parent``: as does ``aq_get``:
>>> Acquisition.aq_get(x, 'hello')
'world'
>>> Acquisition.aq_get(x, 'foo')
42
>>> Acquisition.aq_get(x, 'bar')
3.145
and ``aq_parent``:
>>> Acquisition.aq_parent(x) is y >>> Acquisition.aq_parent(x) is y
True True
...@@ -1808,7 +1827,16 @@ def test_explicit_wrapper_as___parent__(): ...@@ -1808,7 +1827,16 @@ def test_explicit_wrapper_as___parent__():
>>> Acquisition.aq_acquire(x, 'bar') >>> Acquisition.aq_acquire(x, 'bar')
3.145 3.145
as does ``aq_parent``: as does ``aq_get``:
>>> Acquisition.aq_get(x, 'hello')
'world'
>>> Acquisition.aq_get(x, 'foo')
42
>>> Acquisition.aq_get(x, 'bar')
3.145
and ``aq_parent``:
>>> Acquisition.aq_parent(x) is y >>> Acquisition.aq_parent(x) is y
True True
...@@ -1869,7 +1897,16 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -1869,7 +1897,16 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
>>> Acquisition.aq_acquire(x, 'bar') >>> Acquisition.aq_acquire(x, 'bar')
3.145 3.145
as does ``aq_parent``: as does ``aq_get``:
>>> Acquisition.aq_get(x, 'hello')
'world'
>>> Acquisition.aq_get(x, 'foo')
42
>>> Acquisition.aq_get(x, 'bar')
3.145
and ``aq_parent``:
>>> Acquisition.aq_parent(x) == y >>> Acquisition.aq_parent(x) == y
True True
...@@ -1915,7 +1952,16 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -1915,7 +1952,16 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
>>> Acquisition.aq_acquire(x, 'bar') >>> Acquisition.aq_acquire(x, 'bar')
3.145 3.145
as does ``aq_parent``: as does ``aq_get``:
>>> Acquisition.aq_get(x, 'hello')
'world'
>>> Acquisition.aq_get(x, 'foo')
42
>>> Acquisition.aq_get(x, 'bar')
3.145
and ``aq_parent``:
>>> Acquisition.aq_parent(x) == y >>> Acquisition.aq_parent(x) == y
True True
......
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