Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zope-container
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
zope-container
Commits
14b41ba5
Commit
14b41ba5
authored
Jun 16, 2010
by
Christian Theune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #118088: Moving a folder to one of its subfolders causes a system error.
parent
88c4e395
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
CHANGES.txt
CHANGES.txt
+2
-0
src/zope/container/constraints.py
src/zope/container/constraints.py
+11
-1
src/zope/container/constraints.txt
src/zope/container/constraints.txt
+16
-0
No files found.
CHANGES.txt
View file @
14b41ba5
...
@@ -5,6 +5,8 @@ CHANGES
...
@@ -5,6 +5,8 @@ CHANGES
3.11.2 (unreleased)
3.11.2 (unreleased)
-------------------
-------------------
- Fix detection of moving folders into itself or a subfolder of itself.
(#118088)
3.11.1 (2010-04-30)
3.11.1 (2010-04-30)
-------------------
-------------------
...
...
src/zope/container/constraints.py
View file @
14b41ba5
...
@@ -159,7 +159,7 @@ from zope.container.i18n import ZopeMessageFactory as _
...
@@ -159,7 +159,7 @@ from zope.container.i18n import ZopeMessageFactory as _
from
zope.container.interfaces
import
IContainer
from
zope.container.interfaces
import
IContainer
def
checkObject
(
container
,
name
,
object
):
def
checkObject
(
container
,
name
,
object
):
"""Check contain
e
ment constraints for an object and container
"""Check containment constraints for an object and container
"""
"""
# check __setitem__ precondition
# check __setitem__ precondition
...
@@ -170,6 +170,16 @@ def checkObject(container, name, object):
...
@@ -170,6 +170,16 @@ def checkObject(container, name, object):
if
precondition
is
not
None
:
if
precondition
is
not
None
:
precondition
(
container
,
name
,
object
)
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__
# check the constraint on __parent__
__parent__
=
providedBy
(
object
).
get
(
'__parent__'
)
__parent__
=
providedBy
(
object
).
get
(
'__parent__'
)
if
__parent__
is
not
None
:
if
__parent__
is
not
None
:
...
...
src/zope/container/constraints.txt
View file @
14b41ba5
...
@@ -96,4 +96,20 @@ could have defined these in the opposite order:
...
@@ -96,4 +96,20 @@ could have defined these in the opposite order:
>>> checkFactory(Contacts(), 'x', Factory(Buddy))
>>> checkFactory(Contacts(), 'x', Factory(Buddy))
False
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.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment