Log message for revision 78317:
  Merged from old philikon-aq-and-__parent__ branch:
  
  Log message for revision 71224:
    Step 3: Make aq_parent aware of __parent__ pointers.
  
  

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-24 19:46:24 UTC (rev 78316)
+++ Zope/branches/philikon-aq/lib/python/Acquisition/_Acquisition.c     
2007-07-24 20:46:33 UTC (rev 78317)
@@ -1555,13 +1555,34 @@
 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__)))
+    /* We already own the reference to result (PyObject_GetAttr gives
+       it to us), no need to INCREF here */
+    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/lib/python/Acquisition/tests.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Acquisition/tests.py   2007-07-24 
19:46:24 UTC (rev 78316)
+++ Zope/branches/philikon-aq/lib/python/Acquisition/tests.py   2007-07-24 
20:46:33 UTC (rev 78317)
@@ -1715,7 +1715,8 @@
       >>> z.foo = 43  # this should not be found
       >>> z.bar = 3.145
 
-    ``aq_acquire`` works we know it from implicit/acquisition wrappers:
+    ``aq_acquire`` works as we know it from implicit/acquisition
+    wrappers:
 
       >>> Acquisition.aq_acquire(x, 'hello')
       'world'
@@ -1724,7 +1725,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__():
@@ -1761,6 +1769,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):
@@ -1786,7 +1801,7 @@
         ...
       AttributeError: __parent__
 
-    TODO aq_parent, aq_chain
+    TODO aq_chain
     """
 
 def test_explicit_wrapper_as___parent__():
@@ -1821,6 +1836,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):
@@ -1846,7 +1868,7 @@
         ...
       AttributeError: __parent__
 
-    TODO aq_parent, aq_chain
+    TODO aq_chain
     """
 
 def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
@@ -1875,6 +1897,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:
 
@@ -1905,7 +1934,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'
@@ -1914,7 +1943,7 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    TODO aq_parent, aq_chain
+    TODO aq_chain
     """
 
 def test___parent__aq_parent_circles():

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to