summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/resources/simple.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-04-17 15:10:36 (GMT)
committerGitHub <noreply@github.com>2022-04-17 15:10:36 (GMT)
commit7659681556977fe3a19d9f4c5dd93362b9eae25c (patch)
tree863d22344a00d1bd1ceb5e34a020680f54812385 /Lib/importlib/resources/simple.py
parent67712e71b3f20541326d57a475f4bd369a98d918 (diff)
downloadcpython-7659681556977fe3a19d9f4c5dd93362b9eae25c.zip
cpython-7659681556977fe3a19d9f4c5dd93362b9eae25c.tar.gz
cpython-7659681556977fe3a19d9f4c5dd93362b9eae25c.tar.bz2
gh-91298: Refine traversable (apply changes from importlib_resources 5.7.1) (#91623)
* bpo-47142: Refine traversable (apply changes from importlib_resources 5.7.1) * Replace changelog referencing github issue.
Diffstat (limited to 'Lib/importlib/resources/simple.py')
-rw-r--r--Lib/importlib/resources/simple.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/importlib/resources/simple.py b/Lib/importlib/resources/simple.py
index da073cb..d0fbf23 100644
--- a/Lib/importlib/resources/simple.py
+++ b/Lib/importlib/resources/simple.py
@@ -99,10 +99,19 @@ class ResourceContainer(Traversable):
def open(self, *args, **kwargs):
raise IsADirectoryError()
- def joinpath(self, name):
+ @staticmethod
+ def _flatten(compound_names):
+ for name in compound_names:
+ yield from name.split('/')
+
+ def joinpath(self, *descendants):
+ if not descendants:
+ return self
+ names = self._flatten(descendants)
+ target = next(names)
return next(
- traversable for traversable in self.iterdir() if traversable.name == name
- )
+ traversable for traversable in self.iterdir() if traversable.name == target
+ ).joinpath(*names)
class TraversableReader(TraversableResources, SimpleReader):