Skip to content

Commit 94bf972

Browse files
committed
Allow reading and writing when href startswith file:///
1 parent 7e8abc1 commit 94bf972

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pystac/stac_io.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def read_text_from_href(self, href: str) -> str:
303303
except HTTPError as e:
304304
raise Exception(f"Could not read uri {href}") from e
305305
else:
306+
href = safe_urlparse(href).path
306307
with open(href, encoding="utf-8") as f:
307308
href_contents = f.read()
308309
return href_contents
@@ -328,7 +329,7 @@ def write_text_to_href(self, href: str, txt: str) -> None:
328329
"""
329330
if _is_url(href):
330331
raise NotImplementedError("DefaultStacIO cannot write to urls")
331-
href = os.fspath(href)
332+
href = safe_urlparse(href).path
332333
dirname = os.path.dirname(href)
333334
if dirname != "" and not os.path.isdir(dirname):
334335
os.makedirs(dirname)
@@ -391,7 +392,7 @@ def _report_duplicate_object_names(
391392

392393
def _is_url(href: str) -> bool:
393394
parsed = safe_urlparse(href)
394-
return parsed.scheme != ""
395+
return parsed.scheme != "" and parsed.scheme != "file"
395396

396397

397398
if HAS_URLLIB3:

0 commit comments

Comments
 (0)