diff --git a/radicale/__init__.py b/radicale/__init__.py index 2e0375a..434d246 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -76,6 +76,8 @@ def _check(request, function): class HTTPServer(server.HTTPServer): """HTTP server.""" + PROTOCOL = "http" + # Maybe a Pylint bug, ``__init__`` calls ``server.HTTPServer.__init__`` # pylint: disable=W0231 def __init__(self, address, handler): @@ -87,6 +89,7 @@ class HTTPServer(server.HTTPServer): class HTTPSServer(HTTPServer): """HTTPS server.""" + PROTOCOL = "https" def __init__(self, address, handler): """Create server by wrapping HTTP socket in an SSL socket.""" # Fails with Python 2.5, import if needed @@ -208,7 +211,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): def do_PROPFIND(self): """Manage PROPFIND request.""" 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_header("DAV", "1, calendar-access") diff --git a/radicale/ical.py b/radicale/ical.py index ef7bc37..4f4f5af 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -229,6 +229,11 @@ class Calendar(object): """Etag from calendar.""" return '"%s"' % hash(self.text) + @property + def name(self): + """Calendar name.""" + return self.path.split(os.path.sep)[-1] + @property def text(self): """Calendar as plain text.""" diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 2ba578b..eeeef5d 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -80,7 +80,7 @@ def delete(path, calendar): 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 rfc4918-9.1 for info. @@ -108,24 +108,24 @@ def propfind(path, xml_request, calendar): prop = ET.Element(_tag("D", "prop")) propstat.append(prop) - if _tag("D", "resourcetype") in props: - element = ET.Element(_tag("D", "resourcetype")) - element.append(ET.Element(_tag("C", "calendar"))) - prop.append(element) + for tag in props: + element = ET.Element(tag) - if _tag("D", "owner") in props: - element = ET.Element(_tag("D", "owner")) - element.text = calendar.owner - prop.append(element) + if tag == _tag("D", "resourcetype"): + element.append(ET.Element(_tag("C", "calendar"))) + elif tag == _tag("D", "owner"): + element.text = calendar.owner + elif tag == _tag("D", "getcontenttype"): + element.text = "text/calendar" + elif tag == _tag("D", "getetag"): + 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) - if _tag("D", "getcontenttype") in props: - element = ET.Element(_tag("D", "getcontenttype")) - element.text = "text/calendar" - prop.append(element) - - if _tag("D", "getetag") in props: - element = ET.Element(_tag("D", "getetag")) - element.text = calendar.etag prop.append(element) status = ET.Element(_tag("D", "status"))