[DayOne] support moderm plistlib (#909)

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 commit is contained in:
MinchinWeb 2020-04-11 13:08:04 -06:00
parent 86f5e8e243
commit 4fed54576c

View file

@ -8,6 +8,7 @@ import re
from datetime import datetime from datetime import datetime
import time import time
import fnmatch import fnmatch
from pathlib import Path
import plistlib import plistlib
import pytz import pytz
import uuid import uuid
@ -43,7 +44,7 @@ class DayOne(Journal.Journal):
for filename in filenames: for filename in filenames:
with open(filename, "rb") as plist_entry: with open(filename, "rb") as plist_entry:
try: try:
dict_entry = plistlib.readPlist(plist_entry) dict_entry = plistlib.load(plist_entry, fmt=plistlib.FMT_XML)
except self.PLIST_EXCEPTIONS: except self.PLIST_EXCEPTIONS:
pass pass
else: else:
@ -84,8 +85,10 @@ class DayOne(Journal.Journal):
if not hasattr(entry, "uuid"): if not hasattr(entry, "uuid"):
entry.uuid = uuid.uuid1().hex entry.uuid = uuid.uuid1().hex
filename = os.path.join( fn = (
self.config["journal"], "entries", entry.uuid.upper() + ".doentry" Path(self.config["journal"])
/ "entries"
/ (entry.uuid.upper() + ".doentry")
) )
entry_plist = { entry_plist = {
@ -99,7 +102,9 @@ class DayOne(Journal.Journal):
for tag in entry.tags 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: for entry in self._deleted_entries:
filename = os.path.join( filename = os.path.join(
self.config["journal"], "entries", entry.uuid + ".doentry" self.config["journal"], "entries", entry.uuid + ".doentry"