iCal bootstrapping using a default URL works

This commit is contained in:
Lukasz Langa 2011-06-01 22:33:18 +02:00
parent 1510e6c194
commit f7868afed1
3 changed files with 12 additions and 6 deletions

View File

@ -169,6 +169,7 @@ class Application(object):
auth = authorization.lstrip("Basic").strip().encode("ascii") auth = authorization.lstrip("Basic").strip().encode("ascii")
user, password = self.decode( user, password = self.decode(
base64.b64decode(auth), environ).split(":") base64.b64decode(auth), environ).split(":")
environ['USER'] = user
else: else:
user = password = None user = password = None
@ -290,7 +291,7 @@ class Application(object):
"DAV": "1, calendar-access", "DAV": "1, calendar-access",
"Content-Type": "text/xml"} "Content-Type": "text/xml"}
answer = xmlutils.propfind( answer = xmlutils.propfind(
environ["PATH_INFO"], content, calendars) environ["PATH_INFO"], content, calendars, environ.get("USER"))
return client.MULTI_STATUS, headers, answer return client.MULTI_STATUS, headers, answer
def proppatch(self, environ, calendars, content): def proppatch(self, environ, calendars, content):

View File

@ -162,7 +162,7 @@ class Calendar(object):
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
self.path = os.path.join(FOLDER, path.replace("/", os.sep)) self.path = os.path.join(FOLDER, path.replace("/", os.sep))
self.local_path = path self.local_path = path if path != '.' else ''
self.is_principal = principal self.is_principal = principal
@classmethod @classmethod

View File

@ -167,7 +167,7 @@ def delete(path, calendar):
return _pretty_xml(multistatus) return _pretty_xml(multistatus)
def propfind(path, xml_request, calendars): def propfind(path, xml_request, calendars, user=None):
"""Read and answer PROPFIND requests. """Read and answer PROPFIND requests.
Read rfc4918-9.1 for info. Read rfc4918-9.1 for info.
@ -183,13 +183,13 @@ def propfind(path, xml_request, calendars):
multistatus = ET.Element(_tag("D", "multistatus")) multistatus = ET.Element(_tag("D", "multistatus"))
for calendar in calendars: for calendar in calendars:
response = _propfind_response(path, calendar, props) response = _propfind_response(path, calendar, props, user)
multistatus.append(response) multistatus.append(response)
return _pretty_xml(multistatus) return _pretty_xml(multistatus)
def _propfind_response(path, item, props): def _propfind_response(path, item, props, user):
is_calendar = isinstance(item, ical.Calendar) is_calendar = isinstance(item, ical.Calendar)
if is_calendar: if is_calendar:
with item.props as cal_props: with item.props as cal_props:
@ -217,10 +217,11 @@ def _propfind_response(path, item, props):
if tag == _tag("D", "getetag"): if tag == _tag("D", "getetag"):
element.text = item.etag element.text = item.etag
elif tag == _tag("D", "principal-URL"): elif tag == _tag("D", "principal-URL"):
# TODO: use a real principal URL, read rfc3744-4.2 for info
tag = ET.Element(_tag("D", "href")) tag = ET.Element(_tag("D", "href"))
if item.owner_url: if item.owner_url:
tag.text = item.owner_url tag.text = item.owner_url
elif user:
tag.text = '/{}/'.format(user)
else: else:
tag.text = path tag.text = path
element.append(tag) element.append(tag)
@ -239,6 +240,10 @@ def _propfind_response(path, item, props):
comp.set("name", component) comp.set("name", component)
element.append(comp) element.append(comp)
# pylint: enable=W0511 # pylint: enable=W0511
elif tag == _tag("D", "current-user-principal") and user:
tag = ET.Element(_tag("D", "href"))
tag.text = '/{}/'.format(user)
element.append(tag)
elif tag == _tag("D", "current-user-privilege-set"): elif tag == _tag("D", "current-user-privilege-set"):
privilege = ET.Element(_tag("D", "privilege")) privilege = ET.Element(_tag("D", "privilege"))
privilege.append(ET.Element(_tag("D", "all"))) privilege.append(ET.Element(_tag("D", "all")))