diff --git a/gramps/gen/recentfiles.py b/gramps/gen/recentfiles.py index e26752424..8903914c4 100644 --- a/gramps/gen/recentfiles.py +++ b/gramps/gen/recentfiles.py @@ -30,6 +30,8 @@ import os import time import io +import sys +import logging from xml.parsers.expat import ParserCreate try: @@ -182,7 +184,8 @@ class RecentFiles(object): """ Saves the current GRAMPS RecentFiles collection to the associated file. """ - xml_file = io.open(os.path.expanduser(GRAMPS_FILENAME),'w', encoding="utf-8") + xml_file = open(os.path.expanduser(GRAMPS_FILENAME),'w') + if use_lock: fcntl.lockf(xml_file,fcntl.LOCK_EX) xml_file.write("\n") @@ -215,9 +218,13 @@ class RecentParser(object): def __init__(self): self.recent_files = [] +#Python3's expat wants bytes, Python2's wants a string. try: - xml_file = io.open(os.path.expanduser(GRAMPS_FILENAME), "r", - encoding = 'utf-8') + if sys.version_info[0] < 3: + xml_file = open(os.path.expanduser(GRAMPS_FILENAME), "r") + else: + xml_file = open(os.path.expanduser(GRAMPS_FILENAME), "rb") + if use_lock: fcntl.lockf(xml_file,fcntl.LOCK_SH) @@ -230,7 +237,8 @@ class RecentParser(object): if use_lock: fcntl.lockf(xml_file,fcntl.LOCK_UN) xml_file.close() - except: + except Exception as err: + logging.error("Recent file parse error %s", str(err)) if xml_file: xml_file.close()