5
Copyright (C) 1999 Christian Scholz (ruebe@aachen.heimat.de)
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public
18
License along with this library; if not, write to the Free
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from xml.dom import ext
26
from xml.dom.Document import Document
32
from StringIO import StringIO
35
from constants import COLLECTION, OBJECT, DAV_PROPS, RT_ALLPROP, RT_PROPNAME, RT_PROP
37
from utils import create_treelist, quote_uri, gen_estring
40
""" copy resources and eventually create multistatus responses
42
This module implements the COPY class which is responsible for
43
copying resources. Usually the normal copy work is done in the
44
interface class. This class only creates error messages if error
50
def __init__(self,dataclass,src_uri,dst_uri,overwrite):
51
self.__dataclass=dataclass
54
self.__overwrite=overwrite
57
def single_action(self):
58
""" copy a normal resources.
60
We try to copy it and return the result code.
69
# test if dest exists and overwrite is false
70
if dc.exists(self.__dst) and not self.__overwrite: raise DAV_Error, 412
71
# test if src and dst are the same
72
# (we assume that both uris are on the same server!)
73
ps=urlparse.urlparse(self.__src)[2]
74
pd=urlparse.urlparse(self.__dst)[2]
75
if ps==pd: raise DAV_Error, 403
77
return dc.copyone(self.__src,self.__dst,self.__overwrite)
79
#return copyone(dc,self.__src,self.__dst,self.__overwrite)
81
def tree_action(self):
82
""" copy a tree of resources (a collection)
84
Here we return a multistatus xml element.
91
# test if dest exists and overwrite is false
92
if dc.exists(self.__dst) and not self.__overwrite: raise DAV_Error, 412
93
# test if src and dst are the same
94
# (we assume that both uris are on the same server!)
95
ps=urlparse.urlparse(self.__src)[2]
96
pd=urlparse.urlparse(self.__dst)[2]
97
if ps==pd: raise DAV_Error, 403
100
result=dc.copytree(self.__src,self.__dst,self.__overwrite)
101
#result=copytree(dc,self.__src,self.__dst,self.__overwrite)
103
if not result: return None
106
### create the multistatus XML element
107
### (this is also the same as in delete.py.
108
### we might make a common method out of it)
112
ms=doc.createElement("D:multistatus")
113
ms.setAttribute("xmlns:D","DAV:")
116
for el,ec in result.items():
117
re=doc.createElement("D:response")
118
hr=doc.createElement("D:href")
119
st=doc.createElement("D:status")
120
huri=doc.createTextNode(quote_uri(el))
121
t=doc.createTextNode(gen_estring(ec))
129
ext.PrettyPrint(doc,stream=sfile)