[Zope3-checkins] CVS: Zope3/src/zope/app/traversing - adapters.py:1.6.10.1 namespace.py:1.10.12.1

Steve Alexander steve@cat-box.net
Fri, 16 May 2003 12:19:11 -0400


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

Modified Files:
      Tag: stevea-decorators-branch
	adapters.py namespace.py 
Log Message:
All unit tests now pass.
Added an ensureContextWrapped function to zope.proxy.context.

In code that uses context wrapping, we have two situations:

  * Code such as traversal code wants to ensure that there is a context-
    wrapper, and set the parent and items in the context dict.
    If there is no context wrapper, it should create one, but if there
    is one already, it should be preserved.

  * Code that is the primary source of some information, and wants to
    wrap it and add minimal information (name, usually) before allowing
    the world to see the information. The zopecontainerdecorator is an
    example of this.

To resolve these situations, the former code should use
ensureContextWrapped, which keeps an existing context wrapper if possible,
and updates the context and adds/overwrites items in the context dict.
The latter code can continue to use ContextWrapper.



=== Zope3/src/zope/app/traversing/adapters.py 1.6 => 1.6.10.1 ===
--- Zope3/src/zope/app/traversing/adapters.py:1.6	Mon Apr 28 09:18:38 2003
+++ Zope3/src/zope/app/traversing/adapters.py	Fri May 16 12:18:40 2003
@@ -23,7 +23,8 @@
 
 from zope.component import getAdapter, queryAdapter
 from zope.proxy.context import getInnerWrapperData, getWrapperContainer
-from zope.proxy.context import ContextWrapper
+from zope.proxy.context import ensureContextWrapped
+from zope.security.proxy import getObject, Proxy
 
 from zope.app.traversing.namespace import namespaceLookup
 from zope.app.traversing.namespace import UnexpectedParameters
@@ -225,7 +226,8 @@
 
     try:
         next_item = traversable.traverse(nm, parms, name, further_path)
-        obj = ContextWrapper(next_item, obj, name=name)
+        # XXX test this
+        obj = ensureContextWrapped(next_item, obj, name=name)
     except NotFoundError:
         if default != _marker:
             return default


=== Zope3/src/zope/app/traversing/namespace.py 1.10 => 1.10.12.1 ===
--- Zope3/src/zope/app/traversing/namespace.py:1.10	Tue Apr 15 05:37:26 2003
+++ Zope3/src/zope/app/traversing/namespace.py	Fri May 16 12:18:40 2003
@@ -18,8 +18,8 @@
 
 from zope.interface import Interface
 from zope.exceptions import NotFoundError
-from zope.proxy.context import ContextWrapper, getWrapperObject
-from zope.proxy.context import getWrapperContext
+from zope.proxy.context import ensureContextWrapped, ContextWrapper
+from zope.proxy.context import getWrapperObject, getWrapperContext
 from zope.configuration.action import Action
 from zope.component import queryAdapter, getAdapter, getServiceManager
 from zope.component import queryDefaultViewName, queryView, getService
@@ -84,12 +84,21 @@
         # For this reason, we'll remove a layer of wrapping from new
         # before we put it in context.
 
-        new = getWrapperObject(new)
+        new = getWrapperObject(object)
 
+        # XXX: I think this says the same as what is said above.
+        # We need a new context wrapper. This wrapper needs to behave the
+        # same way as object, because nothing has happened to object.
+        # It needs to have a new parent, which should be the object that
+        # is having the side-effect applied.
+        #
+        # Perhaps this would be best done with a 'cloneWrapper' function,
+        # and then changing the dict and parent.
+        # As we don't have one of these, this will have to do instead.
         new = ContextWrapper(new, object, name='.', side_effect_name=name)
 
     else:
-        new = ContextWrapper(new, object, name=name)
+        new = ensureContextWrapped(new, object, name=name)
 
     return new
 
@@ -131,7 +140,7 @@
     resource = resource_service.queryResource(ob, name, request)
     if resource is None:
         return default
-    return ContextWrapper(resource, resource_service, name=name)
+    return ensureContextWrapped(resource, resource_service, name=name)
 
 
 # ---- namespace processors below ----
@@ -155,7 +164,9 @@
             except NotFoundError:
                 pass
             else:
-                return ContextWrapper(next, ob, name=name)
+                # XXX: Should this actually be applying a context wrapper?
+                #      The namespaceLookup function should take care of this.
+                return ensureContextWrapped(next, ob, name=name)
 
         ob = getWrapperContext(ob)
         if ob is None: