I received some calendar entries from somewhere with slashes in the resource part of the name. I don't know if this is valid, but I came up with a patch to handle it.
From 0b0b7f725333bdecc5719d8357f60b974aa5b580 Mon Sep 17 00:00:00 2001 From: Keith Packard <[email protected]> Date: Mon, 25 Jan 2016 10:50:09 -0800 Subject: [PATCH] Allow for resources within collections to have '/' This allows resource names to contain slashes, by stripping off path components until a collection (directory) is found. Signed-off-by: Keith Packard <[email protected]> --- calypso/paths.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/calypso/paths.py b/calypso/paths.py index 11640aa..a5b1b0a 100644 --- a/calypso/paths.py +++ b/calypso/paths.py @@ -87,6 +87,15 @@ def parent_url(path): return new_path # +# Given a URL, return the child URL, which is +# the last path element +# + +def child_url(path): + path_parts = path.strip("/").split("/") + return path_parts[len(path_parts)-1] + +# # If the given URL references a resource, then # return the name of that resource. Otherwise, # return None @@ -96,10 +105,23 @@ log = logging.getLogger() def resource_from_path(path): """Return Calypso item name from ``path``.""" - if is_collection(path): - name = None + + child_path = None + collection = path + + while collection and not is_collection(collection): + child = child_url(collection) + if child_path: + child_path = child + "/" + child_path + else: + child_path = child + collection = parent_url(collection) + + if child_path: + name = urllib.unquote(child_path) else: - name = urllib.unquote(path.strip("/").split("/")[-1]) + name = None + log.debug('Path %s results in name: %s', path, name) return name @@ -113,11 +135,12 @@ def collection_from_path(path): """Returns Calypso collection name from ``path``.""" collection = path - if not is_collection(collection): + while collection and not is_collection(collection): collection = parent_url(collection) - if not is_collection(collection): - log.debug("No collection found for path %s", path) - return None + + if not collection: + log.debug("No collection found for path %s", path) + return None # unquote, strip off any trailing slash, then clean up /../ and // entries collection = "/" + urllib.unquote(collection).strip("/") -- 2.7.0.rc3
-- -keith
signature.asc
Description: PGP signature
_______________________________________________ Calypso mailing list [email protected] http://keithp.com/mailman/listinfo/calypso
