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

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


Log message for revision 71227:
  Step 4: Make aq_get aware of __parent__ pointers.
  (Also some comment cosmetics in _Acquisition.c)
  

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:3248
   + bfa16f6a-5b7b-4684-983a-15b8a78f95a3:/local/Acquisition:3249

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:38 UTC (rev 71226)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/_Acquisition.c	2006-11-21 00:29:48 UTC (rev 71227)
@@ -1391,9 +1391,8 @@
               explicit || 
               WRAPPER(self)->ob_type==(PyTypeObject*)&Wrappertype,
               explicit, containment);
-  /* Not wrapped; check if we have a __parent__ pointer.  If that's
-     the case, we create a wrapper and pretend it's business as
-     usual */
+  /* Not wrapped; check if we have a __parent__ pointer.  In that
+     case, create a wrapper and pretend it's business as usual */
   else if ((result = PyObject_GetAttr(self, py__parent__)))
     {
       self = newWrapper(self, result, (PyTypeObject*)&Wrappertype);
@@ -1408,8 +1407,8 @@
   /* No filter, and no __parent__, so just getattr */
   else
     {
-      /* we need to clean up the AttributeError from the previous
-         getattr (because it has clearly failed) */
+      /* clean up the AttributeError from the previous getattr
+         (because it has clearly failed) */
       PyErr_Fetch(&result,&v,&tb);
       if (result && (result != PyExc_AttributeError))
         {
@@ -1457,14 +1456,36 @@
 static PyObject *
 capi_aq_get(PyObject *self, PyObject *name, PyObject *defalt, int containment)
 {
-  PyObject *result = NULL;
+  PyObject *result = NULL, *v, *tb;
   /* We got a wrapped object, so business as usual */
   if (isWrapper(self)) 
     result=Wrapper_findattr(WRAPPER(self), name, 0, 0, OBJECT(self), 1, 1, 1, 
-                       containment);
+                            containment);
+  /* Not wrapped; check if we have a __parent__ pointer.  In that
+     case, create a wrapper and pretend it's business as usual */
+  else if ((result = PyObject_GetAttr(self, py__parent__)))
+    {
+      self=newWrapper(self, result, (PyTypeObject*)&Wrappertype);
+      Py_DECREF(result); /* don't need __parent__ anymore */
+      result=Wrapper_findattr(WRAPPER(self), name, 0, 0, OBJECT(self),
+                              1, 1, 1, containment);
+      Py_DECREF(self); /* get rid of temp wrapper */
+    }
   else
-    result=PyObject_GetAttr(self, name);
+    {
+      /* 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);
 
+      result=PyObject_GetAttr(self, name);
+    }
+
   if (! result && defalt)
     {
       PyErr_Clear();

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:38 UTC (rev 71226)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/tests.py	2006-11-21 00:29:48 UTC (rev 71227)
@@ -1688,7 +1688,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'
@@ -1697,8 +1698,17 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    as does ``aq_parent``:
+    as does ``aq_get``:
 
+      >>> Acquisition.aq_get(x, 'hello')
+      'world'
+      >>> Acquisition.aq_get(x, 'foo')
+      42
+      >>> Acquisition.aq_get(x, 'bar')
+      3.145
+
+    and ``aq_parent``:
+
       >>> Acquisition.aq_parent(x) is y
       True
       >>> Acquisition.aq_parent(y) is z
@@ -1741,8 +1751,17 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    as does ``aq_parent``:
+    as does ``aq_get``:
 
+      >>> Acquisition.aq_get(x, 'hello')
+      'world'
+      >>> Acquisition.aq_get(x, 'foo')
+      42
+      >>> Acquisition.aq_get(x, 'bar')
+      3.145
+
+    and ``aq_parent``:
+
       >>> Acquisition.aq_parent(x) is y
       True
       >>> Acquisition.aq_parent(y) is z
@@ -1808,8 +1827,17 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    as does ``aq_parent``:
+    as does ``aq_get``:
 
+      >>> Acquisition.aq_get(x, 'hello')
+      'world'
+      >>> Acquisition.aq_get(x, 'foo')
+      42
+      >>> Acquisition.aq_get(x, 'bar')
+      3.145
+
+    and ``aq_parent``:
+
       >>> Acquisition.aq_parent(x) is y
       True
       >>> Acquisition.aq_parent(y) is z
@@ -1869,8 +1897,17 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    as does ``aq_parent``:
+    as does ``aq_get``:
 
+      >>> Acquisition.aq_get(x, 'hello')
+      'world'
+      >>> Acquisition.aq_get(x, 'foo')
+      42
+      >>> Acquisition.aq_get(x, 'bar')
+      3.145
+
+    and ``aq_parent``:
+
       >>> Acquisition.aq_parent(x) == y
       True
       >>> Acquisition.aq_parent(y) is z
@@ -1915,8 +1952,17 @@
       >>> Acquisition.aq_acquire(x, 'bar')
       3.145
 
-    as does ``aq_parent``:
+    as does ``aq_get``:
 
+      >>> Acquisition.aq_get(x, 'hello')
+      'world'
+      >>> Acquisition.aq_get(x, 'foo')
+      42
+      >>> Acquisition.aq_get(x, 'bar')
+      3.145
+
+    and ``aq_parent``:
+
       >>> Acquisition.aq_parent(x) == y
       True
       >>> Acquisition.aq_parent(y) is z



More information about the Checkins mailing list