diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2022-04-17 15:10:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-17 15:10:36 (GMT) |
commit | 7659681556977fe3a19d9f4c5dd93362b9eae25c (patch) | |
tree | 863d22344a00d1bd1ceb5e34a020680f54812385 /Lib/importlib/resources/simple.py | |
parent | 67712e71b3f20541326d57a475f4bd369a98d918 (diff) | |
download | cpython-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.py | 15 |
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): |