From 75b361320211fe8b6e9fbea5765056b24ffd18ba Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 13 Apr 2022 20:17:14 -0400 Subject: [PATCH 1/2] Honor '/'-separated names in ResourceContainer.joinpath. --- importlib_resources/simple.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/importlib_resources/simple.py b/importlib_resources/simple.py index 1f6e43a2..d0fbf237 100644 --- a/importlib_resources/simple.py +++ b/importlib_resources/simple.py @@ -99,13 +99,19 @@ def iterdir(self): def open(self, *args, **kwargs): raise IsADirectoryError() - def joinpath(self, *names): - if not names: + @staticmethod + def _flatten(compound_names): + for name in compound_names: + yield from name.split('/') + + def joinpath(self, *descendants): + if not descendants: return self - name, rest = names[0], names[1:] + names = self._flatten(descendants) + target = next(names) return next( - traversable for traversable in self.iterdir() if traversable.name == name - ).joinpath(*rest) + traversable for traversable in self.iterdir() if traversable.name == target + ).joinpath(*names) class TraversableReader(TraversableResources, SimpleReader): From 07213e3acc47946c9377d9e8ba58fd752929d5de Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Apr 2022 20:42:39 -0400 Subject: [PATCH 2/2] Update changelog. --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 290694e3..1055a2f0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v5.7.1 +====== + +* #249: In ``simple.ResourceContainer.joinpath``, honor + names split by ``posixpath.sep``. + v5.7.0 ======