Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python 3.9 incompatibility by updating plistlib #909

Merged
merged 1 commit into from
Apr 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jrnl/DayOneJournal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import datetime
import time
import fnmatch
from pathlib import Path
import plistlib
import pytz
import uuid
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = {
Expand All @@ -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"
Expand Down