Skip to content

Commit

Permalink
Merge pull request #354 from gadomski/feature/split-default-io-read-w…
Browse files Browse the repository at this point in the history
…rite

Split default IO down into to/from href methods
  • Loading branch information
lossyrob authored May 23, 2021
2 parents 8259069 + 8cedba5 commit 016e56c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Changed

- Split `DefaultStacIO`'s reading and writing into two methods to allow subclasses to use the default link resolution behavior ([#354](https://github.com/stac-utils/pystac/pull/354))

### Fixed

- Reading json without orjson ([#348](https://github.com/stac-utils/pystac/pull/348))
Expand Down
6 changes: 6 additions & 0 deletions pystac/stac_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def read_text(
href = source.get_absolute_href()
if href is None:
raise IOError(f"Could not get an absolute HREF from link {source}")
return self.read_text_from_href(href, *args, **kwargs)

def read_text_from_href(self, href: str, *args: Any, **kwargs: Any) -> str:
parsed = urlparse(href)
if parsed.scheme != "":
try:
Expand All @@ -197,7 +199,11 @@ def write_text(
href = dest.get_absolute_href()
if href is None:
raise IOError(f"Could not get an absolute HREF from link {dest}")
return self.write_text_to_href(href, txt, *args, **kwargs)

def write_text_to_href(
self, href: str, txt: str, *args: Any, **kwargs: Any
) -> None:
dirname = os.path.dirname(href)
if dirname != "" and not os.path.isdir(dirname):
os.makedirs(dirname)
Expand Down

0 comments on commit 016e56c

Please sign in to comment.