Simplify name_from_path and add error check

This commit is contained in:
Unrud 2016-08-13 04:47:35 +02:00
parent 3b29a56c81
commit 1c6e626979

View File

@ -419,12 +419,11 @@ def _param_filter_match(vobject_item, filter_, parent_name):
def name_from_path(path, collection): def name_from_path(path, collection):
"""Return Radicale item name from ``path``.""" """Return Radicale item name from ``path``."""
collection_path = collection.path.strip("/") path = path.strip("/") + "/"
collection_parts = collection_path.split("/") if collection_path else [] start = collection.path + "/"
path = path.strip("/") if not path.startswith(start):
path_parts = path.split("/") if path else [] raise ValueError("'%s' doesn't start with '%s'" % (path, start))
if len(path_parts) - len(collection_parts): return path[len(start):]
return path_parts[-1]
def props_from_request(root, actions=("set", "remove")): def props_from_request(root, actions=("set", "remove")):