[Zope-Checkins] CVS: Zope2 - Acquisition.c:1.46.2.1

Brian Lloyd brian@digiciool.com
Mon, 12 Mar 2001 14:32:19 -0500 (EST)


Update of /cvs-repository/Zope2/lib/Components/ExtensionClass
In directory korak:/home/brian/temp/zope-23-branch/lib/Components/ExtensionClass

Modified Files:
      Tag: zope-2_3-branch
	Acquisition.c 
Log Message:
Ugh - move copy of fixed Acquisition.c



--- Updated File Acquisition.c in package Zope2 --
--- Acquisition.c	2001/01/16 15:39:41	1.46
+++ Acquisition.c	2001/03/12 19:32:18	1.46.2.1
@@ -1050,38 +1050,40 @@
 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;
+  if (inner) {
+    /* o = aq_base(o) */
+    while (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj;
+
+    /* while 1: */
+    while (1) {
+
+      /*   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;
     }
-
-  /* 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 (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj;
-
-  c = OBJECT(self);
-  while (1)
-    {
-      bc=c;
-      while (isWrapper(bc) && WRAPPER(bc)->obj) bc=WRAPPER(bc)->obj;
-      if (bc==o) return PyInt_FromLong(1);
+  }
+  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);
 }