Commit c5ba0b5e authored by Shane Hathaway's avatar Shane Hathaway

Fixed aq_inContextOf().

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