diff --git a/radicale/__init__.py b/radicale/__init__.py index be8aad9..0549f27 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -45,7 +45,7 @@ except ImportError: import BaseHTTPServer as server # pylint: enable-msg=F0401 -from radicale import acl, calendar, config, xmlutils +from radicale import acl, config, ical, xmlutils def _check(request, function): @@ -105,12 +105,12 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @property def _calendar(self): - """The ``calendar.Calendar`` object corresponding to the given path.""" + """The ``ical.Calendar`` object corresponding to the given path.""" # ``normpath`` should clean malformed and malicious request paths attributes = os.path.normpath(self.path.strip("/")).split("/") if len(attributes) >= 2: path = "%s/%s" % (attributes[0], attributes[1]) - return calendar.Calendar(path) + return ical.Calendar(path) def _decode(self, text): """Try to decode text according to various parameters.""" diff --git a/radicale/calendar.py b/radicale/ical.py similarity index 94% rename from radicale/calendar.py rename to radicale/ical.py index e121851..3b19303 100644 --- a/radicale/calendar.py +++ b/radicale/ical.py @@ -42,6 +42,15 @@ def open(path, mode="r"): # pylint: enable-msg=W0622 +def serialize(headers=(), timezones=(), events=(), todos=()): + items = ["BEGIN:VCALENDAR"] + for part in (headers, timezones, todos, events): + if part: + items.append("\n".join(item.text for item in part)) + items.append("END:VCALENDAR") + return "\n".join(items) + + class Header(object): """Internal header class.""" def __init__(self, text): @@ -179,14 +188,8 @@ class Calendar(object): # Create folder if absent if not os.path.exists(os.path.dirname(self.path)): os.makedirs(os.path.dirname(self.path)) - - text = "\n".join(( - "BEGIN:VCALENDAR", - "\n".join([header.text for header in headers]), - "\n".join([timezone.text for timezone in timezones]), - "\n".join([todo.text for todo in todos]), - "\n".join([event.text for event in events]), - "END:VCALENDAR")) + + text = serialize(headers, timezones, events, todos) return open(self.path, "w").write(text) @property diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index abb7497..e22511e 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -175,10 +175,7 @@ def report(xml_request, calendar, url): # is that really what is needed? # Read rfc4791-9.[6|10] for info for hreference in hreferences: - headers = ical.headers(calendar.text) - timezones = ical.timezones(calendar.text) - - objects = ical.events(calendar.text) + ical.todos(calendar.text) + objects = calendar.events + calendar.todos if not objects: # TODO: Read rfc4791-9.[6|10] to find a right answer @@ -216,8 +213,12 @@ def report(xml_request, calendar, url): if _tag("C", "calendar-data") in props: element = ET.Element(_tag("C", "calendar-data")) - # TODO: Maybe assume that events and todos are not the same - element.text = ical.write_calendar(headers, timezones, [obj]) + if isinstance(obj, ical.Event): + element.text = ical.serialize( + calendar.headers, calendar.timezones, events=[obj]) + elif isinstance(obj, ical.Todo): + element.text = ical.serialize( + calendar.headers, calendar.timezones, todos=[obj]) prop.append(element) status = ET.Element(_tag("D", "status"))