Skip to content

Commit a9b0c92

Browse files
committed
Honor backslashes in inner paths as found in submodule_search_locations.
1 parent 463331b commit a9b0c92

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

importlib_resources/readers.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ def __init__(self, namespace_path):
136136

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

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

161163
def resource_path(self, resource):
162164
"""

0 commit comments

Comments
 (0)