[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - IContainer.py:1.6 SampleContainer.py:1.3

Steve Alexander steve@cat-box.net
Mon, 18 Nov 2002 08:34:49 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container
In directory cvs.zope.org:/tmp/cvs-serv443/lib/python/Zope/App/OFS/Container

Modified Files:
	IContainer.py SampleContainer.py 
Log Message:
Clarified the semantics of keys in an IContainer. They must be ascii
strings or unicodes.
If you want a container to make up its own key, and the container
supports this, the key must be the empty string.
I fixed a in Adding.py where this would not occur properly.


=== Zope3/lib/python/Zope/App/OFS/Container/IContainer.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/OFS/Container/IContainer.py:1.5	Tue Jun 11 19:12:34 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/IContainer.py	Mon Nov 18 08:34:19 2002
@@ -22,7 +22,7 @@
 class IItemContainer(Interface):
 
     def __getitem__(key):
-        """Return the content for the given key
+        """Return the content for the given key.
 
         Raises KeyError if the content can't be found.
         """
@@ -44,14 +44,15 @@
         Raises a ValueError if key is an empty string, unless the
         container chooses a different key.
 
+        Raises a TypeError if the key is not a unicode or ascii string.
+
         Returns the key used, which might be different than the given key.
         """
 
     def __delitem__(key):
-        """Delete the keyd object from the container.
+        """Delete the keyed object from the container.
 
         Raises a KeyError if the object is not found.
-
         """
 
 class IContainer(IReadContainer, IWriteContainer):


=== Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py:1.2	Mon Jun 10 19:27:55 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py	Mon Nov 18 08:34:19 2002
@@ -89,8 +89,10 @@
 
     def setObject(self, key, object):
         '''See interface IWriteContainer'''
-        if type(key) in StringTypes and len(key)==0:
-            raise ValueError("The id cannot be an empty string")
+        if not isinstance(key, StringTypes):
+            raise TypeError("The key must be an ascii or unicode string")
+        if len(key) == 0:
+            raise ValueError("The key cannot be an empty string")
         self.__data[key] = object
         return key