diff --git a/lib/importlib_resources/abc.py b/lib/importlib_resources/abc.py index a2b0af62..5e38ba61 100644 --- a/lib/importlib_resources/abc.py +++ b/lib/importlib_resources/abc.py @@ -55,6 +55,9 @@ class Traversable(Protocol): """ An object with a subset of pathlib.Path methods suitable for traversing directories and opening files. + + Any exceptions that occur when accessing the backing resource + may propagate unaltered. """ @abc.abstractmethod @@ -90,9 +93,13 @@ class Traversable(Protocol): """ @abc.abstractmethod - def joinpath(self, child: StrPath) -> "Traversable": + def joinpath(self, *descendants: StrPath) -> "Traversable": """ - Return Traversable child in self + Return Traversable resolved with any descendants applied. + + Each descendant should be a path segment relative to self + and each may contain multiple levels separated by + ``posixpath.sep`` (``/``). """ def __truediv__(self, child: StrPath) -> "Traversable": diff --git a/lib/importlib_resources/simple.py b/lib/importlib_resources/simple.py index da073cbd..d0fbf237 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): diff --git a/package/requirements-package.txt b/package/requirements-package.txt index 5acd462f..910a9fb8 100644 --- a/package/requirements-package.txt +++ b/package/requirements-package.txt @@ -1,5 +1,5 @@ apscheduler==3.9.1 -importlib-resources==5.6.0 +importlib-resources==5.7.1 pyinstaller==4.9 pyopenssl==22.0.0 pycryptodomex==3.14.1 diff --git a/requirements.txt b/requirements.txt index d6b0816c..6fb9cf89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ html5lib==1.1 httpagentparser==1.9.2 idna==3.3 importlib-metadata==4.11.3 -importlib-resources==5.6.0 +importlib-resources==5.7.1 git+https://github.com/Tautulli/ipwhois.git@master#egg=ipwhois IPy==1.01 Mako==1.2.0