Skip to content

Commit

Permalink
Address weird Windows path parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Mar 1, 2024
1 parent 8d7ae00 commit 8d0b52c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fiona/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ class _ParsedPath(_Path):
@classmethod
def from_uri(cls, uri):
parts = urlparse(uri)
path = pathlib.Path(parts.path).as_posix() if parts.path else parts.path
if sys.platform == "win32" and re.match(r"^[a-zA-Z]\:", parts.netloc) and not parts.path:
parsed_path = parts.netloc
parsed_netloc = None
else:
parsed_path = parts.path
parsed_netloc = parts.netloc
path = pathlib.Path(parsed_path).as_posix() if parsed_path else parsed_path
scheme = parts.scheme or None

if parts.query:
Expand All @@ -78,11 +84,11 @@ def from_uri(cls, uri):
else:
archive = None

if parts.scheme and parts.netloc:
if scheme and parsed_netloc:
if archive:
archive = parts.netloc + archive
archive = parsed_netloc + archive
else:
path = parts.netloc + path
path = parsed_netloc + path

return _ParsedPath(path, archive, scheme)

Expand Down
13 changes: 13 additions & 0 deletions tests/test__path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""_path tests."""

import sys

from fiona._path import _parse_path, _vsi_path


def test_parse_zip_windows(monkeypatch):
"""Parse a zip+ Windows path."""
monkeypatch.setattr(sys, "platform", "win32")
path = _parse_path("zip://D:\\a\\Fiona\\Fiona\\tests\\data\\coutwildrnp.zip!coutwildrnp.shp")
vsi_path = _vsi_path(path)
assert vsi_path == "/vsizip/D:\\a\\Fiona\\Fiona\\tests\\data\\coutwildrnp.zip/coutwildrnp.shp"

0 comments on commit 8d0b52c

Please sign in to comment.