GrampsLocale: Fix file encoding error in recentfiles

Expat wants a binary file, not a string file.

svn: r21152
This commit is contained in:
John Ralls 2013-01-17 19:48:32 +00:00
parent fba8cdddd1
commit 87c5b6632a

View File

@ -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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\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()