1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 # Copyright (c) 1999 Christian Scholz (ruebe@aachen.heimat.de)
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 import xml.dom.minidom
24 domimpl = xml.dom.minidom.getDOMImplementation()
28 from DAV.propfind import PROPFIND
32 super_mk_prop_response = PROPFIND.mk_prop_response
33 def mk_prop_response(self, uri, good_props, bad_props, doc):
34 """ make a new <prop> result element
36 We differ between the good props and the bad ones for
37 each generating an extra <propstat>-Node (for each error
41 re=doc.createElement("D:response")
42 # append namespaces to response
44 for nsname in self.namespaces:
45 re.setAttribute("xmlns:ns"+str(nsnum),nsname)
48 # write href information
49 uparts=urlparse.urlparse(uri)
51 if isinstance(fileloc, unicode):
52 fileloc = fileloc.encode('utf-8')
53 href=doc.createElement("D:href")
54 davpath = self._dataclass.parent.get_davpath()
55 hurl = '%s://%s%s%s' % (uparts[0], uparts[1], davpath, urllib.quote(fileloc))
56 huri=doc.createTextNode(hurl)
57 href.appendChild(huri)
60 # write good properties
61 ps=doc.createElement("D:propstat")
65 gp=doc.createElement("D:prop")
66 for ns in good_props.keys():
67 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
68 for p,v in good_props[ns].items():
71 pe=doc.createElement(ns_prefix+str(p))
72 if hasattr(v, '__class__') and v.__class__.__name__ == 'Element':
77 ve=doc.createElement("D:collection")
80 ve=doc.createTextNode(tools.ustr(v))
86 s=doc.createElement("D:status")
87 t=doc.createTextNode("HTTP/1.1 200 OK")
92 # now write the errors!
93 if len(bad_props.items()):
95 # write a propstat for each error code
96 for ecode in bad_props.keys():
97 ps=doc.createElement("D:propstat")
99 bp=doc.createElement("D:prop")
102 for ns in bad_props[ecode].keys():
103 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
105 for p in bad_props[ecode][ns]:
106 pe=doc.createElement(ns_prefix+str(p))
109 s=doc.createElement("D:status")
110 t=doc.createTextNode(utils.gen_estring(ecode))
115 # return the new response element
119 def mk_propname_response(self,uri,propnames,doc):
120 """ make a new <prop> result element for a PROPNAME request
122 This will simply format the propnames list.
123 propnames should have the format {NS1 : [prop1, prop2, ...], NS2: ...}
126 re=doc.createElement("D:response")
128 # write href information
129 uparts=urlparse.urlparse(uri)
131 if isinstance(fileloc, unicode):
132 fileloc = fileloc.encode('utf-8')
133 href=doc.createElement("D:href")
134 davpath = self._dataclass.parent.get_davpath()
135 hurl = '%s://%s%s%s' % (uparts[0], uparts[1], davpath, urllib.quote(fileloc))
136 huri=doc.createTextNode(hurl)
137 href.appendChild(huri)
140 ps=doc.createElement("D:propstat")
143 for ns,plist in propnames.items():
145 pr=doc.createElement("D:prop")
147 pr.setAttribute("xmlns:"+nsp,ns)
150 # write propertynames
152 pe=doc.createElement(nsp+":"+p)
160 PROPFIND.mk_prop_response = mk_prop_response
161 PROPFIND.mk_propname_response = mk_propname_response