From 38cc471eafc288cd81a642cafd893dc43ae8e4f2 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 25 Mar 2022 20:25:00 +0100 Subject: [PATCH] Improved error handling --- LXMF/LXMF.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/LXMF/LXMF.py b/LXMF/LXMF.py index f1e2e56..cb38c82 100644 --- a/LXMF/LXMF.py +++ b/LXMF/LXMF.py @@ -405,26 +405,28 @@ class LXMessage: else: return None + def packed_container(self): + if not self.packed: + self.pack() + + container = { + "state": self.state, + "lxmf_bytes": self.packed, + "transport_encrypted": self.transport_encrypted, + "transport_encryption": self.transport_encryption, + "method": self.method + } + + return msgpack.packb(container) + + def write_to_directory(self, directory_path): file_name = RNS.hexrep(self.hash, delimit=False) file_path = directory_path+"/"+file_name try: - if not self.packed: - self.pack() - - container = { - "state": self.state, - "lxmf_bytes": self.packed, - "transport_encrypted": self.transport_encrypted, - "transport_encryption": self.transport_encryption, - "method": self.method - } - - packed_container = msgpack.packb(container) - file = open(file_path, "wb") - file.write(packed_container) + file.write(self.packed_container()) file.close() return file_path