From 128a20714b049401c4113233a13911148419a8a6 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Thu, 23 Feb 2012 15:17:59 +0100 Subject: [PATCH] Use is_leaf and is_node instead of is_item and is_collection --- radicale/ical.py | 33 ++++++++++++++++++++++----------- radicale/storage/filesystem.py | 6 +++--- radicale/xmlutils.py | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/radicale/ical.py b/radicale/ical.py index 56281f6..2903c46 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -178,7 +178,7 @@ class Collection(object): self.encoding = "utf-8" split_path = path.split("/") self.path = path if path != '.' else '' - if principal and split_path and self.is_collection(self.path): + if principal and split_path and self.is_node(self.path): # Already existing principal collection self.owner = split_path[0] elif len(split_path) > 1: @@ -189,13 +189,16 @@ class Collection(object): self.is_principal = principal @classmethod - def from_path(cls, path, depth="infinite", include_container=True): + def from_path(cls, path, depth="1", include_container=True): """Return a list of collections and items under the given ``path``. If ``depth`` is "0", only the actual object under ``path`` is - returned. Otherwise, also sub-items are appended to the result. If - ``include_container`` is ``True`` (the default), the containing object - is included in the result. + returned. + + If ``depth`` is anything but "0", it is considered as "1" and direct + children are included in the result. If ``include_container`` is + ``True`` (the default), the containing object is included in the + result. The ``path`` is relative. @@ -205,14 +208,14 @@ class Collection(object): attributes = sane_path.split("/") if not attributes: return None - if not (cls.is_item("/".join(attributes)) or path.endswith("/")): + if not (cls.is_leaf("/".join(attributes)) or path.endswith("/")): attributes.pop() result = [] path = "/".join(attributes) principal = len(attributes) <= 1 - if cls.is_collection(path): + if cls.is_node(path): if depth == "0": result.append(cls(path, principal)) else: @@ -249,13 +252,21 @@ class Collection(object): raise NotImplementedError @classmethod - def is_collection(cls, path): - """Return ``True`` if relative ``path`` is a collection.""" + def is_node(cls, path): + """Return ``True`` if relative ``path`` is a node. + + A node is a WebDAV collection whose members are other collections. + + """ raise NotImplementedError @classmethod - def is_item(cls, path): - """Return ``True`` if relative ``path`` is a collection item.""" + def is_leaf(cls, path): + """Return ``True`` if relative ``path`` is a leaf. + + A leaf is a WebDAV collection whose members are not collections. + + """ raise NotImplementedError @property diff --git a/radicale/storage/filesystem.py b/radicale/storage/filesystem.py index 6dbdbb7..4ecc5b7 100644 --- a/radicale/storage/filesystem.py +++ b/radicale/storage/filesystem.py @@ -81,16 +81,16 @@ class Collection(ical.Collection): _, directories, files = next(os.walk(abs_path)) for filename in directories + files: rel_filename = posixpath.join(path, filename) - if cls.is_collection(rel_filename) or cls.is_item(rel_filename): + if cls.is_node(rel_filename) or cls.is_leaf(rel_filename): yield cls(rel_filename) @classmethod - def is_collection(cls, path): + def is_node(cls, path): abs_path = os.path.join(FOLDER, path.replace("/", os.sep)) return os.path.isdir(abs_path) @classmethod - def is_item(cls, path): + def is_leaf(cls, path): abs_path = os.path.join(FOLDER, path.replace("/", os.sep)) return os.path.isfile(abs_path) and not abs_path.endswith(".props") diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 41a0d7a..ea3843e 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -279,7 +279,7 @@ def _propfind_response(path, item, props, user): if item.is_principal: tag = ET.Element(_tag("D", "principal")) element.append(tag) - if item.is_item(item.path): + if item.is_leaf(item.path): tag = ET.Element(_tag("C", item.resource_type)) element.append(tag) tag = ET.Element(_tag("D", "collection"))