Commit c5ba0b5e authored by Shane Hathaway's avatar Shane Hathaway

Fixed aq_inContextOf().

parent dbefa2df
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. DAMAGE.
$Id: Acquisition.c,v 1.47 2001/02/19 19:16:07 jeremy Exp $ $Id: Acquisition.c,v 1.48 2001/03/12 16:36:46 shane Exp $
If you have questions regarding this software, If you have questions regarding this software,
contact: contact:
...@@ -1050,38 +1050,40 @@ Wrapper_acquire_method(Wrapper *self, PyObject *args, PyObject *kw) ...@@ -1050,38 +1050,40 @@ Wrapper_acquire_method(Wrapper *self, PyObject *args, PyObject *kw)
static PyObject * static PyObject *
Wrapper_inContextOf(Wrapper *self, PyObject *args) Wrapper_inContextOf(Wrapper *self, PyObject *args)
{ {
PyObject *o, *c, *bc; PyObject *o, *c;
int inner=0; int inner=1;
UNLESS(PyArg_ParseTuple(args,"O|i",&o,&inner)) return NULL; UNLESS(PyArg_ParseTuple(args,"O|i",&o,&inner)) return NULL;
if (inner) if (inner) {
while (self->obj && isWrapper(self->obj)) /* o = aq_base(o) */
self=WRAPPER(self->obj); while (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj;
c = OBJECT(self);
while (1)
{
if (c==o) return PyInt_FromLong(1);
if (c && isWrapper(c)) c=WRAPPER(c)->container;
else break;
}
/* Now try harder: Compare each object in the containment chain that /* while 1: */
starts at self, with the object of the wrapper passed in to this while (1) {
method. If a match is found, return 1. Thanks to Toby Dickenson.*/
while (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj; /* if aq_base(self) is o: return 1 */
c = self->obj;
while (isWrapper(c) && WRAPPER(c)->obj) c = WRAPPER(c)->obj;
if (c == o) return PyInt_FromLong(1);
/* self = aq_parent(aq_inner(self)) */
/* if self is None: break */
while (self->obj && isWrapper(self->obj)) self = WRAPPER(self->obj);
if (self->container && isWrapper(self->container))
self = WRAPPER(self->container);
else break;
}
}
else {
/* Follow wrappers instead. */
c = OBJECT(self); c = OBJECT(self);
while (1) while (1) {
{ if (c==o) return PyInt_FromLong(1);
bc=c;
while (isWrapper(bc) && WRAPPER(bc)->obj) bc=WRAPPER(bc)->obj;
if (bc==o) return PyInt_FromLong(1);
if (c && isWrapper(c)) c=WRAPPER(c)->container; if (c && isWrapper(c)) c=WRAPPER(c)->container;
else break; else break;
} }
}
return PyInt_FromLong(0); return PyInt_FromLong(0);
} }
...@@ -1425,7 +1427,7 @@ void ...@@ -1425,7 +1427,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.47 $"; char *rev="$Revision: 1.48 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -1444,7 +1446,7 @@ initAcquisition() ...@@ -1444,7 +1446,7 @@ initAcquisition()
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.47 2001/02/19 19:16:07 jeremy Exp $\n", "$Id: Acquisition.c,v 1.48 2001/03/12 16:36:46 shane Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
......
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