Commit 60ef19a2 authored by Tres Seaver's avatar Tres Seaver

- Raise more "Pythonic" errors from ``__setitem__``, losing the dependency

  on ``zope.exceptions``:

  o ``zope.exceptions.DuplicationError`` -> ``KeyError``

  o ``zope.exceptions.UserError`` -> ``ValueError``
parent c8107b86
......@@ -5,6 +5,13 @@ CHANGES
3.7.1 (unreleased)
------------------
- Raise more "Pythonic" errors from ``__setitem__``, losing the dependency
on ``zope.exceptions``:
o ``zope.exceptions.DuplicationError`` -> ``KeyError``
o ``zope.exceptions.UserError`` -> ``ValueError``
- Moved import of ``IBroken`` interface to use new ``zope.broken``
package, which has no dependencies beyond ``zope.interface``.
......
......@@ -68,7 +68,6 @@ setup(name='zope.container',
'zope.component',
'zope.event',
'zope.location',
'zope.exceptions',
'zope.security',
'zope.lifecycleevent',
'zope.i18nmessageid',
......
......@@ -25,7 +25,6 @@ from zope.interface.declarations import ObjectSpecification
from zope.event import notify
from zope.component.interfaces import ObjectEvent
from zope.location.interfaces import ILocation, ISublocations
from zope.exceptions.interfaces import DuplicationError, UserError
from zope.security.checker import selectChecker, CombinedChecker
from zope.lifecycleevent import ObjectModifiedEvent
......@@ -478,7 +477,7 @@ def setitem(container, setitemf, name, object):
>>> setitem(container, container.__setitem__, u'c', [])
Traceback (most recent call last):
...
DuplicationError: c
KeyError: u'c'
>>> del container[u'c']
......@@ -582,7 +581,7 @@ def setitem(container, setitemf, name, object):
if old is object:
return
if old is not None:
raise DuplicationError(name)
raise KeyError(name)
object, event = containedEvent(object, container, name)
setitemf(name, object)
......@@ -718,19 +717,19 @@ class NameChooser(object):
>>> NameChooser(container).checkName('+foo', object())
Traceback (most recent call last):
...
UserError: Names cannot begin with '+' or '@' or contain '/'
ValueError: Names cannot begin with '+' or '@' or contain '/'
>>> NameChooser(container).checkName('@foo', object())
Traceback (most recent call last):
...
UserError: Names cannot begin with '+' or '@' or contain '/'
ValueError: Names cannot begin with '+' or '@' or contain '/'
>>> NameChooser(container).checkName('f/oo', object())
Traceback (most recent call last):
...
UserError: Names cannot begin with '+' or '@' or contain '/'
ValueError: Names cannot begin with '+' or '@' or contain '/'
>>> NameChooser(container).checkName('foo', object())
Traceback (most recent call last):
...
UserError: The given name is already being used
KeyError: u'The given name is already being used'
>>> NameChooser(container).checkName(2, object())
Traceback (most recent call last):
...
......@@ -745,7 +744,7 @@ class NameChooser(object):
"""
if not name:
raise UserError(
raise ValueError(
_("An empty name was provided. Names cannot be empty.")
)
......@@ -755,12 +754,12 @@ class NameChooser(object):
raise TypeError("Invalid name type", type(name))
if name[:1] in '+@' or '/' in name:
raise UserError(
raise ValueError(
_("Names cannot begin with '+' or '@' or contain '/'")
)
if name in self.context:
raise UserError(
raise KeyError(
_("The given name is already being used")
)
......
......@@ -21,7 +21,6 @@ from BTrees.OOBTree import OOBTree
from persistent import Persistent
from zope.container.interfaces import IContainer, IContentContainer
from zope.container.contained import Contained, setitem, uncontained
from zope.exceptions import DuplicationError
from zope.interface import implements, directlyProvides
# XXX This container implementation is really only used by
......@@ -93,7 +92,7 @@ class Folder(Persistent, Contained):
raise TypeError("Name must not be empty")
if name in self.data:
raise DuplicationError("name, %s, is already in use" % name)
raise KeyError("name, %s, is already in use" % name)
setitem(self, self.data.__setitem__, name, object)
......
......@@ -64,7 +64,11 @@ class IWriteContainer(Interface):
"""Add the given `object` to the container under the given name.
Raises a ``TypeError`` if the key is not a unicode or ascii string.
Raises a ``ValueError`` if key is empty.
Raises a ``ValueError`` if the key is empty, or if the key contains
a character which is not allowed in an object name.
Raises a ``KeyError`` if the key violates a uniqueness constraint.
The container might choose to add a different object than the
one passed to this method.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment