[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - IContainer.py:1.1.2.7 SampleContainer.py:1.1.2.8

Jim Fulton jim@zope.com
Sat, 8 Jun 2002 13:15:25 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	IContainer.py SampleContainer.py 
Log Message:
Refactored isAddable method out of IContainer into a separate, more
specilized interface. This part of the framework needs more thought,
but, in any case, containers that don't need to restrict their content
(or that restrict it in other ways) shouldn't be burdened by this part
of the interface.

I also rewrote IContainer doc strings to conform to coding style.


=== Zope3/lib/python/Zope/App/OFS/Container/IContainer.py 1.1.2.6 => 1.1.2.7 ===
 
 class IReadContainer(Interface):
-    """An interface for the read aspects of a container. For all methods
-       that return a sequence of values, the return value is guaranteed to
-       support the read-only semantics of a Python sequence (indexing,
-       slicing, len). The return value is not, however, required to be an
-       actual native sequence type (list or tuple).
+    """Readable content containers
+
+       For all methods that return a sequence of values, the return
+       value is guaranteed to support the read-only semantics of a
+       Python sequence (indexing, slicing, len). The return value is
+       not, however, required to be an actual native sequence type
+       (list or tuple).
 
        Note that the IReadContainer interface implies a collection of
        objects that are exposed via various publishing mechanisms.
-       Collections of object that *do not* want to be traversed
-       should not implement this."""
+       Collections of object that *do not* want to be traversed should
+       not implement this.
+
+       """
 
     def objectIds():
-        """Return a sequence-like object containing the names of the
-           objects that appear in the container."""
+        """Return a sequence of ids used in the container
+
+           Return a sequence-like object containing the names of the
+           objects that appear in the container.
+
+           """
 
     def objectValues():
-        """Return a sequence-like object containing the objects that
-           appear in the container."""
+        """Return a sequence of the values in the container
+
+           Return a sequence-like object containing the objects that
+           appear in the container.
+
+           """
 
     def objectItems():
-        """Return a sequence-like object containing tuples of the form
-           (name, object) for the objects that appear in the container."""
+        """Return a sequence of id-object pairs
+
+           Return a sequence-like object containing tuples of the form
+           (name, object) for the objects that appear in the container.
+
+           """
+
+    def getObject(name):
+        """Return the named object.
+        
+           If the named object is not found, KeyError is raised.
+
+           """
 
-    def getObject(name, default=KeyError):
+    def queryObject(name, default=None):
         """Return the named object.
         
-           If the named object is not found, KeyError is raised,
-           if that is the default value; any other value for default will
-           instead be returned, with no exception raised"""
+           If the named object is not found, the default is returned
+
+           """
 
     def hasObject(name):
         """Return true if the named object appears in the container."""
@@ -67,11 +90,23 @@
         """
 
     def delObject(name):
-        """Delete the named object from the container. Raises a KeyError
-           if the object is not found."""
-    
+        """Delete the named object from the container.
+
+        TheRaises a KeyError if the object is not found.
+
+        """
+
+class IContainer(IReadContainer, IWriteContainer):
+    """Readable and writable content container."""
+
+
+class IHomogenousContainer(Interface):
+
+    # XXX this needs to be rethought a bit.
     def isAddable(interfaces):
-        """Tells you whether something that implements the given
+        """Test for interface compatability for container and factory
+
+        Tells you whether something that implements the given
         interfaces may be added to this container.
 
         The argument may be a single interface, a tuple of interfaces,
@@ -82,6 +117,3 @@
         of the given interfaces may be added to this container.
         Otherwise, returns false."""
 
-
-class IContainer(IReadContainer, IWriteContainer):
-    """The interface for working with a readable and writable container."""


=== Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py 1.1.2.7 => 1.1.2.8 ===
         if type(name) in StringTypes and len(name)==0:
             raise ValueError("The id cannot be an empty string")
-        if not self.isAddable(getattr(object,'__implements__', None)):
-            raise UnaddableError (self, object, name)
         self.__data[name] = object
-
-    def isAddable(self, interfaces):
-        '''See interface IWriteContainer'''
-        return 1
 
     def delObject(self, name):
         '''See interface IWriteContainer'''