Skip to content

Commit

Permalink
Factor actual implementation of Wrapper_inContextOf out to a reusable
Browse files Browse the repository at this point in the history
function so that we can write a module-level function for that functionality
as well.
  • Loading branch information
philikon committed Jul 28, 2007
1 parent da7cab2 commit add9eb0
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions _Acquisition.c
Expand Up @@ -1190,49 +1190,45 @@ Wrapper_acquire_method(Wrapper *self, PyObject *args, PyObject *kw)
# endif
}


static PyObject *
Wrapper_inContextOf(Wrapper *self, PyObject *args)
capi_aq_inContextOf(PyObject *self, PyObject *o, int inner)
{
PyObject *subob, *o, *c;
int inner=1;

UNLESS(PyArg_ParseTuple(args,"O|i",&o,&inner)) return NULL;
PyObject *next, *c;

if (inner) {
/* subob = self */
subob = OBJECT(self);

/* o = aq_base(o) */
while (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj;
/* next = self
o = aq_base(o) */
next = self;
while (isWrapper(o) && WRAPPER(o)->obj)
o=WRAPPER(o)->obj;

/* while 1: */
while (1) {

/* if aq_base(subob) is o: return 1 */
c = subob;
/* if aq_base(next) is o: return 1 */
c = next;
while (isWrapper(c) && WRAPPER(c)->obj) c = WRAPPER(c)->obj;
if (c == o) return PyInt_FromLong(1);

/* self = aq_inner(subob) */
/* self = aq_inner(next) */
/* if self is None: break */
if (isWrapper(subob)) {
self = WRAPPER(subob);
while (self->obj && isWrapper(self->obj))
self = WRAPPER(self->obj);
if (isWrapper(next)) {
self = next;
while (WRAPPER(self)->obj && isWrapper(WRAPPER(self)->obj))
self = WRAPPER(self)->obj;
}
else break;

/* subob = aq_parent(self) */
/* if subob is None: break */
if (self->container)
subob = self->container;
/* next = aq_parent(self) */
/* if next is None: break */
if (WRAPPER(self)->container)
next = WRAPPER(self)->container;
else break;
}
}
else {
/* Follow wrappers instead. */
c = OBJECT(self);
c = (PyObject*)self;
while (1) {
if (c==o) return PyInt_FromLong(1);
if (c && isWrapper(c)) c=WRAPPER(c)->container;
Expand All @@ -1243,6 +1239,18 @@ Wrapper_inContextOf(Wrapper *self, PyObject *args)
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 *
Wrappers_are_not_picklable(PyObject *wrapper, PyObject *args)
{
Expand Down

0 comments on commit add9eb0

Please sign in to comment.