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 import BaseHTTPServer as server
# pylint: enable-msg=F0401 # pylint: enable-msg=F0401
from radicale import acl, calendar, config, xmlutils from radicale import acl, config, ical, xmlutils
def _check(request, function): def _check(request, function):
@ -105,12 +105,12 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
@property @property
def _calendar(self): 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 # ``normpath`` should clean malformed and malicious request paths
attributes = os.path.normpath(self.path.strip("/")).split("/") attributes = os.path.normpath(self.path.strip("/")).split("/")
if len(attributes) >= 2: if len(attributes) >= 2:
path = "%s/%s" % (attributes[0], attributes[1]) path = "%s/%s" % (attributes[0], attributes[1])
return calendar.Calendar(path) return ical.Calendar(path)
def _decode(self, text): def _decode(self, text):
"""Try to decode text according to various parameters.""" """Try to decode text according to various parameters."""

View File

@ -42,6 +42,15 @@ def open(path, mode="r"):
# pylint: enable-msg=W0622 # 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): class Header(object):
"""Internal header class.""" """Internal header class."""
def __init__(self, text): def __init__(self, text):
@ -180,13 +189,7 @@ class Calendar(object):
if not os.path.exists(os.path.dirname(self.path)): if not os.path.exists(os.path.dirname(self.path)):
os.makedirs(os.path.dirname(self.path)) os.makedirs(os.path.dirname(self.path))
text = "\n".join(( text = serialize(headers, timezones, events, todos)
"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"))
return open(self.path, "w").write(text) return open(self.path, "w").write(text)
@property @property

View File

@ -175,10 +175,7 @@ def report(xml_request, calendar, url):
# is that really what is needed? # is that really what is needed?
# Read rfc4791-9.[6|10] for info # Read rfc4791-9.[6|10] for info
for hreference in hreferences: for hreference in hreferences:
headers = ical.headers(calendar.text) objects = calendar.events + calendar.todos
timezones = ical.timezones(calendar.text)
objects = ical.events(calendar.text) + ical.todos(calendar.text)
if not objects: if not objects:
# TODO: Read rfc4791-9.[6|10] to find a right answer # 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: if _tag("C", "calendar-data") in props:
element = ET.Element(_tag("C", "calendar-data")) element = ET.Element(_tag("C", "calendar-data"))
# TODO: Maybe assume that events and todos are not the same if isinstance(obj, ical.Event):
element.text = ical.write_calendar(headers, timezones, [obj]) 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) prop.append(element)
status = ET.Element(_tag("D", "status")) status = ET.Element(_tag("D", "status"))