Add support for PROPPATCH requests

This commit is contained in:
Guillaume Ayoub 2011-04-28 18:04:34 +02:00
parent d4cda967c2
commit c1da6872dd
2 changed files with 53 additions and 1 deletions

View File

@ -291,7 +291,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
self.send_response(client.OK)
self.send_header(
"Allow", "DELETE, HEAD, GET, MKCALENDAR, "
"OPTIONS, PROPFIND, PUT, REPORT")
"OPTIONS, PROPFIND, PROPPATCH, PUT, REPORT")
self.send_header("DAV", "1, calendar-access")
self.end_headers()
@ -309,6 +309,18 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(self._answer)
@log_request_content
def do_PROPPATCH(self):
"""Manage PROPPATCH request."""
self._answer = xmlutils.proppatch()
self.send_response(client.MULTI_STATUS)
self.send_header("DAV", "1, calendar-access")
self.send_header("Content-Length", len(self._answer))
self.send_header("Content-Type", "text/xml")
self.end_headers()
self.wfile.write(self._answer)
@log_request_content
@check_rights
def do_PUT(self):

View File

@ -179,6 +179,46 @@ def propfind(path, xml_request, calendar, depth):
return ET.tostring(multistatus, config.get("encoding", "request"))
def proppatch(path, xml_request, calendar):
"""Read and answer PROPPATCH requests.
Read rfc4918-9.2 for info.
"""
# Reading request
root = ET.fromstring(xml_request)
prop_element = root.find(_tag("D", "prop"))
prop_list = prop_element.getchildren()
props = [prop.tag for prop in prop_list]
# Writing answer
multistatus = ET.Element(_tag("D", "multistatus"))
response = ET.Element(_tag("D", "response"))
multistatus.append(response)
href = ET.Element(_tag("D", "href"))
href.text = path
response.append(href)
propstat = ET.Element(_tag("D", "propstat"))
response.append(propstat)
prop = ET.Element(_tag("D", "prop"))
propstat.append(prop)
for tag in props:
element = ET.Element(tag)
prop.append(element)
status = ET.Element(_tag("D", "status"))
status.text = _response(200)
propstat.append(status)
return ET.tostring(multistatus, config.get("encoding", "request"))
def put(path, ical_request, calendar):
"""Read PUT requests."""
name = name_from_path(path, calendar)