From 467843294ef51e7a263b20b138fba522511174c7 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 7 Apr 2020 10:11:58 -0600 Subject: [PATCH] [DayOne] support moderm `plistlib` The API of the standard library's `plistlib` changed with version 3.4 of Python, and the old API is being removed in Python 3.9. In other words, the new API is supported by all version of Python we current support (3.6 to 3.8). See https://docs.python.org/3.4/library/plistlib.html for more details. This should (hopefully) allow our Python 3.9 tests to pass. --- jrnl/DayOneJournal.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index 8e8b2cd03..af82333c4 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -8,6 +8,7 @@ from datetime import datetime import time import fnmatch +from pathlib import Path import plistlib import pytz import uuid @@ -43,7 +44,7 @@ def open(self): for filename in filenames: with open(filename, "rb") as plist_entry: try: - dict_entry = plistlib.readPlist(plist_entry) + dict_entry = plistlib.load(plist_entry, fmt=plistlib.FMT_XML) except self.PLIST_EXCEPTIONS: pass else: @@ -84,8 +85,10 @@ def write(self): if not hasattr(entry, "uuid"): entry.uuid = uuid.uuid1().hex - filename = os.path.join( - self.config["journal"], "entries", entry.uuid.upper() + ".doentry" + fn = ( + Path(self.config["journal"]) + / "entries" + / (entry.uuid.upper() + ".doentry") ) entry_plist = { @@ -99,7 +102,9 @@ def write(self): for tag in entry.tags ], } - plistlib.writePlist(entry_plist, filename) + # plistlib expects a binary object + with fn.open(mode="wb") as f: + plistlib.dump(entry_plist, f, fmt=plistlib.FMT_XML, sort_keys=False) for entry in self._deleted_entries: filename = os.path.join( self.config["journal"], "entries", entry.uuid + ".doentry"