[Zope3-checkins] CVS: Zope3/src/zope/app/container - sample.py:1.8

Jim Fulton jim at zope.com
Sun Sep 21 13:31:36 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv13284/src/zope/app/container

Modified Files:
	sample.py 
Log Message:
Changed __iter__ to use the iterator of the underlying container.

Changed setObject to __setitem__. Took out name-checking code. Name
checking is now handled by the setitem helper function.


=== Zope3/src/zope/app/container/sample.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/container/sample.py:1.7	Tue Jun  3 10:19:31 2003
+++ Zope3/src/zope/app/container/sample.py	Sun Sep 21 13:31:35 2003
@@ -26,8 +26,9 @@
 
 from zope.app.interfaces.container import IContainer
 from zope.interface import implements
+from zope.app.container.contained import Contained, setitem, uncontained
 
-class SampleContainer(object):
+class SampleContainer(Contained):
     """Sample container implementation suitable for testing.
 
     It is not suitable, directly as a base class unless the subclass
@@ -54,7 +55,7 @@
         return self.__data.keys()
 
     def __iter__(self):
-        return iter(self.__data.keys())
+        return iter(self.__data)
 
     def __getitem__(self, key):
         '''See interface IReadContainer'''
@@ -82,24 +83,11 @@
 
     has_key = __contains__
 
-    def setObject(self, key, object):
+    def __setitem__(self, key, object):
         '''See interface IWriteContainer'''
-        bad = False
-        if isinstance(key, StringTypes):
-            try:
-                unicode(key)
-            except UnicodeError:
-                bad = True
-        else:
-            bad = True
-        if bad: 
-            raise TypeError("'%s' is invalid, the key must be an "
-                            "ascii or unicode string" % key)
-        if len(key) == 0:
-            raise ValueError("The key cannot be an empty string")
-        self.__data[key] = object
-        return key
+        setitem(self, self.__data.__setitem__, key, object)
 
     def __delitem__(self, key):
         '''See interface IWriteContainer'''
+        uncontained(self.__data[key], self, key)
         del self.__data[key]




More information about the Zope3-Checkins mailing list