GrampsLocale: Fix file encoding error in recentfiles
Expat wants a binary file, not a string file. svn: r21152
This commit is contained in:
parent
e920cbfac1
commit
42de599bd0
@ -30,6 +30,8 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import io
|
import io
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
from xml.parsers.expat import ParserCreate
|
from xml.parsers.expat import ParserCreate
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -182,7 +184,8 @@ class RecentFiles(object):
|
|||||||
"""
|
"""
|
||||||
Saves the current GRAMPS RecentFiles collection to the associated file.
|
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:
|
if use_lock:
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_EX)
|
fcntl.lockf(xml_file,fcntl.LOCK_EX)
|
||||||
xml_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
xml_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||||
@ -215,9 +218,13 @@ class RecentParser(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.recent_files = []
|
self.recent_files = []
|
||||||
|
|
||||||
|
#Python3's expat wants bytes, Python2's wants a string.
|
||||||
try:
|
try:
|
||||||
xml_file = io.open(os.path.expanduser(GRAMPS_FILENAME), "r",
|
if sys.version_info[0] < 3:
|
||||||
encoding = 'utf-8')
|
xml_file = open(os.path.expanduser(GRAMPS_FILENAME), "r")
|
||||||
|
else:
|
||||||
|
xml_file = open(os.path.expanduser(GRAMPS_FILENAME), "rb")
|
||||||
|
|
||||||
if use_lock:
|
if use_lock:
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
||||||
|
|
||||||
@ -230,7 +237,8 @@ class RecentParser(object):
|
|||||||
if use_lock:
|
if use_lock:
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
||||||
xml_file.close()
|
xml_file.close()
|
||||||
except:
|
except Exception as err:
|
||||||
|
logging.error("Recent file parse error %s", str(err))
|
||||||
if xml_file:
|
if xml_file:
|
||||||
xml_file.close()
|
xml_file.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user