[Zope3-checkins] CVS: Zope3/src/zope/app/publication - publicationtraverse.py:1.6.8.1

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


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

Modified Files:
      Tag: stevea-decorators-branch
	publicationtraverse.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/publication/publicationtraverse.py 1.6 => 1.6.8.1 ===
--- Zope3/src/zope/app/publication/publicationtraverse.py:1.6	Thu May  1 15:35:26 2003
+++ Zope3/src/zope/app/publication/publicationtraverse.py	Fri May 16 12:18:40 2003
@@ -19,7 +19,8 @@
 from zope.component import queryView
 from zope.publisher.interfaces import NotFound
 from types import StringTypes
-from zope.proxy.context import ContextWrapper
+#from zope.proxy.context import ContextWrapper
+from zope.app.traversing.adapters import ensureContextWrapped
 from zope.security.checker import ProxyFactory
 
 from zope.proxy.introspection import removeAllProxies
@@ -52,6 +53,7 @@
                     pset(pname, pval, request)
 
             if ns:
+                # namespaceLookup takes care of its own context-wrapping
                 ob2 = namespaceLookup(name, ns, nm, unknown_parms, ob, request)
                 return ProxyFactory(ob2)
 
@@ -78,7 +80,7 @@
             else:
                 raise NotFound(ob, name, request)
 
-        return ProxyFactory(ContextWrapper(ob2, ob, name=name))
+        return ProxyFactory(ensureContextWrapped(ob2, ob, name=name))
 
 class PublicationTraverser(PublicationTraverse):