[Checkins] SVN: Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/ Step 5: Make aq_chain aware of __parent__ pointers.

Philipp von Weitershausen philikon at philikon.de
Mon Nov 20 19:30:10 EST 2006


Log message for revision 71229:
  Step 5: Make aq_chain aware of __parent__ pointers.
  

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

-=-

Property changes on: Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition
___________________________________________________________________
Name: svk:merge
   - bfa16f6a-5b7b-4684-983a-15b8a78f95a3:/local/Acquisition:3250
   + bfa16f6a-5b7b-4684-983a-15b8a78f95a3:/local/Acquisition:3251

Modified: Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/_Acquisition.c
===================================================================
--- Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/_Acquisition.c	2006-11-21 00:29:58 UTC (rev 71228)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/_Acquisition.c	2006-11-21 00:30:09 UTC (rev 71229)
@@ -1650,7 +1650,7 @@
 static PyObject *
 capi_aq_chain(PyObject *self, int containment)
 {
-  PyObject *result;
+  PyObject *result, *v, *tb;
 
   UNLESS (result=PyList_New(0)) return NULL;
 
@@ -1673,9 +1673,28 @@
             }
         }
       else
-        if (PyList_Append(result, self) < 0)
-          goto err;
+        {
+          if (PyList_Append(result, self) < 0)
+            goto err;
 
+          if ((self=PyObject_GetAttr(self, py__parent__)))
+            {
+              Py_DECREF(self); /* don't need our own reference */
+              if (self!=Py_None)
+                continue;
+            }
+          else
+            {
+              PyErr_Fetch(&self,&v,&tb);
+              if (self && (self != PyExc_AttributeError))
+                {
+                  PyErr_Restore(self,v,tb);
+                  return NULL;
+                }
+              Py_XDECREF(self); Py_XDECREF(v); Py_XDECREF(tb);
+            }
+        }
+
       break;
     }
   

Modified: Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/tests.py
===================================================================
--- Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/tests.py	2006-11-21 00:29:58 UTC (rev 71228)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/tests.py	2006-11-21 00:30:09 UTC (rev 71229)
@@ -1714,7 +1714,10 @@
       >>> Acquisition.aq_parent(y) is z
       True
 
-    TODO aq_chain
+    as well as ``aq_chain``:
+
+      >>> Acquisition.aq_chain(x) == [x, y, z]
+      True
     """
 
 def test_implicit_wrapper_as___parent__():
@@ -1767,6 +1770,11 @@
       >>> Acquisition.aq_parent(y) is z
       True
 
+    as well as ``aq_chain``:
+
+      >>> Acquisition.aq_chain(x) == [x, y, z]
+      True
+
     Note that also the (implicit) acquisition wrapper has a __parent__
     pointer, which is automatically computed from the acquisition
     container (it's identical to aq_parent):
@@ -1791,8 +1799,6 @@
       Traceback (most recent call last):
         ...
       AttributeError: __parent__
-
-    TODO aq_chain
     """
 
 def test_explicit_wrapper_as___parent__():
@@ -1843,6 +1849,11 @@
       >>> Acquisition.aq_parent(y) is z
       True
 
+    as well as ``aq_chain``:
+
+      >>> Acquisition.aq_chain(x) == [x, y, z]
+      True
+
     Note that also the (explicit) acquisition wrapper has a __parent__
     pointer, which is automatically computed from the acquisition
     container (it's identical to aq_parent):
@@ -1867,8 +1878,6 @@
       Traceback (most recent call last):
         ...
       AttributeError: __parent__
-
-    TODO aq_chain
     """
 
 def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
@@ -1917,6 +1926,13 @@
       >>> Acquisition.aq_parent(y) is z
       True
 
+    as well as ``aq_chain``:
+
+      >>> Acquisition.aq_chain(x) == [x, y, z]
+      True
+      >>> x.aq_chain == [x, y, z]
+      True
+
     Because the outmost object, ``x``, is wrapped in an implicit
     acquisition wrapper, we can also use direct attribute access:
 
@@ -1926,8 +1942,6 @@
       42
       >>> x.bar
       3.145
-
-    TODO aq_chain
     """
 
 def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
@@ -1976,7 +1990,12 @@
       >>> Acquisition.aq_parent(y) is z
       True
 
-    TODO aq_chain
+    as well as ``aq_chain``:
+
+      >>> Acquisition.aq_chain(x) == [x, y, z]
+      True
+      >>> x.aq_chain == [x, y, z]
+      True
     """
 
 import unittest



More information about the Checkins mailing list