[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - ContainerTraversable.py:1.1.2.5 IContainer.py:1.1.2.6 SampleContainer.py:1.1.2.7 container.zcml:1.1.2.5

Gary Poster garyposter@earthlink.net
Fri, 17 May 2002 13:16:14 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	ContainerTraversable.py IContainer.py SampleContainer.py 
	container.zcml 
Log Message:
1) Fixed some of my own (wrapping) errors in CA and Traversal
2) added IBindingAware interface for services that need to know when they are bound and unbound to a local service manager
3) in subscribables, made event_types into event_type (YAGNI)
4) in subscribables, added ability to unsubscribe per subscription, not just whole-hog
5) in subscribables, added ability to query subscribable for subscriptions of a given subscriber
6) made ISubscribable extremely verbose, to hopefully describe exactly what's going on (see it for more smaller changes)
7) added ISubscriptionAware interface for objects that need to know when they have been subscribed and unsubscribed
8) built out local event service; once there are some views and once I have some more robust tests this *prototype* should by ready to fly.  Note that it is currently a standard service that can be added to any service manager, and thus the design does attempt to address many of the nested service manager issues.
9) as part of this, created the first indirect subscriber (all placeful
subscriptions will usually need to use indirect subscribers in order to retain their context when events are fired): PathSubscriber
10) removed an endless loop between local service managers and  ZopeSecurityPolicy in which both needed the other to function: ZopeSecurityPolicy now explicitly asks for adapters from the global service manager
11) unintentionally retained some of the "default=ComponentLookupError"-type argument signatures from my sandbox, but only within Container and Folder; I won't worry about undoing it though (unless I am otherwise requested) since it seems these interfaces are due for a dict-like overhaul anyway.

Also, if anyone needs a local event service setup for other tests (like the ObjectHub, for instance) see the LocalEventService/tests/EventSetup.py

more tests on the way for the local event service, and for the changes to the subscribable interface



=== Zope3/lib/python/Zope/App/OFS/Container/ContainerTraversable.py 1.1.2.4 => 1.1.2.5 ===
 # 
 ##############################################################################
+"""
+Revision:
+$Id$
+"""
+
+
 from Zope.App.Traversing.ITraversable import ITraversable
 from IContainer import IReadContainer
 from Zope.Exceptions import NotFoundError
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
 
 class ContainerTraversable:
     """Traverses containers via getattr and getObject.
@@ -47,8 +54,11 @@
             # containers know about "method" and "content"
 
             name,namespace = original_name.split(';', 1)
+            if namespace.startswith("ns="): # XXX not very graceful; temporary
+                namespace=namespace[3:]
             
-            if namespace not in ('method', 'content'):
+            # XXX take out the etc if you take out the Services below
+            if namespace not in ('method', 'content', 'etc'): 
                 raise NotFoundError, 'unrecognised namespace "%s" in "%s"' \
                      % (namespace, original_name)
         else:
@@ -63,5 +73,12 @@
             
         if namespace in (None, 'content') and container.hasObject(name):
             return container.getObject(name)
-            
+        
+        # XXX probably shouldn't be here
+        if namespace in (None, 'etc') and name=='Services': 
+            try:
+                return container.getServiceManager()
+            except AttributeError, ComponentLookupError:
+                pass # raise below
+        
         raise NotFoundError, original_name


=== Zope3/lib/python/Zope/App/OFS/Container/IContainer.py 1.1.2.5 => 1.1.2.6 ===
 
 
-_RAISE_KEYERROR = []
+
 
 class IReadContainer(Interface):
     """An interface for the read aspects of a container. For all methods
@@ -40,10 +40,12 @@
         """Return a sequence-like object containing tuples of the form
            (name, object) for the objects that appear in the container."""
 
-    def getObject(name, default=_RAISE_KEYERROR):
-        """Return the named object, or the value of the default argument
-           if given and the named object is not found. If no default is
-           given and the object is not found a KeyError is raised."""
+    def getObject(name, default=KeyError):
+        """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"""
 
     def hasObject(name):
         """Return true if the named object appears in the container."""
@@ -69,11 +71,16 @@
            if the object is not found."""
     
     def isAddable(interfaces):
-        """Given an interface or tuple of interfaces that one object
-        implements (or None, if the object is not a component--that is,
-        if it declares no implementation), returns a true value (an
-        object that implements the full set of the given interfaces is
-        addable to this container) or a false value (is not)."""
+        """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,
+        or None, if the thing you're considering adding declares no
+        interfaces.
+
+        Returns a true value if an object that implements absolutely all
+        of the given interfaces may be added to this container.
+        Otherwise, returns false."""
 
 
 class IContainer(IReadContainer, IWriteContainer):


=== Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.py 1.1.2.6 => 1.1.2.7 ===
 from Exceptions import UnaddableError
 
-_marker = object()
-
 class SampleContainer(object):
     """Sample container implementation suitable for testing.
 
@@ -60,10 +58,10 @@
         '''See interface IReadContainer'''
         return self.__data.keys()
 
-    def getObject(self, name, default=_marker):
+    def getObject(self, name, default=KeyError):
         '''See interface IReadContainer'''
         v = self.__data.get(name, default)
-        if v is _marker:
+        if v is KeyError:
             raise KeyError, name
         return v
 


=== Zope3/lib/python/Zope/App/OFS/Container/container.zcml 1.1.2.4 => 1.1.2.5 ===
    xmlns:xmlrpc='http://namespaces.zope.org/xmlrpc'
    xmlns:vfs='http://namespaces.zope.org/vfs'
+   xmlns:security='http://namespaces.zope.org/security'
 >
 
 <browser:view name="_traverse" 
@@ -16,6 +17,10 @@
 <adapter factory=".ContainerTraversable."
          provides="Zope.App.Traversing.ITraversable."
          for=".IContainer.IReadContainer." />
+
+<security:protectClass name=".ContainerTraverser+"
+         permission_id="Zope.View"
+         names="publishTraverse, browserDefault" />
 
 
 <browser:view name="_traverse"