Factor actual implementation of Wrapper_inContextOf out to a reusable

function so that we can write a module-level function for that functionality
as well.
parent a0f6eee8
...@@ -1190,49 +1190,45 @@ Wrapper_acquire_method(Wrapper *self, PyObject *args, PyObject *kw) ...@@ -1190,49 +1190,45 @@ Wrapper_acquire_method(Wrapper *self, PyObject *args, PyObject *kw)
# endif # endif
} }
static PyObject * static PyObject *
Wrapper_inContextOf(Wrapper *self, PyObject *args) capi_aq_inContextOf(PyObject *self, PyObject *o, int inner)
{ {
PyObject *subob, *o, *c; PyObject *next, *c;
int inner=1;
UNLESS(PyArg_ParseTuple(args,"O|i",&o,&inner)) return NULL;
if (inner) { if (inner) {
/* subob = self */ /* next = self
subob = OBJECT(self); o = aq_base(o) */
next = self;
/* o = aq_base(o) */ while (isWrapper(o) && WRAPPER(o)->obj)
while (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj; o=WRAPPER(o)->obj;
/* while 1: */ /* while 1: */
while (1) { while (1) {
/* if aq_base(subob) is o: return 1 */ /* if aq_base(next) is o: return 1 */
c = subob; c = next;
while (isWrapper(c) && WRAPPER(c)->obj) c = WRAPPER(c)->obj; while (isWrapper(c) && WRAPPER(c)->obj) c = WRAPPER(c)->obj;
if (c == o) return PyInt_FromLong(1); if (c == o) return PyInt_FromLong(1);
/* self = aq_inner(subob) */ /* self = aq_inner(next) */
/* if self is None: break */ /* if self is None: break */
if (isWrapper(subob)) { if (isWrapper(next)) {
self = WRAPPER(subob); self = next;
while (self->obj && isWrapper(self->obj)) while (WRAPPER(self)->obj && isWrapper(WRAPPER(self)->obj))
self = WRAPPER(self->obj); self = WRAPPER(self)->obj;
} }
else break; else break;
/* subob = aq_parent(self) */ /* next = aq_parent(self) */
/* if subob is None: break */ /* if next is None: break */
if (self->container) if (WRAPPER(self)->container)
subob = self->container; next = WRAPPER(self)->container;
else break; else break;
} }
} }
else { else {
/* Follow wrappers instead. */ /* Follow wrappers instead. */
c = OBJECT(self); c = (PyObject*)self;
while (1) { while (1) {
if (c==o) return PyInt_FromLong(1); if (c==o) return PyInt_FromLong(1);
if (c && isWrapper(c)) c=WRAPPER(c)->container; if (c && isWrapper(c)) c=WRAPPER(c)->container;
...@@ -1243,6 +1239,18 @@ Wrapper_inContextOf(Wrapper *self, PyObject *args) ...@@ -1243,6 +1239,18 @@ Wrapper_inContextOf(Wrapper *self, PyObject *args)
return PyInt_FromLong(0); return PyInt_FromLong(0);
} }
static PyObject *
Wrapper_inContextOf(Wrapper *self, PyObject *args)
{
PyObject *o;
int inner=1;
UNLESS(PyArg_ParseTuple(args,"O|i",&o,&inner)) return NULL;
return capi_aq_inContextOf((PyObject*)self, o, inner);
}
PyObject * PyObject *
Wrappers_are_not_picklable(PyObject *wrapper, PyObject *args) Wrappers_are_not_picklable(PyObject *wrapper, PyObject *args)
{ {
......
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