1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program 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
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 import xml.dom.minidom
23 domimpl = xml.dom.minidom.getDOMImplementation()
27 from DAV.propfind import PROPFIND
31 super_mk_prop_response = PROPFIND.mk_prop_response
32 def mk_prop_response(self,uri,good_props,bad_props,doc):
33 """ make a new <prop> result element
35 We differ between the good props and the bad ones for
36 each generating an extra <propstat>-Node (for each error
40 re=doc.createElement("D:response")
41 # append namespaces to response
43 for nsname in self.namespaces:
44 re.setAttribute("xmlns:ns"+str(nsnum),nsname)
47 # write href information
48 uparts=urlparse.urlparse(uri)
50 href=doc.createElement("D:href")
51 huri=doc.createTextNode(uparts[0]+'://'+'/'.join(uparts[1:2]) + urllib.quote(fileloc))
52 href.appendChild(huri)
55 # write good properties
56 ps=doc.createElement("D:propstat")
60 gp=doc.createElement("D:prop")
61 for ns in good_props.keys():
62 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
63 for p,v in good_props[ns].items():
66 pe=doc.createElement(ns_prefix+str(p))
67 if hasattr(v, '__class__') and v.__class__.__name__ == 'Element':
72 ve=doc.createElement("D:collection")
75 ve=doc.createTextNode(tools.ustr(v))
81 s=doc.createElement("D:status")
82 t=doc.createTextNode("HTTP/1.1 200 OK")
87 # now write the errors!
88 if len(bad_props.items()):
90 # write a propstat for each error code
91 for ecode in bad_props.keys():
92 ps=doc.createElement("D:propstat")
94 bp=doc.createElement("D:prop")
97 for ns in bad_props[ecode].keys():
98 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
100 for p in bad_props[ecode][ns]:
101 pe=doc.createElement(ns_prefix+str(p))
104 s=doc.createElement("D:status")
105 t=doc.createTextNode(utils.gen_estring(ecode))
110 # return the new response element
114 PROPFIND.mk_prop_response = mk_prop_response