[Checkins] SVN: Zope/branches/philikon-aq/lib/python/Acquisition/ Add a module-level aq_inContextOf function, along the lines of the

Philipp von Weitershausen philikon at philikon.de
Fri Jul 27 21:20:43 EDT 2007


Log message for revision 78408:
  Add a module-level aq_inContextOf function, along the lines of the
  module-level aq_acquire, aq_inner, aq_parent, etc. functions.
  

Changed:
  U   Zope/branches/philikon-aq/lib/python/Acquisition/_Acquisition.c
  U   Zope/branches/philikon-aq/lib/python/Acquisition/tests.py

-=-
Modified: Zope/branches/philikon-aq/lib/python/Acquisition/_Acquisition.c
===================================================================
--- Zope/branches/philikon-aq/lib/python/Acquisition/_Acquisition.c	2007-07-28 01:09:30 UTC (rev 78407)
+++ Zope/branches/philikon-aq/lib/python/Acquisition/_Acquisition.c	2007-07-28 01:20:42 UTC (rev 78408)
@@ -1239,7 +1239,6 @@
   return PyInt_FromLong(0);
 }
 
-
 static PyObject *
 Wrapper_inContextOf(Wrapper *self, PyObject *args)
 {
@@ -1753,6 +1752,18 @@
   return capi_aq_chain(self, containment);
 }
 
+static PyObject *
+module_aq_inContextOf(PyObject *ignored, PyObject *args)
+{
+  PyObject *self, *o;
+  int inner=1;
+
+  UNLESS (PyArg_ParseTuple(args, "OO|i", &self, &o, &inner))
+    return NULL;
+
+  return capi_aq_inContextOf(self, o, inner);
+}
+
 static struct PyMethodDef methods[] = {
   {"aq_acquire", (PyCFunction)module_aq_acquire, METH_VARARGS|METH_KEYWORDS, 
    "aq_acquire(ob, name [, filter, extra, explicit]) -- "
@@ -1770,10 +1781,13 @@
    "aq_self(ob) -- Get the object with the outermost wrapper removed"},
   {"aq_inner", (PyCFunction)module_aq_inner, METH_VARARGS, 
    "aq_inner(ob) -- "
-   "Get the object with alll but the innermost wrapper removed"},
+   "Get the object with all but the innermost wrapper removed"},
   {"aq_chain", (PyCFunction)module_aq_chain, METH_VARARGS, 
    "aq_chain(ob [, containment]) -- "
    "Get a list of objects in the acquisition environment"},
+  {"aq_inContextOf", (PyCFunction)module_aq_inContextOf, METH_VARARGS,
+   "aq_inContextOf(base, ob [, inner]) -- "
+   "Determine whether the object is in the acquisition context of base."},
   {NULL,	NULL}
 };
 

Modified: Zope/branches/philikon-aq/lib/python/Acquisition/tests.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Acquisition/tests.py	2007-07-28 01:09:30 UTC (rev 78407)
+++ Zope/branches/philikon-aq/lib/python/Acquisition/tests.py	2007-07-28 01:20:42 UTC (rev 78408)
@@ -457,7 +457,14 @@
     >>> a.b.c.aq_inContextOf(a.b.c)
     1
 
+    >>> Acquisition.aq_inContextOf(a.b.c, a)
+    1
+    >>> Acquisition.aq_inContextOf(a.b.c, a.b)
+    1
+    >>> Acquisition.aq_inContextOf(a.b.c, a.b.c)
+    1
 
+
     >>> a.b.c.aq_acquire('y')
     42
 
@@ -1275,6 +1282,13 @@
     1
     >>> not checkContext(b.c, b.a)
     1
+
+    Acquisition.aq_inContextOf works the same way:
+
+    >>> Acquisition.aq_inContextOf(b.c, b)
+    1
+    >>> not Acquisition.aq_inContextOf(b.c, b.a)
+    1
     
     >>> b.a.aq_inContextOf(b)
     1



More information about the Checkins mailing list