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

Philipp von Weitershausen philikon at philikon.de
Mon Nov 20 19:29:17 EST 2006


Log message for revision 71224:
  Step 3: Make aq_parent 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:3245
   + bfa16f6a-5b7b-4684-983a-15b8a78f95a3:/local/Acquisition:3246

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:06 UTC (rev 71223)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/_Acquisition.c	2006-11-21 00:29:17 UTC (rev 71224)
@@ -586,7 +586,6 @@
         {
           /* we need to clean up the AttributeError from the previous
              getattr (because it has clearly failed) */
-          /* perhaps it's overkill to only catch  AttributeErrors */
           PyErr_Fetch(&r,&v,&tb);
           if (r && (r != PyExc_AttributeError))
             {
@@ -1507,13 +1506,32 @@
 static PyObject *
 capi_aq_parent(PyObject *self)
 {
-  PyObject *result=Py_None;
+  PyObject *result, *v, *tb;
 
   if (isWrapper(self) && WRAPPER(self)->container)
-          result=WRAPPER(self)->container;
+    {
+      result=WRAPPER(self)->container;
+      Py_INCREF(result);
+      return result;
+    }
+  else if ((result=PyObject_GetAttr(self, py__parent__)))
+    return result;
+  else
+    {
+      /* we need to clean up the AttributeError from the previous
+         getattr (because it has clearly failed) */
+      PyErr_Fetch(&result,&v,&tb);
+      if (result && (result != PyExc_AttributeError))
+        {
+          PyErr_Restore(result,v,tb);
+          return NULL;
+        }
+      Py_XDECREF(result); Py_XDECREF(v); Py_XDECREF(tb);
 
-  Py_INCREF(result);
-  return result;
+      result=Py_None;
+      Py_INCREF(result);
+      return result;
+    }
 }
 
 static PyObject *

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:06 UTC (rev 71223)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/tests.py	2006-11-21 00:29:17 UTC (rev 71224)
@@ -1697,7 +1697,14 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    TODO aq_parent, aq_chain
+    as does ``aq_parent``:
+
+      >>> Acquisition.aq_parent(x) is y
+      True
+      >>> Acquisition.aq_parent(y) is z
+      True
+
+    TODO aq_chain
     """
 
 def test_implicit_wrapper_as___parent__():
@@ -1734,6 +1741,13 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
+    as does ``aq_parent``:
+
+      >>> Acquisition.aq_parent(x) is y
+      True
+      >>> Acquisition.aq_parent(y) is 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):
@@ -1759,7 +1773,7 @@
         ...
       AttributeError: __parent__
 
-    TODO aq_parent, aq_chain
+    TODO aq_chain
     """
 
 def test_explicit_wrapper_as___parent__():
@@ -1794,6 +1808,13 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
+    as does ``aq_parent``:
+
+      >>> Acquisition.aq_parent(x) is y
+      True
+      >>> Acquisition.aq_parent(y) is 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):
@@ -1819,7 +1840,7 @@
         ...
       AttributeError: __parent__
 
-    TODO aq_parent, aq_chain
+    TODO aq_chain
     """
 
 def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
@@ -1839,7 +1860,7 @@
       ...     hello = 'world'
       >>> x = Impl().__of__(y)
 
-    Again, acquiring objects work as usual:
+    Again, acquiring objects works as usual:
 
       >>> Acquisition.aq_acquire(x, 'hello')
       'world'
@@ -1848,6 +1869,13 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
+    as does ``aq_parent``:
+
+      >>> Acquisition.aq_parent(x) == y
+      True
+      >>> Acquisition.aq_parent(y) is z
+      True
+
     Because the outmost object, ``x``, is wrapped in an implicit
     acquisition wrapper, we can also use direct attribute access:
 
@@ -1858,7 +1886,7 @@
       >>> x.bar
       3.145
 
-    TODO aq_parent, aq_chain
+    TODO aq_chain
     """
 
 def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
@@ -1878,7 +1906,7 @@
       ...     hello = 'world'
       >>> x = Expl().__of__(y)
 
-    Again, acquiring objects work as usual:
+    Again, acquiring objects works as usual:
 
       >>> Acquisition.aq_acquire(x, 'hello')
       'world'
@@ -1887,7 +1915,14 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    TODO aq_parent, aq_chain
+    as does ``aq_parent``:
+
+      >>> Acquisition.aq_parent(x) == y
+      True
+      >>> Acquisition.aq_parent(y) is z
+      True
+
+    TODO aq_chain
     """
 
 import unittest



More information about the Zope-Checkins mailing list