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

Jim Fulton jim@zope.com
Sat, 30 Nov 2002 13:34:35 -0500


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

Modified Files:
	IContainer.py ZopeContainerAdapter.py 
Log Message:

Added marker interfaces to indicate containers that will:

- Pick item names if no item is given, and containers that

- Always pick their own item names.

Updates views to take advantage of this information.



=== Zope3/lib/python/Zope/App/OFS/Container/IContainer.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/OFS/Container/IContainer.py:1.6	Mon Nov 18 08:34:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/IContainer.py	Sat Nov 30 13:34:34 2002
@@ -11,8 +11,9 @@
 # FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
-"""
+"""Container interfaces
 
+$Id$
 """
 
 
@@ -57,6 +58,15 @@
 
 class IContainer(IReadContainer, IWriteContainer):
     """Readable and writable content container."""
+
+
+class IOptionalNamesContainer(IContainer):
+    """Containers that will choose names for their items if no names are given
+    """
+
+class IContainerNamesContainer(IContainer):
+    """Containers that always choose names for their items
+    """
 
 class IHomogenousContainer(Interface):
 


=== Zope3/lib/python/Zope/App/OFS/Container/ZopeContainerAdapter.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Container/ZopeContainerAdapter.py:1.2	Mon Nov 18 18:52:58 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/ZopeContainerAdapter.py	Sat Nov 30 13:34:34 2002
@@ -18,6 +18,8 @@
 """
 
 from Zope.App.OFS.Container.IZopeContainer import IZopeContainer
+from Zope.App.OFS.Container.IContainer import IOptionalNamesContainer
+from Zope.App.OFS.Container.IContainer import IContainerNamesContainer
 from Zope.ComponentArchitecture import queryAdapter
 from Zope.Proxy.ContextWrapper import ContextWrapper
 from Zope.Event import publishEvent
@@ -82,16 +84,22 @@
 
     def setObject(self, key, object):
         "See Zope.App.OFS.Container.IZopeContainer.IZopeWriteContainer"
-        
-        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("Item name is not a string.")
+
+        container = self.context
+
+        if not key:
+            if not (IOptionalNamesContainer.isImplementedBy(container)
+                    or IContainerNamesContainer.isImplementedBy(container)):
+                raise ValueError("Empty names are not allowed")
 
         # We remove the proxies from the object before adding it to
         # the container, because we can't store proxies.
         object = removeAllProxies(object)
 
         # Add the object
-        container = self.context
         key = container.setObject(key, object)
 
         # Publish an added event