use json instead of python's marshal

This commit is contained in:
holger krekel 2024-03-28 11:05:25 +01:00
parent 6ab3e9657d
commit cbaa6924c1
2 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import os import os
import logging import logging
import marshal import json
import filelock import filelock
from contextlib import contextmanager from contextlib import contextmanager
@ -20,14 +20,14 @@ class FileDict:
data = self.read() data = self.read()
yield data yield data
write_path = self.path.with_suffix(".tmp") write_path = self.path.with_suffix(".tmp")
with write_path.open("wb") as f: with write_path.open("w") as f:
marshal.dump(data, f) json.dump(data, f)
os.rename(write_path, self.path) os.rename(write_path, self.path)
def read(self): def read(self):
try: try:
with self.path.open("rb") as f: with self.path.open("r") as f:
return marshal.load(f) return json.load(f)
except FileNotFoundError: except FileNotFoundError:
return {} return {}
except Exception: except Exception:

View File

@ -35,7 +35,7 @@ class Notifier:
self.to_notify_queue = Queue() self.to_notify_queue = Queue()
def get_metadata_dict(self, addr): 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): def add_token(self, addr, token):
with self.get_metadata_dict(addr).modify() as data: with self.get_metadata_dict(addr).modify() as data: