Rename calendar into ical to avoid name collisions.

This commit is contained in:
Guillaume Ayoub 2010-02-11 01:41:24 +01:00
parent 9a07ec71d3
commit e1a161edc9
3 changed files with 21 additions and 17 deletions

View File

@ -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."""

View File

@ -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

View File

@ -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"))