Minor cleanups

Everything works fine with Apple clients now.
This commit is contained in:
Guillaume Ayoub 2016-08-01 19:00:57 +02:00
parent b517818749
commit 6b30870be5
3 changed files with 11 additions and 20 deletions

View File

@ -321,9 +321,9 @@ class Application:
content = None content = None
if is_valid_user: if is_valid_user:
if function in (self.do_GET, self.do_HEAD, if function in (
self.do_OPTIONS, self.do_PROPFIND, self.do_GET, self.do_HEAD, self.do_OPTIONS,
self.do_REPORT): self.do_PROPFIND, self.do_REPORT):
lock_mode = "r" lock_mode = "r"
else: else:
lock_mode = "w" lock_mode = "w"

View File

@ -385,8 +385,7 @@ class Collection(BaseCollection):
_, directories, _ = next(os.walk(collection._filesystem_path)) _, directories, _ = next(os.walk(collection._filesystem_path))
for sub_path in directories: for sub_path in directories:
if not is_safe_filesystem_path_component(sub_path): if not is_safe_filesystem_path_component(sub_path):
cls.logger.debug( cls.logger.debug("Skipping collection: %s", sub_path)
"Skipping collection: %s", sub_path)
continue continue
full_path = os.path.join(collection._filesystem_path, sub_path) full_path = os.path.join(collection._filesystem_path, sub_path)
if os.path.exists(full_path): if os.path.exists(full_path):
@ -441,8 +440,7 @@ class Collection(BaseCollection):
for href in hrefs: for href in hrefs:
if not is_safe_filesystem_path_component(href): if not is_safe_filesystem_path_component(href):
self.logger.debug( self.logger.debug("Skipping component: %s", href)
"Skipping component: %s", href)
continue continue
path = os.path.join(self._filesystem_path, href) path = os.path.join(self._filesystem_path, href)
if not href.endswith(".props") and os.path.isfile(path): if not href.endswith(".props") and os.path.isfile(path):
@ -560,6 +558,9 @@ class Collection(BaseCollection):
return None return None
items = [] items = []
for href in os.listdir(self._filesystem_path): for href in os.listdir(self._filesystem_path):
if not is_safe_filesystem_path_component(href):
self.logger.debug("Skipping component: %s", href)
continue
path = os.path.join(self._filesystem_path, href) path = os.path.join(self._filesystem_path, href)
if os.path.isfile(path) and not path.endswith(".props"): if os.path.isfile(path) and not path.endswith(".props"):
with open(path, encoding=self.storage_encoding) as fd: with open(path, encoding=self.storage_encoding) as fd:

View File

@ -505,8 +505,7 @@ def delete(path, collection):
return _pretty_xml(multistatus) return _pretty_xml(multistatus)
def propfind(path, xml_request, read_collections, write_collections, def propfind(path, xml_request, read_collections, write_collections, user):
user=None):
"""Read and answer PROPFIND requests. """Read and answer PROPFIND requests.
Read rfc4918-9.1 for info. Read rfc4918-9.1 for info.
@ -552,7 +551,7 @@ def _propfind_response(path, item, props, user, write=False):
# TODO: fix this # TODO: fix this
is_collection = hasattr(item, "list") is_collection = hasattr(item, "list")
if is_collection: if is_collection:
is_leaf = bool(item.list()) is_leaf = bool(item.get_meta("tag"))
collection = item collection = item
else: else:
collection = item.collection collection = item.collection
@ -671,16 +670,7 @@ def _propfind_response(path, item, props, user, write=False):
elif tag == _tag("CS", "getctag"): elif tag == _tag("CS", "getctag"):
element.text = item.etag element.text = item.etag
elif tag == _tag("C", "calendar-timezone"): elif tag == _tag("C", "calendar-timezone"):
timezones = set() element.text = item.get_meta("C:calendar-timezone")
for href, _ in item.list():
event = item.get(href)
if "vtimezone" in event.contents:
for timezone_ in event.vtimezone_list:
timezones.add(timezone_)
timezone_collection = vobject.iCalendar()
for timezone_ in timezones:
timezone_collection.add(timezone_)
element.text = timezone_collection.serialize()
elif tag == _tag("D", "displayname"): elif tag == _tag("D", "displayname"):
element.text = item.get_meta("D:displayname") or item.path element.text = item.get_meta("D:displayname") or item.path
elif tag == _tag("ICAL", "calendar-color"): elif tag == _tag("ICAL", "calendar-color"):