[Zope3-checkins] CVS: Zope3/src/zope/app - configure.zcml:1.35.2.2
copypastemove.py:1.10.24.3 location.py:1.1.2.8 zapi.py:1.10.2.3
Jim Fulton
jim at zope.com
Fri Sep 12 15:16:07 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv13470/src/zope/app
Modified Files:
Tag: parentgeddon-branch
configure.zcml copypastemove.py location.py zapi.py
Log Message:
Can't have the tests passing, can we?
=== Zope3/src/zope/app/configure.zcml 1.35.2.1 => 1.35.2.2 ===
--- Zope3/src/zope/app/configure.zcml:1.35.2.1 Mon Sep 8 14:21:18 2003
+++ Zope3/src/zope/app/configure.zcml Fri Sep 12 15:15:05 2003
@@ -77,12 +77,6 @@
for="*" />
<adapter
- factory="zope.app.copypastemove.NoChildrenObjectCopier"
- provides="zope.app.interfaces.copypastemove.INoChildrenObjectCopier"
- permission="zope.ManageContent"
- for="zope.app.interfaces.content.folder.IFolder" />
-
- <adapter
factory="zope.app.copypastemove.PrincipalClipboard"
provides="zope.app.interfaces.copypastemove.IPrincipalClipboard"
for="zope.app.interfaces.annotation.IAnnotations" />
=== Zope3/src/zope/app/copypastemove.py 1.10.24.2 => 1.10.24.3 ===
--- Zope3/src/zope/app/copypastemove.py:1.10.24.2 Tue Sep 9 14:08:17 2003
+++ Zope3/src/zope/app/copypastemove.py Fri Sep 12 15:15:05 2003
@@ -18,19 +18,11 @@
"""
from zope.app import zapi
+from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.copypastemove import IObjectMover
from zope.app.interfaces.copypastemove import IObjectCopier
-from zope.app.interfaces.copypastemove import INoChildrenObjectCopier
from zope.app.interfaces.container import IAddNotifiable
-from zope.app.interfaces.container import IDeleteNotifiable
-from zope.app.interfaces.container import IMoveNotifiable
-from zope.app.interfaces.container import ICopyNotifiable
-from zope.app.interfaces.container import IMoveSource
-from zope.app.interfaces.container import ICopySource, INoChildrenCopySource
-from zope.app.interfaces.container import CopyException
-from zope.app.interfaces.container import IPasteTarget
-from zope.app.event.objectevent import ObjectMovedEvent, ObjectCopiedEvent
-from zope.app.event import publish
+from zope.app.interfaces.container import INameChooser
from zope.proxy import removeAllProxies
from zope.interface import implements
from zope.exceptions import NotFoundError, DuplicationError
@@ -50,40 +42,24 @@
Typically, the target is adapted to IPasteTarget.'''
obj = self.context
- container = zapi.getParent(obj)
- orig_name = zapi.getName(obj)
+ container = obj.__parent__
+
+ # XXX Only allow moving between the same types of containers for
+ # now, until we can properly implement containment constraints:
+ if target.__class__ != container.__class__:
+ raise zapi.UserError(
+ _("Can only move objects between like containers")
+ )
+
+ orig_name = obj.__name__
if new_name is None:
new_name = orig_name
- movesource = zapi.getAdapter(container, IMoveSource)
- target_path = zapi.getPath(target)
- source_path = zapi.getPath(container)
-
- if zapi.queryAdapter(obj, IMoveNotifiable):
- zapi.getAdapter(obj, IMoveNotifiable).beforeDeleteHook(
- obj, container, movingTo=target_path)
- elif zapi.queryAdapter(obj, IDeleteNotifiable):
- zapi.getAdapter(obj, IDeleteNotifiable
- ).beforeDeleteHook(obj, container)
-
- new_obj = movesource.removeObject(orig_name, target)
- pastetarget = zapi.getAdapter(target, IPasteTarget)
- # publish an ObjectCreatedEvent (perhaps...?)
- new_name = pastetarget.pasteObject(new_name, new_obj)
-
- # call afterAddHook
- if zapi.queryAdapter(new_obj, IMoveNotifiable):
- zapi.getAdapter(new_obj, IMoveNotifiable).afterAddHook(
- new_obj, container, movedFrom=source_path)
- elif zapi.queryAdapter(new_obj, IAddNotifiable):
- zapi.getAdapter(new_obj, IAddNotifiable).afterAddHook(
- new_obj, container)
-
- # publish ObjectMovedEvent
- publish(container, ObjectMovedEvent(
- container, source_path, target_path))
+ chooser = zapi.getAdapter(target, INameChooser)
+ new_name = chooser.chooseName(new_name, obj)
- return new_name
+ target[new_name] = obj
+ del container[orig_name]
def moveable(self):
'''Returns True if the object is moveable, otherwise False.'''
@@ -95,11 +71,7 @@
Returns True if it can be moved there. Otherwise, returns
false.
'''
- obj = self.context
- if name is None:
- name = zapi.getName(obj)
- pastetarget = zapi.getAdapter(target, IPasteTarget)
- return pastetarget.acceptsObject(name, obj)
+ return obj.__parent__.__class__ is target.__class__
class ObjectCopier:
@@ -120,33 +92,19 @@
an IObjectCreated event should be published.
"""
obj = self.context
- container = zapi.getParent(obj)
- orig_name = zapi.getName(obj)
+ container = obj.__parent__
+ orig_name = obj.__name__
if new_name is None:
new_name = orig_name
- target_path = zapi.getPath(target)
- source_path = zapi.getPath(container)
+ chooser = zapi.getAdapter(target, INameChooser)
+ new_name = chooser.chooseName(new_name, obj)
- copysource = zapi.getAdapter(container, ICopySource)
- obj = copysource.copyObject(orig_name, target_path)
+ copy = removeAllProxies(obj)
+ cppy = locationCopy(value)
+ publish(target, ObjectCopiedEvent(copy))
- pastetarget = zapi.getAdapter(target, IPasteTarget)
- # publish an ObjectCreatedEvent (perhaps...?)
- new_name = pastetarget.pasteObject(new_name, obj)
-
- # call afterAddHook
- if zapi.queryAdapter(obj, ICopyNotifiable):
- zapi.getAdapter(obj, ICopyNotifiable).afterAddHook(
- obj, container, copiedFrom=source_path)
- elif zapi.queryAdapter(obj, IAddNotifiable):
- zapi.getAdapter(obj, IAddNotifiable).afterAddHook(obj, container)
-
- # publish ObjectCopiedEvent
- publish(container,
- ObjectCopiedEvent(container, source_path, target_path))
-
- return new_name
+ target[new_name] = copy
def copyable(self):
'''Returns True if the object is copyable, otherwise False.'''
@@ -158,63 +116,8 @@
Returns True if it can be copied there. Otherwise, returns
False.
'''
- obj = self.context
- if name is None:
- name = zapi.getName(obj)
- pastetarget = zapi.getAdapter(target, IPasteTarget)
- return pastetarget.acceptsObject(name, obj)
-
-
-class NoChildrenObjectCopier(ObjectCopier):
-
- implements(INoChildrenObjectCopier)
-
- def __init__(self, object):
- self.context = object
-
- def copyTo(self, target, new_name=None):
- """Copy this object but not its children to the target given.
-
- Returns the new name within the target, or None
- if the target doesn't do names.
- Typically, the target is adapted to IPasteTarget.
- After the copy is added to the target container, publish
- an IObjectCopied event in the context of the target container.
- If a new object is created as part of the copying process, then
- an IObjectCreated event should be published.
- """
- obj = self.context
- container = zapi.getParent(obj)
- orig_name = zapi.getName(obj)
- if new_name is None:
- new_name = orig_name
-
- target_path = zapi.getPath(target)
- source_path = zapi.getPath(container)
-
- copysource = zapi.getAdapter(container, INoChildrenCopySource)
- obj = copysource.copyObjectWithoutChildren(orig_name, target_path)
- if obj is None:
- raise CopyException(container, orig_name,
- 'Could not get a copy without children of %s'
- % orig_name)
-
- pastetarget = zapi.getAdapter(target, IPasteTarget)
- # publish an ObjectCreatedEvent (perhaps...?)
- new_name = pastetarget.pasteObject(new_name, obj)
-
- # call afterAddHook
- if zapi.queryAdapter(obj, ICopyNotifiable):
- zapi.getAdapter(obj, ICopyNotifiable).afterAddHook(
- obj, container, copiedFrom=source_path)
- elif zapi.queryAdapter(obj, IAddNotifiable):
- zapi.getAdapter(obj, IAddNotifiable).afterAddHook(obj, container)
-
- # publish ObjectCopiedEvent
- publish(container, ObjectCopiedEvent(
- container, source_path, target_path))
+ return obj.__parent__.__class__ is target.__class__
- return new_name
class PrincipalClipboard:
'''Principal clipboard
@@ -257,7 +160,4 @@
raise DuplicationError("name, %s, is already in use" % newid)
if mover.moveable() and mover.moveableTo(container, newid):
- # the mover will call beforeDeleteHook hook for us
mover.moveTo(container, newid)
- # the mover will call the afterAddHook hook for us
- # the mover will publish an ObjectMovedEvent for us
=== Zope3/src/zope/app/location.py 1.1.2.7 => 1.1.2.8 ===
--- Zope3/src/zope/app/location.py:1.1.2.7 Fri Sep 12 11:38:28 2003
+++ Zope3/src/zope/app/location.py Fri Sep 12 15:15:05 2003
@@ -23,6 +23,9 @@
from zope.app.interfaces.traversing import IContainmentRoot
from zope.app.interfaces.traversing import ITraverser
from zope.proxy import removeAllProxies
+from zope.proxy import ProxyBase, getProxiedObject
+from zope.app.decorator import DecoratorSpecificationDescriptor
+from zope.app.decorator import DecoratedSecurityCheckerDescriptor
import cPickle
import tempfile
@@ -433,6 +436,56 @@
raise ValueError("ZPersistent paths must be absolute", path)
root = LocationPhysicallyLocatable(self.location).getRoot()
return zapi.getAdapter(root, ITraverser).traverse(path[1:])
+
+
+class LocationProxy(ProxyBase):
+ """Contained-object proxy
+
+ This is a picklable proxy that can be put around objects that
+ don't implemeny IContained.
+
+ >>> l = [1, 2, 3]
+ >>> p = ContainedProxy(l, "Dad", "p")
+ >>> p
+ [1, 2, 3]
+ >>> p.__parent__
+ 'Dad'
+ >>> p.__name__
+ 'p'
+
+ >>> import pickle
+ >>> p2 = pickle.loads(pickle.dumps(p))
+ >>> p2
+ [1, 2, 3]
+ >>> p2.__parent__
+ 'Dad'
+ >>> p2.__name__
+ 'p'
+
+
+ """
+
+ zope.interface.implements(ILocation)
+
+ __slots__ = '__parent__', '__name__'
+ __safe_for_unpickling__ = True
+
+ def __new__(self, ob, container=None, name=None):
+ return ProxyBase.__new__(self, ob)
+
+ def __init__(self, ob, container=None, name=None):
+ ProxyBase.__init__(self, ob)
+ self.__parent__ = container
+ self.__name__ = name
+
+ def __reduce__(self, proto=None):
+ raise TypeError, "Not picklable"
+
+ __reduce_ex__ = __reduce__
+
+ __providedBy__ = DecoratorSpecificationDescriptor()
+
+ __Security_checker__ = DecoratedSecurityCheckerDescriptor()
class TLocation(Location):
=== Zope3/src/zope/app/zapi.py 1.10.2.2 => 1.10.2.3 ===
--- Zope3/src/zope/app/zapi.py:1.10.2.2 Wed Sep 10 18:08:17 2003
+++ Zope3/src/zope/app/zapi.py Fri Sep 12 15:15:05 2003
@@ -36,16 +36,3 @@
from zope.app.interfaces.exceptions import UserError
name = getName
-
-
-from zope.app.interfaces.container import IAddTarget
-def add(container, name, object):
- """Add an object to a container, using an adapter
- """
- return getAdapter(container, IAddTarget).addObject(name, object)
-
-from zope.app.interfaces.container import IRemoveSource
-def remove(container, name, object):
- """Remove an object to a container, using an adapter
- """
- return getAdapter(container, IRemoveSource).removeObject(name)
More information about the Zope3-Checkins
mailing list