From 1c6e6269794323b805363a83b70087f32d74ac5e Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 13 Aug 2016 04:47:35 +0200 Subject: [PATCH 1/4] Simplify name_from_path and add error check --- radicale/xmlutils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index fcedf7d..4d01ea1 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -419,12 +419,11 @@ def _param_filter_match(vobject_item, filter_, parent_name): def name_from_path(path, collection): """Return Radicale item name from ``path``.""" - collection_path = collection.path.strip("/") - collection_parts = collection_path.split("/") if collection_path else [] - path = path.strip("/") - path_parts = path.split("/") if path else [] - if len(path_parts) - len(collection_parts): - return path_parts[-1] + path = path.strip("/") + "/" + start = collection.path + "/" + if not path.startswith(start): + raise ValueError("'%s' doesn't start with '%s'" % (path, start)) + return path[len(start):] def props_from_request(root, actions=("set", "remove")): From ecd0a162145e0c9ef9b6d082afbcef2769df1608 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 13 Aug 2016 04:48:59 +0200 Subject: [PATCH 2/4] Remove unused variable path --- radicale/xmlutils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 4d01ea1..92b3450 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -791,7 +791,6 @@ def report(path, xml_request, collection): name = name_from_path(hreference, collection) if name: # Reference is an item - path = "/".join(hreference.split("/")[:-1]) + "/" item = collection.get(name) if item is None: response = _item_response(hreference, found_item=False) @@ -800,7 +799,6 @@ def report(path, xml_request, collection): items = [item] else: # Reference is a collection - path = hreference items = collection.pre_filtered_list(filters) for item in items: From 453a8ba636e0a5d91a26bcac06fcc7f0a9aaa8de Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 13 Aug 2016 04:51:42 +0200 Subject: [PATCH 3/4] Fix "fix this" in xmlutils --- radicale/xmlutils.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 92b3450..df12c24 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -33,6 +33,8 @@ from datetime import datetime, timedelta, timezone from http import client from urllib.parse import unquote, urlparse +from . import storage + MIMETYPES = { "VADDRESSBOOK": "text/vcard", @@ -534,8 +536,7 @@ def propfind(path, xml_request, read_collections, write_collections, user): def _propfind_response(path, item, props, user, write=False): """Build and return a PROPFIND response.""" - # TODO: fix this - is_collection = hasattr(item, "list") + is_collection = isinstance(item, storage.BaseCollection) if is_collection: is_leaf = bool(item.get_meta("tag")) collection = item @@ -547,18 +548,11 @@ def _propfind_response(path, item, props, user, write=False): href = ET.Element(_tag("D", "href")) if is_collection: # Some clients expect collections to end with / - uri = item.path + "/" + uri = "/%s/" % item.path if item.path else "/" else: - # TODO: fix this - if path.split("/")[-1] == item.href: - # Happening when depth is 0 - uri = path - else: - # Happening when depth is 1 - uri = "/".join((path, item.href)) + uri = "/" + posixpath.join(collection.path, item.href) - # TODO: fix this - href.text = _href(collection, uri.replace("//", "/")) + href.text = _href(collection, uri) response.append(href) propstat404 = ET.Element(_tag("D", "propstat")) @@ -831,13 +825,7 @@ def report(path, xml_request, collection): else: not_found_props.append(element) - # TODO: fix this - if hreference.split("/")[-1] == item.href: - # Happening when depth is 0 - uri = hreference - else: - # Happening when depth is 1 - uri = posixpath.join(hreference, item.href) + uri = "/" + posixpath.join(collection.path, item.href) multistatus.append(_item_response( uri, found_props=found_props, not_found_props=not_found_props, found_item=True)) From 469efbb0327dbaabb32d58be72d04f2f1c95e992 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 13 Aug 2016 04:52:51 +0200 Subject: [PATCH 4/4] Cosmetics --- radicale/xmlutils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index df12c24..9093ae8 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -538,7 +538,7 @@ def _propfind_response(path, item, props, user, write=False): """Build and return a PROPFIND response.""" is_collection = isinstance(item, storage.BaseCollection) if is_collection: - is_leaf = bool(item.get_meta("tag")) + is_leaf = item.get_meta("tag") in ("VADDRESSBOOK", "VCALENDAR") collection = item else: collection = item.collection @@ -786,7 +786,7 @@ def report(path, xml_request, collection): if name: # Reference is an item item = collection.get(name) - if item is None: + if not item: response = _item_response(hreference, found_item=False) multistatus.append(response) continue