[Zope3-checkins] CVS: Zope3/src/zope/app/container - configure.zcml:1.10 copypastemove.py:1.5
Sidnei da Silva
sidnei@x3ng.com.br
Mon, 31 Mar 2003 09:49:11 -0500
Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv18980/src/zope/app/container
Modified Files:
configure.zcml copypastemove.py
Log Message:
Refactored feature of getting a copy without children into separate adapters and interfaces. With tests :)
=== Zope3/src/zope/app/container/configure.zcml 1.9 => 1.10 ===
--- Zope3/src/zope/app/container/configure.zcml:1.9 Mon Feb 17 10:10:39 2003
+++ Zope3/src/zope/app/container/configure.zcml Mon Mar 31 09:48:40 2003
@@ -47,6 +47,13 @@
/>
<adapter
+ provides="zope.app.interfaces.container.INoChildrenCopySource"
+ for="zope.app.interfaces.content.folder.IFolder"
+ permission="zope.ManageContent"
+ factory="zope.app.container.copypastemove.NoChildrenCopySource"
+ />
+
+ <adapter
provides="zope.app.interfaces.container.IMoveSource"
for="zope.app.interfaces.content.folder.IFolder"
permission="zope.ManageContent"
=== Zope3/src/zope/app/container/copypastemove.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/container/copypastemove.py:1.4 Sun Mar 30 10:40:58 2003
+++ Zope3/src/zope/app/container/copypastemove.py Mon Mar 31 09:48:40 2003
@@ -20,7 +20,7 @@
from zope.app.interfaces.container import IOptionalNamesContainer
from zope.app.interfaces.container import IContainerNamesContainer
from zope.app.interfaces.container import IMoveSource
-from zope.app.interfaces.container import ICopySource
+from zope.app.interfaces.container import ICopySource, INoChildrenCopySource
from zope.app.interfaces.container import IPasteTarget
from zope.app.interfaces.container import IPasteNamesChooser
from zope.app.interfaces.content.folder import ICloneWithoutChildren
@@ -132,7 +132,7 @@
def __init__(self, container):
self.context = container
- def copyObject(self, key, copyingTo, with_children=True):
+ def copyObject(self, key, copyingTo):
'''Return the object with the given key, as the first part of a
copy.
@@ -141,13 +141,29 @@
value = self.context.get(key, None)
if value is not None:
value = removeAllProxies(value)
- if with_children:
- value = copy.deepcopy(value)
- else:
- if ICloneWithoutChildren.isImplementedBy(value):
- value = value.cloneWithoutChildren()
- else:
- raise NotImplementedError(value, ICloneWithoutChildren)
+ value = copy.deepcopy(value)
+ return ContextWrapper(value, self.context, name=key)
+
+
+class NoChildrenCopySource:
+
+ __implements__ = INoChildrenCopySource
+
+ def __init__(self, container):
+ self.context = container
+
+ def copyObjectWithoutChildren(self, key, copyingTo):
+ '''Return the object with the given key, without children, as
+ the first part of a copy.
+
+ copyingTo is the unicode path for where the copy is to.
+ '''
+ value = self.context.get(key, None)
+ if value is not None:
+ value = removeAllProxies(value)
+ if not ICloneWithoutChildren.isImplementedBy(value):
+ return None
+ value = value.cloneWithoutChildren()
return ContextWrapper(value, self.context, name=key)
class PasteNamesChooser: