Skip to content

Commit 016e56c

Browse files
authored
Merge pull request #354 from gadomski/feature/split-default-io-read-write
Split default IO down into to/from href methods
2 parents 8259069 + 8cedba5 commit 016e56c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Changed
88

9+
- 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))
10+
911
### Fixed
1012

1113
- Reading json without orjson ([#348](https://github.com/stac-utils/pystac/pull/348))

pystac/stac_io.py

+6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def read_text(
176176
href = source.get_absolute_href()
177177
if href is None:
178178
raise IOError(f"Could not get an absolute HREF from link {source}")
179+
return self.read_text_from_href(href, *args, **kwargs)
179180

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

204+
def write_text_to_href(
205+
self, href: str, txt: str, *args: Any, **kwargs: Any
206+
) -> None:
201207
dirname = os.path.dirname(href)
202208
if dirname != "" and not os.path.isdir(dirname):
203209
os.makedirs(dirname)

0 commit comments

Comments
 (0)