[Checkins] SVN: zope.container/trunk/ Fix #118088: Moving a folder to one of its subfolders causes a system error.

Christian Theune ct at gocept.com
Wed Jun 16 09:03:06 EDT 2010


Log message for revision 113531:
  Fix #118088: Moving a folder to one of its subfolders causes a system error.
  
  

Changed:
  U   zope.container/trunk/CHANGES.txt
  U   zope.container/trunk/src/zope/container/constraints.py
  U   zope.container/trunk/src/zope/container/constraints.txt

-=-
Modified: zope.container/trunk/CHANGES.txt
===================================================================
--- zope.container/trunk/CHANGES.txt	2010-06-16 13:02:48 UTC (rev 113530)
+++ zope.container/trunk/CHANGES.txt	2010-06-16 13:03:06 UTC (rev 113531)
@@ -5,6 +5,8 @@
 3.11.2 (unreleased)
 -------------------
 
+- Fix detection of moving folders into itself or a subfolder of itself.
+  (#118088)
 
 3.11.1 (2010-04-30)
 -------------------

Modified: zope.container/trunk/src/zope/container/constraints.py
===================================================================
--- zope.container/trunk/src/zope/container/constraints.py	2010-06-16 13:02:48 UTC (rev 113530)
+++ zope.container/trunk/src/zope/container/constraints.py	2010-06-16 13:03:06 UTC (rev 113531)
@@ -159,7 +159,7 @@
 from zope.container.interfaces import IContainer
 
 def checkObject(container, name, object):
-    """Check containement constraints for an object and container
+    """Check containment constraints for an object and container
     """
 
     # check __setitem__ precondition
@@ -170,6 +170,16 @@
         if precondition is not None:
             precondition(container, name, object)
 
+    # check that object is not being pasted into itself or its children.
+    target = container
+    while target is not None:
+        if target is object:
+            raise TypeError("Cannot add an object to itself or its children.")
+        if zope.location.interfaces.ILocation.providedBy(target):
+            target = target.__parent__
+        else:
+            target = None
+
     # check the constraint on __parent__
     __parent__ = providedBy(object).get('__parent__')
     if __parent__ is not None:

Modified: zope.container/trunk/src/zope/container/constraints.txt
===================================================================
--- zope.container/trunk/src/zope/container/constraints.txt	2010-06-16 13:02:48 UTC (rev 113530)
+++ zope.container/trunk/src/zope/container/constraints.txt	2010-06-16 13:03:06 UTC (rev 113531)
@@ -96,4 +96,20 @@
     >>> checkFactory(Contacts(), 'x', Factory(Buddy))
     False
 
+The constraints prevent us from moving a container beneath itself (either into
+itself or another folder beneath it):
 
+    >>> container = Container()
+    >>> checkObject(container, 'x', container)
+    Traceback (most recent call last):
+    TypeError: Cannot add an object to itself or its children.
+
+    >>> import zope.location.interfaces
+    >>> import zope.interface
+    >>> subcontainer = Container()
+    >>> zope.interface.directlyProvides(subcontainer,
+    ...     zope.location.interfaces.ILocation)
+    >>> subcontainer.__parent__ = container
+    >>> checkObject(subcontainer, 'x', container)
+    Traceback (most recent call last):
+    TypeError: Cannot add an object to itself or its children.



More information about the checkins mailing list