[Zope3-checkins] CVS: Zope3/src/zope/app/container - copypastemove.py:1.5.14.1

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


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

Modified Files:
      Tag: stevea-decorators-branch
	copypastemove.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/container/copypastemove.py 1.5 => 1.5.14.1 ===
--- Zope3/src/zope/app/container/copypastemove.py:1.5	Mon Mar 31 09:48:40 2003
+++ Zope3/src/zope/app/container/copypastemove.py	Fri May 16 12:18:39 2003
@@ -27,7 +27,7 @@
 from zope.component import getAdapter
 from zope.proxy.introspection import removeAllProxies
 from zope.app.event.objectevent import ObjectModifiedEvent
-from zope.proxy.context import ContextWrapper
+from zope.proxy.context import ContextWrapper, ensureContextWrapped
 from zope.app.event import publish
 from zope.proxy.introspection import removeAllProxies
 from types import StringTypes
@@ -115,7 +115,8 @@
         container = self.context
 
         object = container[key]
-        object = ContextWrapper(object, container, name=key)
+        # XXX: is this context wrapping needed?
+        object = ensureContextWrapped(object, container, name=key)
 
         # here, we dont call the before delete hook
         del container[key]