Support displayname and principal-URL tags in PROPFIND requests

This commit is contained in:
Guillaume Ayoub 2010-09-12 13:13:21 +02:00
parent 873dec1d5d
commit 71819cdb39
3 changed files with 26 additions and 18 deletions

View File

@ -76,6 +76,8 @@ def _check(request, function):
class HTTPServer(server.HTTPServer): class HTTPServer(server.HTTPServer):
"""HTTP server.""" """HTTP server."""
PROTOCOL = "http"
# Maybe a Pylint bug, ``__init__`` calls ``server.HTTPServer.__init__`` # Maybe a Pylint bug, ``__init__`` calls ``server.HTTPServer.__init__``
# pylint: disable=W0231 # pylint: disable=W0231
def __init__(self, address, handler): def __init__(self, address, handler):
@ -87,6 +89,7 @@ class HTTPServer(server.HTTPServer):
class HTTPSServer(HTTPServer): class HTTPSServer(HTTPServer):
"""HTTPS server.""" """HTTPS server."""
PROTOCOL = "https"
def __init__(self, address, handler): def __init__(self, address, handler):
"""Create server by wrapping HTTP socket in an SSL socket.""" """Create server by wrapping HTTP socket in an SSL socket."""
# Fails with Python 2.5, import if needed # Fails with Python 2.5, import if needed
@ -208,7 +211,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
def do_PROPFIND(self): def do_PROPFIND(self):
"""Manage PROPFIND request.""" """Manage PROPFIND request."""
xml_request = self.rfile.read(int(self.headers["Content-Length"])) xml_request = self.rfile.read(int(self.headers["Content-Length"]))
self._answer = xmlutils.propfind(self.path, xml_request, self._calendar) self._answer = xmlutils.propfind(self.path, xml_request, self._calendar, self)
self.send_response(client.MULTI_STATUS) self.send_response(client.MULTI_STATUS)
self.send_header("DAV", "1, calendar-access") self.send_header("DAV", "1, calendar-access")

View File

@ -229,6 +229,11 @@ class Calendar(object):
"""Etag from calendar.""" """Etag from calendar."""
return '"%s"' % hash(self.text) return '"%s"' % hash(self.text)
@property
def name(self):
"""Calendar name."""
return self.path.split(os.path.sep)[-1]
@property @property
def text(self): def text(self):
"""Calendar as plain text.""" """Calendar as plain text."""

View File

@ -80,7 +80,7 @@ def delete(path, calendar):
return ET.tostring(multistatus, config.get("encoding", "request")) return ET.tostring(multistatus, config.get("encoding", "request"))
def propfind(path, xml_request, calendar): def propfind(path, xml_request, calendar, request):
"""Read and answer PROPFIND requests. """Read and answer PROPFIND requests.
Read rfc4918-9.1 for info. Read rfc4918-9.1 for info.
@ -108,24 +108,24 @@ def propfind(path, xml_request, calendar):
prop = ET.Element(_tag("D", "prop")) prop = ET.Element(_tag("D", "prop"))
propstat.append(prop) propstat.append(prop)
if _tag("D", "resourcetype") in props: for tag in props:
element = ET.Element(_tag("D", "resourcetype")) element = ET.Element(tag)
if tag == _tag("D", "resourcetype"):
element.append(ET.Element(_tag("C", "calendar"))) element.append(ET.Element(_tag("C", "calendar")))
prop.append(element) elif tag == _tag("D", "owner"):
if _tag("D", "owner") in props:
element = ET.Element(_tag("D", "owner"))
element.text = calendar.owner element.text = calendar.owner
prop.append(element) elif tag == _tag("D", "getcontenttype"):
if _tag("D", "getcontenttype") in props:
element = ET.Element(_tag("D", "getcontenttype"))
element.text = "text/calendar" element.text = "text/calendar"
prop.append(element) elif tag == _tag("D", "getetag"):
if _tag("D", "getetag") in props:
element = ET.Element(_tag("D", "getetag"))
element.text = calendar.etag element.text = calendar.etag
elif tag == _tag("D", "displayname"):
element.text = calendar.name
elif tag == _tag("D", "principal-URL"):
# TODO: use a real principal URL, read rfc3744-4.2 for info
element.text = "%s://%s%s" % (
request.server.PROTOCOL, request.headers["Host"], request.path)
prop.append(element) prop.append(element)
status = ET.Element(_tag("D", "status")) status = ET.Element(_tag("D", "status"))