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 href=doc.createElement("D:href")
52 davpath = self._dataclass.parent.get_davpath()
53 hurl = '%s://%s%s%s' % (uparts[0], uparts[1], davpath, urllib.quote(fileloc))
54 huri=doc.createTextNode(hurl)
55 href.appendChild(huri)
58 # write good properties
59 ps=doc.createElement("D:propstat")
63 gp=doc.createElement("D:prop")
64 for ns in good_props.keys():
65 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
66 for p,v in good_props[ns].items():
69 pe=doc.createElement(ns_prefix+str(p))
70 if hasattr(v, '__class__') and v.__class__.__name__ == 'Element':
75 ve=doc.createElement("D:collection")
78 ve=doc.createTextNode(tools.ustr(v))
84 s=doc.createElement("D:status")
85 t=doc.createTextNode("HTTP/1.1 200 OK")
90 # now write the errors!
91 if len(bad_props.items()):
93 # write a propstat for each error code
94 for ecode in bad_props.keys():
95 ps=doc.createElement("D:propstat")
97 bp=doc.createElement("D:prop")
100 for ns in bad_props[ecode].keys():
101 ns_prefix="ns"+str(self.namespaces.index(ns))+":"
103 for p in bad_props[ecode][ns]:
104 pe=doc.createElement(ns_prefix+str(p))
107 s=doc.createElement("D:status")
108 t=doc.createTextNode(utils.gen_estring(ecode))
113 # return the new response element
117 def mk_propname_response(self,uri,propnames,doc):
118 """ make a new <prop> result element for a PROPNAME request
120 This will simply format the propnames list.
121 propnames should have the format {NS1 : [prop1, prop2, ...], NS2: ...}
124 re=doc.createElement("D:response")
126 # write href information
127 uparts=urlparse.urlparse(uri)
129 href=doc.createElement("D:href")
130 davpath = self._dataclass.parent.get_davpath()
131 hurl = '%s://%s%s%s' % (uparts[0], uparts[1], davpath, urllib.quote(fileloc))
132 huri=doc.createTextNode(hurl)
133 href.appendChild(huri)
136 ps=doc.createElement("D:propstat")
139 for ns,plist in propnames.items():
141 pr=doc.createElement("D:prop")
143 pr.setAttribute("xmlns:"+nsp,ns)
146 # write propertynames
148 pe=doc.createElement(nsp+":"+p)
156 PROPFIND.mk_prop_response = mk_prop_response
157 PROPFIND.mk_propname_response = mk_propname_response