Skip to content

Commit 5d3d1b8

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

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

importlib_resources/readers.py

+5-5
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,10 @@ 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))):
156+
for match in reversed(list(re.finditer(r'[\\/]', path_str))):
157157
with contextlib.suppress(FileNotFoundError, IsADirectoryError):
158-
inner = path_str[match.end() :]
159-
yield ZipPath(path_str[: match.start()], inner + '/' * len(inner))
158+
inner = path_str[match.end() :].replace('\\', '/').lstrip('/')
159+
yield ZipPath(path_str[: match.start()], inner)
160160

161161
def resource_path(self, resource):
162162
"""

0 commit comments

Comments
 (0)