Merge branch 'lightning', restoring the Lightning support

Conflicts:
	radicale/xmlutils.py
This commit is contained in:
Guillaume Ayoub 2011-06-26 13:52:06 +02:00
commit c9aa115119
3 changed files with 22 additions and 16 deletions

View File

@ -166,8 +166,8 @@ class Application(object):
content = None content = None
# Find calendar(s) # Find calendar(s)
items = ical.Calendar.from_path(environ["PATH_INFO"], items = ical.Calendar.from_path(
environ.get("HTTP_DEPTH", "0")) environ["PATH_INFO"], environ.get("HTTP_DEPTH", "0"))
# Get function corresponding to method # Get function corresponding to method
function = getattr(self, environ["REQUEST_METHOD"].lower()) function = getattr(self, environ["REQUEST_METHOD"].lower())

View File

@ -163,7 +163,12 @@ class Calendar(object):
tag = "VCALENDAR" tag = "VCALENDAR"
def __init__(self, path, principal=False): def __init__(self, path, principal=False):
"""Initialize the calendar with ``cal`` and ``user`` parameters.""" """Initialize the calendar.
``path`` must be the normalized relative path of the calendar, using
the slash as the folder delimiter, with no leading nor trailing slash.
"""
self.encoding = "utf-8" self.encoding = "utf-8"
split_path = path.split("/") split_path = path.split("/")
self.owner = split_path[0] if len(split_path) > 1 else None self.owner = split_path[0] if len(split_path) > 1 else None
@ -193,9 +198,8 @@ class Calendar(object):
result = [] result = []
path = "/".join(attributes[:min(len(attributes), 2)]) path = "/".join(attributes[:min(len(attributes), 2)])
path = path.replace("/", os.sep) abs_path = os.path.join(FOLDER, path.replace("/", os.sep))
abs_path = os.path.join(FOLDER, path) if os.path.isdir(abs_path):
if os.path.isdir(abs_path) or len(attributes) == 1:
if depth == "0": if depth == "0":
result.append(cls(path, principal=True)) result.append(cls(path, principal=True))
else: else:
@ -203,11 +207,10 @@ class Calendar(object):
result.append(cls(path, principal=True)) result.append(cls(path, principal=True))
try: try:
for filename in next(os.walk(abs_path))[2]: for filename in next(os.walk(abs_path))[2]:
file_path = os.path.join(path, filename)
if cls.is_vcalendar(os.path.join(abs_path, filename)): if cls.is_vcalendar(os.path.join(abs_path, filename)):
result.append(cls(file_path)) result.append(cls(os.path.join(path, filename)))
except StopIteration: except StopIteration:
# directory does not exist yet # Directory does not exist yet
pass pass
else: else:
calendar = cls(path) calendar = cls(path)
@ -298,8 +301,6 @@ class Calendar(object):
def write(self, headers=None, items=None): def write(self, headers=None, items=None):
"""Write calendar with given parameters.""" """Write calendar with given parameters."""
if self.is_principal:
return
headers = headers or self.headers or ( headers = headers or self.headers or (
Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"), Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
Header("VERSION:2.0")) Header("VERSION:2.0"))
@ -415,11 +416,11 @@ class Calendar(object):
def owner_url(self): def owner_url(self):
"""Get the calendar URL according to its owner.""" """Get the calendar URL according to its owner."""
if self.owner: if self.owner:
return ('/%s/' % self.owner).replace('//', '/') return "/%s/" % self.owner
else: else:
return None return None
@property @property
def url(self): def url(self):
"""Get the standard calendar URL.""" """Get the standard calendar URL."""
return ('/%s/' % self.local_path).replace('//', '/') return "/%s/" % self.local_path

View File

@ -201,7 +201,7 @@ def _propfind_response(path, item, props, user):
response = ET.Element(_tag("D", "response")) response = ET.Element(_tag("D", "response"))
href = ET.Element(_tag("D", "href")) href = ET.Element(_tag("D", "href"))
href.text = item.url if is_calendar else "%s/%s" % (path, item.name) href.text = item.local_path if is_calendar else "%s/%s" % (path, item.name)
response.append(href) response.append(href)
propstat404 = ET.Element(_tag("D", "propstat")) propstat404 = ET.Element(_tag("D", "propstat"))
@ -264,7 +264,9 @@ def _propfind_response(path, item, props, user):
if tag == _tag("D", "getcontenttype"): if tag == _tag("D", "getcontenttype"):
element.text = "text/calendar" element.text = "text/calendar"
elif tag == _tag("D", "resourcetype"): elif tag == _tag("D", "resourcetype"):
if not item.is_principal: if item.is_principal:
tag = ET.Element(_tag("D", "principal"))
element.append(tag)
tag = ET.Element(_tag("C", "calendar")) tag = ET.Element(_tag("C", "calendar"))
element.append(tag) element.append(tag)
tag = ET.Element(_tag("D", "collection")) tag = ET.Element(_tag("D", "collection"))
@ -284,6 +286,9 @@ def _propfind_response(path, item, props, user):
# Not for calendars # Not for calendars
elif tag == _tag("D", "getcontenttype"): elif tag == _tag("D", "getcontenttype"):
element.text = "text/calendar; component=%s" % item.tag.lower() element.text = "text/calendar; component=%s" % item.tag.lower()
elif tag == _tag("D", "resourcetype"):
# resourcetype must be returned empty for non-collection elements
pass
else: else:
is404 = True is404 = True