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()
30 from DAV.propfind import PROPFIND
32 raise osv.except_osv('PyWebDAV Import Error!','Please install pywebdav \
33 from http://pywebdav.googlecode.com')
37 super_mk_prop_response = PROPFIND.mk_prop_response
38 def mk_prop_response(self,uri,good_props,bad_props,doc):
39 """ make a new <prop> result element
41 We differ between the good props and the bad ones for
42 each generating an extra <propstat>-Node (for each error
46 re=doc.createElement("D:response")
47 # append namespaces to response
49 for nsname in self.namespaces:
50 re.setAttribute("xmlns:ns"+str(nsnum),nsname)
53 # write href information
54 uparts=urlparse.urlparse(uri)
56 href=doc.createElement("D:href")
57 huri=doc.createTextNode(uparts[0]+'://'+'/'.join(uparts[1:2]) + urllib.quote(fileloc))
58 href.appendChild(huri)
61 # write good properties
62 ps=doc.createElement("D:propstat")
66 gp=doc.createElement("D:prop")
67 for ns in good_props.keys():
68 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
69 for p,v in good_props[ns].items():
72 pe=doc.createElement(ns_prefix+str(p))
73 if hasattr(v, '__class__') and v.__class__.__name__ == 'Element':
78 ve=doc.createElement("D:collection")
81 ve=doc.createTextNode(tools.ustr(v))
87 s=doc.createElement("D:status")
88 t=doc.createTextNode("HTTP/1.1 200 OK")
93 # now write the errors!
94 if len(bad_props.items()):
96 # write a propstat for each error code
97 for ecode in bad_props.keys():
98 ps=doc.createElement("D:propstat")
100 bp=doc.createElement("D:prop")
103 for ns in bad_props[ecode].keys():
104 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
106 for p in bad_props[ecode][ns]:
107 pe=doc.createElement(ns_prefix+str(p))
110 s=doc.createElement("D:status")
111 t=doc.createTextNode(utils.gen_estring(ecode))
116 # return the new response element
120 PROPFIND.mk_prop_response = mk_prop_response