Merge branch 'master' of git://gitorious.org/radicale/radicale
Conflicts: radicale/xmlutils.py
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Radicale Server - Calendar Server
|
||||
# Copyright © 2008-2010 Guillaume Ayoub
|
||||
# Copyright © 2008-2011 Guillaume Ayoub
|
||||
# Copyright © 2008 Nicolas Kandel
|
||||
# Copyright © 2008 Pascal Halter
|
||||
#
|
||||
@@ -27,8 +27,6 @@ in them for XML requests (all but PUT).
|
||||
|
||||
"""
|
||||
|
||||
# TODO: Manage depth and calendars/collections
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from radicale import client, config, ical, log
|
||||
@@ -54,7 +52,8 @@ def _response(code):
|
||||
def name_from_path(path):
|
||||
"""Return Radicale item name from ``path``."""
|
||||
log.log(10, "Return Radicale item name from ``path``.")
|
||||
return path.split("/")[-1]
|
||||
path_parts = path.strip("/").split("/")
|
||||
return path_parts[-1] if len(path_parts) > 2 else None
|
||||
|
||||
|
||||
def delete(path, calendar):
|
||||
@@ -83,7 +82,7 @@ def delete(path, calendar):
|
||||
return ET.tostring(multistatus, config.get("encoding", "request"))
|
||||
|
||||
|
||||
def propfind(path, xml_request, calendar, depth, request):
|
||||
def propfind(path, xml_request, calendar, depth):
|
||||
"""Read and answer PROPFIND requests.
|
||||
|
||||
Read rfc4918-9.1 for info.
|
||||
@@ -100,23 +99,24 @@ def propfind(path, xml_request, calendar, depth, request):
|
||||
# Writing answer
|
||||
multistatus = ET.Element(_tag("D", "multistatus"))
|
||||
|
||||
if depth == "0":
|
||||
elements = [calendar]
|
||||
elif depth == "1":
|
||||
elements = [calendar] + calendar.events + calendar.todos
|
||||
if calendar:
|
||||
if depth == "0":
|
||||
items = [calendar]
|
||||
else:
|
||||
# depth is 1, infinity or not specified
|
||||
# we limit ourselves to depth == 1
|
||||
items = [calendar] + calendar.events + calendar.todos
|
||||
else:
|
||||
# depth is infinity or not specified
|
||||
# we limit ourselves to depth == 1
|
||||
elements = [calendar] + calendar.events + calendar.todos
|
||||
items = []
|
||||
|
||||
for element in elements:
|
||||
is_calendar = isinstance(element, ical.Calendar)
|
||||
for item in items:
|
||||
is_calendar = isinstance(item, ical.Calendar)
|
||||
|
||||
response = ET.Element(_tag("D", "response"))
|
||||
multistatus.append(response)
|
||||
|
||||
href = ET.Element(_tag("D", "href"))
|
||||
href.text = path if is_calendar else "%s/%s" % (path, element.name)
|
||||
href.text = path if is_calendar else path + item.name
|
||||
response.append(href)
|
||||
|
||||
propstat = ET.Element(_tag("D", "propstat"))
|
||||
@@ -127,36 +127,44 @@ def propfind(path, xml_request, calendar, depth, request):
|
||||
|
||||
for tag in props:
|
||||
element = ET.Element(tag)
|
||||
if tag == _tag("D", "resourcetype"):
|
||||
if is_calendar:
|
||||
tag = ET.Element(_tag("C", "calendar"))
|
||||
element.append(tag)
|
||||
tag = ET.Element(_tag("D", "collection"))
|
||||
element.append(tag)
|
||||
else:
|
||||
tag = ET.Element(_tag("C", "comp"))
|
||||
tag.set("name", element.tag)
|
||||
element.append(tag)
|
||||
if tag == _tag("D", "resourcetype") and is_calendar:
|
||||
tag = ET.Element(_tag("C", "calendar"))
|
||||
element.append(tag)
|
||||
tag = ET.Element(_tag("D", "collection"))
|
||||
element.append(tag)
|
||||
elif tag == _tag("D", "owner"):
|
||||
element.text = calendar.owner
|
||||
elif tag == _tag("D", "getcontenttype"):
|
||||
element.text = "text/calendar"
|
||||
elif tag == _tag("CS", "getctag") and is_calendar:
|
||||
element.text = item.etag
|
||||
elif tag == _tag("D", "getetag"):
|
||||
element.text = element.etag
|
||||
elif tag == _tag("D", "displayname"):
|
||||
element.text = item.etag
|
||||
elif tag == _tag("D", "displayname") and is_calendar:
|
||||
element.text = calendar.name
|
||||
elif tag == _tag("D", "supported-report-set"):
|
||||
supported_report = ET.Element(_tag("D", "supported-report"))
|
||||
report_set = ET.Element(_tag("D", "report"))
|
||||
report_set.append(ET.Element(_tag("C", "calendar-multiget")))
|
||||
supported_report.append(report_set)
|
||||
element.append(supported_report)
|
||||
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)
|
||||
|
||||
tag = ET.Element(_tag("D", "href"))
|
||||
tag.text = path
|
||||
element.append(tag)
|
||||
elif tag in (
|
||||
_tag("D", "principal-collection-set"),
|
||||
_tag("C", "calendar-user-address-set"),
|
||||
_tag("C", "calendar-home-set")):
|
||||
tag = ET.Element(_tag("D", "href"))
|
||||
tag.text = path
|
||||
element.append(tag)
|
||||
elif tag == _tag("C", "supported-calendar-component-set"):
|
||||
comp = ET.Element(_tag("C", "comp"))
|
||||
comp.set("name", "VTODO") # pylint: disable=W0511
|
||||
element.append(comp)
|
||||
comp = ET.Element(_tag("C", "comp"))
|
||||
comp.set("name", "VEVENT")
|
||||
element.append(comp)
|
||||
elif tag == _tag("D", "current-user-privilege-set"):
|
||||
privilege = ET.Element(_tag("D", "privilege"))
|
||||
privilege.append(ET.Element(_tag("D", "all")))
|
||||
element.append(privilege)
|
||||
prop.append(element)
|
||||
|
||||
status = ET.Element(_tag("D", "status"))
|
||||
@@ -192,12 +200,15 @@ def report(path, xml_request, calendar):
|
||||
prop_list = prop_element.getchildren()
|
||||
props = [prop.tag for prop in prop_list]
|
||||
|
||||
if root.tag == _tag("C", "calendar-multiget"):
|
||||
# Read rfc4791-7.9 for info
|
||||
hreferences = set((href_element.text for href_element
|
||||
in root.findall(_tag("D", "href"))))
|
||||
if calendar:
|
||||
if root.tag == _tag("C", "calendar-multiget"):
|
||||
# Read rfc4791-7.9 for info
|
||||
hreferences = set((href_element.text for href_element
|
||||
in root.findall(_tag("D", "href"))))
|
||||
else:
|
||||
hreferences = (path,)
|
||||
else:
|
||||
hreferences = (path,)
|
||||
hreferences = ()
|
||||
|
||||
# Writing answer
|
||||
multistatus = ET.Element(_tag("D", "multistatus"))
|
||||
@@ -228,19 +239,14 @@ def report(path, xml_request, calendar):
|
||||
prop = ET.Element(_tag("D", "prop"))
|
||||
propstat.append(prop)
|
||||
|
||||
if _tag("D", "getetag") in props:
|
||||
element = ET.Element(_tag("D", "getetag"))
|
||||
element.text = item.etag
|
||||
prop.append(element)
|
||||
|
||||
if _tag("C", "calendar-data") in props:
|
||||
element = ET.Element(_tag("C", "calendar-data"))
|
||||
if isinstance(item, ical.Event):
|
||||
element.text = ical.serialize(
|
||||
calendar.headers, calendar.timezones + [item])
|
||||
elif isinstance(item, ical.Todo):
|
||||
element.text = ical.serialize(
|
||||
calendar.headers, calendar.timezones + [item])
|
||||
for tag in props:
|
||||
element = ET.Element(tag)
|
||||
if tag == _tag("D", "getetag"):
|
||||
element.text = item.etag
|
||||
elif tag == _tag("C", "calendar-data"):
|
||||
if isinstance(item, (ical.Event, ical.Todo)):
|
||||
element.text = ical.serialize(
|
||||
calendar.headers, calendar.timezones + [item])
|
||||
prop.append(element)
|
||||
|
||||
status = ET.Element(_tag("D", "status"))
|
||||
|
||||
Reference in New Issue
Block a user