Skip to content

Commit

Permalink
use json instead of python's marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
hpk42 committed Mar 28, 2024
1 parent 6ab3e96 commit cbaa692
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions chatmaild/src/chatmaild/filedict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import logging
import marshal
import json
import filelock
from contextlib import contextmanager

Expand All @@ -20,14 +20,14 @@ def modify(self):
data = self.read()
yield data
write_path = self.path.with_suffix(".tmp")
with write_path.open("wb") as f:
marshal.dump(data, f)
with write_path.open("w") as f:
json.dump(data, f)
os.rename(write_path, self.path)

def read(self):
try:
with self.path.open("rb") as f:
return marshal.load(f)
with self.path.open("r") as f:
return json.load(f)
except FileNotFoundError:
return {}
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion chatmaild/src/chatmaild/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, vmail_dir):
self.to_notify_queue = Queue()

def get_metadata_dict(self, addr):
return FileDict(self.vmail_dir / addr / "metadata.marshalled")
return FileDict(self.vmail_dir / addr / "metadata.json")

def add_token(self, addr, token):
with self.get_metadata_dict(addr).modify() as data:
Expand Down

0 comments on commit cbaa692

Please sign in to comment.