[Checkins] SVN: Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/ Allow assignment to a wrapper's __parent__.

Philipp von Weitershausen philikon at philikon.de
Mon Nov 20 19:28:55 EST 2006


Log message for revision 71222:
  Allow assignment to a wrapper's __parent__.
  

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

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:28:44 UTC (rev 71221)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/_Acquisition.c	2006-11-21 00:28:54 UTC (rev 71222)
@@ -663,8 +663,8 @@
 
   /* Allow assignment to parent, to change context. */
   if (PyString_Check(oname)) name=PyString_AS_STRING(oname);
-  if (*name=='a' && name[1]=='q' && name[2]=='_' 
-      && strcmp(name+3,"parent")==0)
+  if ((*name=='a' && name[1]=='q' && name[2]=='_' 
+       && strcmp(name+3,"parent")==0) || (strcmp(name, "__parent__")==0))
     {
       Py_XINCREF(v);
       ASSIGN(self->container, v);

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:28:44 UTC (rev 71221)
+++ Zope/branches/philikon-aq-and-__parent__/lib/python/Acquisition/tests.py	2006-11-21 00:28:54 UTC (rev 71222)
@@ -1713,9 +1713,9 @@
     The intermediate parent is an object that supports implicit
     acquisition.  We bind it to the root via the __of__ protocol:
 
-      >>> class ImplWrapper(Acquisition.Implicit):
+      >>> class Impl(Acquisition.Implicit):
       ...     foo = 42
-      >>> y = ImplWrapper().__of__(z)
+      >>> y = Impl().__of__(z)
 
     The child object is again a simple object with a simple __parent__
     pointer:
@@ -1741,6 +1741,24 @@
       >>> y.__parent__ is z
       True
 
+    Just as much as you can assign to aq_parent, you can also assign
+    to __parent__ to change the acquisition context of the wrapper:
+
+      >>> newroot = Root()
+      >>> y.__parent__ = newroot
+      >>> y.__parent__ is z
+      False
+      >>> y.__parent__ is newroot
+      True
+
+    Note that messing with the wrapper won't in any way affect the
+    wrapped object:
+
+      >>> Acquisition.aq_base(y).__parent__
+      Traceback (most recent call last):
+        ...
+      AttributeError: __parent__
+
     TODO aq_parent, aq_chain
     """
 
@@ -1755,9 +1773,9 @@
     The intermediate parent is an object that supports implicit
     acquisition.  We bind it to the root via the __of__ protocol:
 
-      >>> class ExplWrapper(Acquisition.Explicit):
+      >>> class Expl(Acquisition.Explicit):
       ...     foo = 42
-      >>> y = ExplWrapper().__of__(z)
+      >>> y = Expl().__of__(z)
 
     The child object is again a simple object with a simple __parent__
     pointer:
@@ -1783,6 +1801,24 @@
       >>> y.__parent__ is z
       True
 
+    Just as much as you can assign to aq_parent, you can also assign
+    to __parent__ to change the acquisition context of the wrapper:
+
+      >>> newroot = Root()
+      >>> y.__parent__ = newroot
+      >>> y.__parent__ is z
+      False
+      >>> y.__parent__ is newroot
+      True
+
+    Note that messing with the wrapper won't in any way affect the
+    wrapped object:
+
+      >>> Acquisition.aq_base(y).__parent__
+      Traceback (most recent call last):
+        ...
+      AttributeError: __parent__
+
     TODO aq_parent, aq_chain
     """
 



More information about the Checkins mailing list