~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to document_webdav_old/webdav/DAV/davcopy.py

  • Committer: Fabien Pinckaers
  • Date: 2008-12-12 09:09:57 UTC
  • Revision ID: fp@tinyerp.com-20081212090957-cson0n0jove7dt7i
document_webdav

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
    python davserver
 
5
    Copyright (C) 1999 Christian Scholz (ruebe@aachen.heimat.de)
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
 
20
 
 
21
 
 
22
"""
 
23
 
 
24
 
 
25
from xml.dom import ext
 
26
from xml.dom.Document import Document
 
27
 
 
28
import sys
 
29
import string
 
30
import urlparse
 
31
import urllib
 
32
from StringIO import StringIO
 
33
 
 
34
import utils
 
35
from constants import COLLECTION, OBJECT, DAV_PROPS, RT_ALLPROP, RT_PROPNAME, RT_PROP
 
36
from errors import *
 
37
from utils import create_treelist, quote_uri, gen_estring
 
38
 
 
39
class COPY:
 
40
    """ copy resources and eventually create multistatus responses
 
41
 
 
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
 
45
    occur.
 
46
 
 
47
    """
 
48
 
 
49
 
 
50
    def __init__(self,dataclass,src_uri,dst_uri,overwrite):
 
51
        self.__dataclass=dataclass
 
52
        self.__src=src_uri
 
53
        self.__dst=dst_uri
 
54
        self.__overwrite=overwrite
 
55
 
 
56
 
 
57
    def single_action(self):
 
58
        """ copy a normal resources.
 
59
 
 
60
        We try to copy it and return the result code.
 
61
        This is for Depth==0
 
62
 
 
63
        """
 
64
 
 
65
        dc=self.__dataclass
 
66
        base=self.__src
 
67
 
 
68
        ### some basic tests
 
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
 
76
 
 
77
        return dc.copyone(self.__src,self.__dst,self.__overwrite)
 
78
 
 
79
        #return copyone(dc,self.__src,self.__dst,self.__overwrite)
 
80
 
 
81
    def tree_action(self):
 
82
        """ copy a tree of resources (a collection)
 
83
 
 
84
        Here we return a multistatus xml element.
 
85
 
 
86
        """
 
87
        dc=self.__dataclass
 
88
        base=self.__src
 
89
 
 
90
        ### some basic tests
 
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
 
98
        
 
99
        
 
100
        result=dc.copytree(self.__src,self.__dst,self.__overwrite)
 
101
        #result=copytree(dc,self.__src,self.__dst,self.__overwrite)
 
102
 
 
103
        if not result: return None
 
104
 
 
105
        ###
 
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)
 
109
        ###
 
110
 
 
111
        doc = Document(None)
 
112
        ms=doc.createElement("D:multistatus")
 
113
        ms.setAttribute("xmlns:D","DAV:")
 
114
        doc.appendChild(ms)
 
115
 
 
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))
 
122
                st.appendChild(t)
 
123
                hr.appendChild(huri)
 
124
                re.appendChild(hr)
 
125
                re.appendChild(st)
 
126
                ms.appendChild(re)
 
127
 
 
128
        sfile=StringIO()
 
129
        ext.PrettyPrint(doc,stream=sfile)
 
130
        s=sfile.getvalue()
 
131
        sfile.close()
 
132
        return s
 
133