From cbaa6924c10e6c4627864a9ff16310a34e34ed34 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 28 Mar 2024 11:05:25 +0100 Subject: [PATCH] use json instead of python's marshal --- chatmaild/src/chatmaild/filedict.py | 10 +++++----- chatmaild/src/chatmaild/metadata.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chatmaild/src/chatmaild/filedict.py b/chatmaild/src/chatmaild/filedict.py index 4515867..3d9caf8 100644 --- a/chatmaild/src/chatmaild/filedict.py +++ b/chatmaild/src/chatmaild/filedict.py @@ -1,6 +1,6 @@ import os import logging -import marshal +import json import filelock from contextlib import contextmanager @@ -20,14 +20,14 @@ class FileDict: 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: diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index 8900e2c..fb5628f 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -35,7 +35,7 @@ class Notifier: 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: