Skip to content

Commit

Permalink
Honor backslashes in inner paths as found in submodule_search_locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Sep 20, 2023
1 parent 463331b commit a9b0c92
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions importlib_resources/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ def __init__(self, namespace_path):

@classmethod
def _resolve(cls, path_str) -> abc.Traversable:
"""
r"""
Given an item from a namespace path, resolve it to a Traversable.
path_str might be a directory on the filesystem or a path to a
zipfile plus the path within the zipfile, e.g. ``/foo/bar`` or
``/foo/baz.zip/inner_dir``.
``/foo/baz.zip/inner_dir`` or ``foo\baz.zip\inner_dir\sub``.
"""
(dir,) = (cand for cand in cls._candidate_paths(path_str) if cand.is_dir())
return dir
Expand All @@ -153,10 +153,12 @@ def _candidate_paths(cls, path_str):

@staticmethod
def _resolve_zip_path(path_str):
for match in reversed(list(re.finditer('/', path_str))):
with contextlib.suppress(FileNotFoundError, IsADirectoryError):
inner = path_str[match.end() :]
yield ZipPath(path_str[: match.start()], inner + '/' * len(inner))
for match in reversed(list(re.finditer(r'[\\/]', path_str))):
with contextlib.suppress(
FileNotFoundError, IsADirectoryError, PermissionError
):
inner = path_str[match.end() :].replace('\\', '/') + '/'
yield ZipPath(path_str[: match.start()], inner.lstrip('/'))

def resource_path(self, resource):
"""
Expand Down

0 comments on commit a9b0c92

Please sign in to comment.