[Checkins] SVN: zope.container/trunk/ - Raise more "Pythonic" errors from ``__setitem__``, losing the dependency
Tres Seaver
tseaver at palladion.com
Wed Feb 4 19:47:40 EST 2009
Log message for revision 96116:
- Raise more "Pythonic" errors from ``__setitem__``, losing the dependency
on ``zope.exceptions``:
o ``zope.exceptions.DuplicationError`` -> ``KeyError``
o ``zope.exceptions.UserError`` -> ``ValueError``
Changed:
U zope.container/trunk/CHANGES.txt
U zope.container/trunk/setup.py
U zope.container/trunk/src/zope/container/contained.py
U zope.container/trunk/src/zope/container/folder.py
U zope.container/trunk/src/zope/container/interfaces.py
-=-
Modified: zope.container/trunk/CHANGES.txt
===================================================================
--- zope.container/trunk/CHANGES.txt 2009-02-05 00:46:31 UTC (rev 96115)
+++ zope.container/trunk/CHANGES.txt 2009-02-05 00:47:40 UTC (rev 96116)
@@ -5,6 +5,13 @@
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``.
Modified: zope.container/trunk/setup.py
===================================================================
--- zope.container/trunk/setup.py 2009-02-05 00:46:31 UTC (rev 96115)
+++ zope.container/trunk/setup.py 2009-02-05 00:47:40 UTC (rev 96116)
@@ -68,7 +68,6 @@
'zope.component',
'zope.event',
'zope.location',
- 'zope.exceptions',
'zope.security',
'zope.lifecycleevent',
'zope.i18nmessageid',
Modified: zope.container/trunk/src/zope/container/contained.py
===================================================================
--- zope.container/trunk/src/zope/container/contained.py 2009-02-05 00:46:31 UTC (rev 96115)
+++ zope.container/trunk/src/zope/container/contained.py 2009-02-05 00:47:40 UTC (rev 96116)
@@ -25,7 +25,6 @@
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 @@
>>> setitem(container, container.__setitem__, u'c', [])
Traceback (most recent call last):
...
- DuplicationError: c
+ KeyError: u'c'
>>> del container[u'c']
@@ -582,7 +581,7 @@
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 @@
>>> 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 @@
"""
if not name:
- raise UserError(
+ raise ValueError(
_("An empty name was provided. Names cannot be empty.")
)
@@ -755,12 +754,12 @@
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")
)
Modified: zope.container/trunk/src/zope/container/folder.py
===================================================================
--- zope.container/trunk/src/zope/container/folder.py 2009-02-05 00:46:31 UTC (rev 96115)
+++ zope.container/trunk/src/zope/container/folder.py 2009-02-05 00:47:40 UTC (rev 96116)
@@ -21,7 +21,6 @@
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 @@
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)
Modified: zope.container/trunk/src/zope/container/interfaces.py
===================================================================
--- zope.container/trunk/src/zope/container/interfaces.py 2009-02-05 00:46:31 UTC (rev 96115)
+++ zope.container/trunk/src/zope/container/interfaces.py 2009-02-05 00:47:40 UTC (rev 96116)
@@ -64,8 +64,12 @@
"""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.
More information about the Checkins
mailing list