[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/Acquisition/ Merge r71220 from old branch:

Philipp von Weitershausen philikon at philikon.de
Tue Jul 10 11:49:42 EDT 2007


Log message for revision 77680:
  Merge r71220 from old branch:
    Warming up: Make acquisition wrappers have __parent__ in addition to aq_parent
    (they point to the same thing).
  

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-10 14:48:45 UTC (rev 77679)
+++ Zope/branches/philikon-aq/lib/python/Acquisition/_Acquisition.c	2007-07-10 15:49:42 UTC (rev 77680)
@@ -419,18 +419,27 @@
   char *name="";
 
   if (PyString_Check(oname)) name=PyString_AS_STRING(oname);
-  if (*name=='a' && name[1]=='q' && name[2]=='_')
-    if ((r=Wrapper_special(self, name+3, oname)))
-      {
-	if (filter)
-	  switch(apply_filter(filter,OBJECT(self),oname,r,extra,orig))
-	    {
-	    case -1: return NULL;
-	    case 1: return r;
-	    }
-	else return r;
-      }
-    else PyErr_Clear();
+  if ((*name=='a' && name[1]=='q' && name[2]=='_') ||
+      (strcmp(name, "__parent__")==0))
+    {
+      /* __parent__ is an alias to aq_parent */
+      if (strcmp(name, "__parent__")==0)
+        name = "parent";
+      else
+        name = name + 3;
+
+      if ((r=Wrapper_special(self, name, oname)))
+        {
+          if (filter)
+            switch(apply_filter(filter,OBJECT(self),oname,r,extra,orig))
+              {
+              case -1: return NULL;
+              case 1: return r;
+              }
+          else return r;
+        }
+      else PyErr_Clear();
+    }
   else if (*name=='_' && name[1]=='_' && 
            (strcmp(name+2,"reduce__")==0 ||
             strcmp(name+2,"reduce_ex__")==0 ||

Modified: Zope/branches/philikon-aq/lib/python/Acquisition/tests.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Acquisition/tests.py	2007-07-10 14:48:45 UTC (rev 77679)
+++ Zope/branches/philikon-aq/lib/python/Acquisition/tests.py	2007-07-10 15:49:42 UTC (rev 77680)
@@ -357,6 +357,11 @@
     ...
     AttributeError: aq_parent
 
+    >>> c.__parent__
+    Traceback (most recent call last):
+    ...
+    AttributeError: __parent__
+
     >>> Acquisition.aq_acquire(c, 'id')
     'unwrapped'
     >>> Acquisition.aq_acquire(c, 'x')
@@ -533,6 +538,13 @@
     >>> show(Acquisition.aq_self(a.b.c))
     c
 
+    A wrapper's __parent__ attribute (which is equivalent to its
+    aq_parent attribute) points to the Acquisition parent.
+
+    >>> a.b.c.__parent__ == a.b.c.aq_parent
+    True
+    >>> a.b.c.__parent__ == a.b
+    True
     """
 
 def test__of__exception():



More information about the Zope-Checkins mailing list