mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
67712e71b3
commit
7659681556
4 changed files with 42 additions and 16 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue