Update importlib-resources==5.10.0

[skip ci]
This commit is contained in:
JonnyWong16 2022-11-12 17:02:51 -08:00
parent 5bb9dbd0f6
commit c73450c0db
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
12 changed files with 335 additions and 101 deletions

View file

@ -1,5 +1,7 @@
import abc
import io
import itertools
import pathlib
from typing import Any, BinaryIO, Iterable, Iterator, NoReturn, Text, Optional
from ._compat import runtime_checkable, Protocol, StrPath
@ -50,6 +52,10 @@ class ResourceReader(metaclass=abc.ABCMeta):
raise FileNotFoundError
class TraversalError(Exception):
pass
@runtime_checkable
class Traversable(Protocol):
"""
@ -92,7 +98,6 @@ class Traversable(Protocol):
Return True if self is a file
"""
@abc.abstractmethod
def joinpath(self, *descendants: StrPath) -> "Traversable":
"""
Return Traversable resolved with any descendants applied.
@ -101,6 +106,22 @@ class Traversable(Protocol):
and each may contain multiple levels separated by
``posixpath.sep`` (``/``).
"""
if not descendants:
return self
names = itertools.chain.from_iterable(
path.parts for path in map(pathlib.PurePosixPath, descendants)
)
target = next(names)
matches = (
traversable for traversable in self.iterdir() if traversable.name == target
)
try:
match = next(matches)
except StopIteration:
raise TraversalError(
"Target not found during traversal.", target, list(names)
)
return match.joinpath(*names)
def __truediv__(self, child: StrPath) -> "Traversable":
"""
@ -118,7 +139,8 @@ class Traversable(Protocol):
accepted by io.TextIOWrapper.
"""
@abc.abstractproperty
@property
@abc.abstractmethod
def name(self) -> str:
"""
The base name of this object without any parent references.