Skip to content

Commit a7a17c2

Browse files
authored
Merge pull request #1025 from rkingsbury/monty
Add explicit text mode to zopen calls (monty warning)
2 parents 9bc96da + 9da353e commit a7a17c2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/maggma/stores/file_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def query( # type: ignore
442442
# TODO - could add more logic for detecting different file types
443443
# and more nuanced exception handling
444444
try:
445-
with zopen(d["path"], "r", encoding=self.encoding) as f:
445+
with zopen(d["path"], "rt", encoding=self.encoding) as f:
446446
data = f.read()
447447
except Exception as e:
448448
data = f"Unable to read: {e}"

src/maggma/stores/mongolike.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ def connect(self, force_reset: bool = False):
684684

685685
# create the .json file if it does not exist
686686
if not self.read_only and not Path(self.paths[0]).exists():
687-
with zopen(self.paths[0], "w", encoding=self.encoding) as f:
687+
with zopen(self.paths[0], "wt", encoding=self.encoding) as f:
688688
data: list[dict] = []
689689
bytesdata = orjson.dumps(data)
690690
f.write(bytesdata.decode("utf-8"))
@@ -711,7 +711,7 @@ def read_json_file(self, path) -> list:
711711
Args:
712712
path: Path to the JSON file to be read
713713
"""
714-
with zopen(path, "r") as f:
714+
with zopen(path, "rt") as f:
715715
data = f.read()
716716
data = data.decode() if isinstance(data, bytes) else data
717717
objects = bson.json_util.loads(data) if "$oid" in data else orjson.loads(data)
@@ -761,7 +761,7 @@ def update_json_file(self):
761761
"""
762762
Updates the json file when a write-like operation is performed.
763763
"""
764-
with zopen(self.paths[0], "w", encoding=self.encoding) as f:
764+
with zopen(self.paths[0], "wt", encoding=self.encoding) as f:
765765
data = list(self.query())
766766
for d in data:
767767
d.pop("_id")

0 commit comments

Comments
 (0)