[Zope-CVS] CVS: Packages/Moztop/moztopsupport/dav - copy.py:1.3 move.py:1.2

Sidnei da Silva sidnei@x3ng.com.br
Sun, 30 Mar 2003 10:32:02 -0500


Update of /cvs-repository/Packages/Moztop/moztopsupport/dav
In directory cvs.zope.org:/tmp/cvs-serv17180/moztopsupport/dav

Modified Files:
	copy.py move.py 
Log Message:
Improved COPY and implemented very basic MOVE

=== Packages/Moztop/moztopsupport/dav/copy.py 1.2 => 1.3 ===
--- Packages/Moztop/moztopsupport/dav/copy.py:1.2	Sat Mar 29 16:33:04 2003
+++ Packages/Moztop/moztopsupport/dav/copy.py	Sun Mar 30 10:32:01 2003
@@ -17,7 +17,8 @@
 
 from zope.component import queryAdapter, getAdapter, getView
 from zope.app.interfaces.copypastemove import IObjectCopier
-from zope.app.traversing import getRoot, traverse
+from zope.app.traversing import getRoot, traverse, joinPath
+from zope.app.interfaces.container import IReadContainer
 
 class COPY:
     """COPY handler
@@ -26,19 +27,49 @@
     def __init__(self, context, request):
         self.context = context
         self.request = request
+        self._destination = request.getHeader('destination', '')
+        self._depth = request.getHeader('depth', 'infinity')
+        self._overwrite = request.getHeader('overwrite', 'T')
+
+    def Destination(self):
+        return self._destination
+
+    def setDestination(self, dest=''):
+        self._destination = dest
+        
+    def Overwrite(self):
+        return self._overwrite
+
+    def setOverwrite(self, overwrite='T'):
+        self._overwrite = overwrite
+
+    def Depth(self):
+        return self._depth
+
+    def setDepth(self, depth='infinity'):
+        self._depth = depth
 
     def COPY(self):
         request = self.request
-        destination = request.getHeader('destination', '')
-        overwrite = request.getHeader('overwrite', 'T')
+        context = self.context
+        destination = self.Destination()
+        depth = self.Depth()
+        if depth not in ['0', '1', 'infinity']:
+            request.response.setStatus(400)
+            return ''
+
+        with_children = depth != '0' and True or False
+        
         if not destination:
             request.response.setStatus(400)
+            return ''
 
         root = getRoot(self.context)
         server_url = str(getView(root, 'absolute_url', self.request))
         path_start = destination.find(server_url)
         if path_start == -1:
             request.response.setStatus(400)
+            return ''
 
         target = destination[len(server_url):]
         target = target.split('/')
@@ -49,6 +80,19 @@
         copier = queryAdapter(self.context, IObjectCopier, None)
         if copier is None:
             request.response.setStatus(403)
-        copier.copyTo(dest, obj_name)
+            return ''
+        copier.copyTo(dest, obj_name, with_children=with_children)
         request.response.setStatus(201)
+        if depth != '0':
+            if IReadContainer.isImplementedBy(context):
+                for id, obj in context.items():
+                    wrapped = ContextWrapper(obj, context, name=id)
+                    copy = queryView(wrapped, 'COPY', request, None)
+                    if copy is None:
+                        request.response.setStatus(412)
+                        return ''
+                    copy.setDestination(joinPath(destination, obj_name))
+                    subdepth = depth == '1' and '0' or 'infinity'
+                    copy.setDepth(subdepth)
+                    copy.COPY()
         return ''


=== Packages/Moztop/moztopsupport/dav/move.py 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/dav/move.py:1.1	Sat Mar 29 12:09:54 2003
+++ Packages/Moztop/moztopsupport/dav/move.py	Sun Mar 30 10:32:01 2003
@@ -15,12 +15,9 @@
 """
 __metaclass__ = type
 
-from zope.app.interfaces.file import IWriteDirectory
-from zope.app.interfaces.file import IDirectoryFactory
-from zope.app.interfaces.container import IZopeWriteContainer
-from zope.app.event import publish
-from zope.app.event.objectevent import ObjectCreatedEvent
-from zope.component import queryAdapter, getAdapter
+from zope.component import queryAdapter, getAdapter, getView
+from zope.app.interfaces.copypastemove import IObjectMover
+from zope.app.traversing import getRoot, traverse
 
 class MOVE:
     """MOVE handler
@@ -33,5 +30,25 @@
     def MOVE(self):
         request = self.request
         destination = request.getHeader('destination', '')
-        request.response.setStatus(403)
+        overwrite = request.getHeader('overwrite', 'T')
+        if not destination:
+            request.response.setStatus(400)
+
+        root = getRoot(self.context)
+        server_url = str(getView(root, 'absolute_url', self.request))
+        path_start = destination.find(server_url)
+        if path_start == -1:
+            request.response.setStatus(400)
+
+        target = destination[len(server_url):]
+        target = target.split('/')
+        target_path = '/'.join(target[:-1])
+        obj_name = target[-1]
+        dest = traverse(root, target_path)
+        
+        mover = queryAdapter(self.context, IObjectMover, None)
+        if mover is None:
+            request.response.setStatus(403)
+        mover.moveTo(dest, obj_name)
+        request.response.setStatus(201)
         return ''