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
0aa8b4e1
Commit
0aa8b4e1
authored
Mar 05, 2009
by
Dan Korostelev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for reserved names.
parent
45b86cc4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
3 deletions
+52
-3
CHANGES.txt
CHANGES.txt
+4
-1
src/zope/container/contained.py
src/zope/container/contained.py
+32
-0
src/zope/container/interfaces.py
src/zope/container/interfaces.py
+16
-2
No files found.
CHANGES.txt
View file @
0aa8b4e1
...
...
@@ -5,7 +5,10 @@ CHANGES
3.7.2 (unreleased)
------------------
- ...
- Add support for reserved names for containers. To specify reserved
names for some container, you need to provide an adapter from the
container to the ``zope.container.interfaces.IReservedNames`` interface.
The default NameChooser is now also aware of reserved names.
3.7.1 (2009-02-05)
------------------
...
...
src/zope/container/contained.py
View file @
0aa8b4e1
...
...
@@ -31,6 +31,7 @@ from zope.lifecycleevent import ObjectModifiedEvent
from
zope.container.i18n
import
ZopeMessageFactory
as
_
from
zope.container.interfaces
import
IContained
from
zope.container.interfaces
import
INameChooser
from
zope.container.interfaces
import
IReservedNames
,
NameReserved
from
zope.container.interfaces
import
IObjectAddedEvent
from
zope.container.interfaces
import
IObjectMovedEvent
from
zope.container.interfaces
import
IObjectRemovedEvent
...
...
@@ -740,6 +741,32 @@ class NameChooser(object):
>>> NameChooser(container).checkName('2', object())
True
We can reserve some names by providing a IReservedNames adapter
to a container:
>>> NameChooser(container).checkName('reserved', None)
True
>>> NameChooser(container).checkName('other', None)
True
>>> from zope.container.interfaces import IContainer
>>> class ReservedNames(object):
... zope.component.adapts(IContainer)
... zope.interface.implements(IReservedNames)
...
... def __init__(self, context):
... self.reservedNames = set(('reserved', 'other'))
>>> zope.component.provideAdapter(ReservedNames)
>>> NameChooser(container).checkName('reserved', None)
Traceback (most recent call last):
...
NameReserved: reserved
>>> NameChooser(container).checkName('other', None)
Traceback (most recent call last):
...
NameReserved: other
"""
...
...
@@ -758,6 +785,11 @@ class NameChooser(object):
_
(
"Names cannot begin with '+' or '@' or contain '/'"
)
)
reserved
=
IReservedNames
(
self
.
context
,
None
)
if
reserved
is
not
None
:
if
name
in
reserved
.
reservedNames
:
raise
NameReserved
(
name
)
if
name
in
self
.
context
:
raise
KeyError
(
_
(
"The given name is already being used"
)
...
...
src/zope/container/interfaces.py
View file @
0aa8b4e1
...
...
@@ -18,11 +18,14 @@ $Id$
__docformat__
=
'restructuredtext'
from
zope.interface
import
Interface
,
Attribute
,
Invalid
from
zope.component.interfaces
import
IObjectEvent
from
zope.interface.common.mapping
import
IItemMapping
from
zope.interface.common.mapping
import
IReadMapping
,
IEnumerableMapping
from
zope.
location.interfaces
import
ILocation
from
zope.
component.interfaces
import
IObjectEvent
from
zope.lifecycleevent.interfaces
import
IObjectModifiedEvent
from
zope.location.interfaces
import
ILocation
from
zope.schema
import
Set
from
zope.container.i18n
import
ZopeMessageFactory
as
_
class
DuplicateIDError
(
KeyError
):
pass
...
...
@@ -193,6 +196,17 @@ class IOrderedContainer(IContainer):
class
IContainerNamesContainer
(
IContainer
):
"""Containers that always choose names for their items."""
class
IReservedNames
(
Interface
):
"""A sequence of names that are reserved for that container"""
reservedNames
=
Set
(
title
=
_
(
u'Reserved Names'
),
description
=
_
(
u'Names that are not allowed for addable content'
),
required
=
True
,
)
class
NameReserved
(
ValueError
):
__doc__
=
_
(
"""The name is reserved for this container"""
)
##############################################################################
# Moving Objects
...
...
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