more open=>io.open changes, as John advised

svn: r21729
This commit is contained in:
Paul Franklin 2013-03-24 00:11:05 +00:00
parent 5adc2102a2
commit 4db73f0422
5 changed files with 13 additions and 11 deletions

View File

@ -35,6 +35,7 @@ General option handling, including saving and parsing.
from __future__ import print_function
import os
import io
#-------------------------------------------------------------------------
#
@ -198,7 +199,7 @@ class OptionListCollection(object):
"""
Saves the current OptionListCollection to the associated file.
"""
f = open(self.filename,"w")
f = io.open(self.filename, "w", encoding='utf-8')
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
f.write('<options>\n')

View File

@ -1083,9 +1083,7 @@ class PluginRegister(object):
full_filename = os.path.join(dir, filename)
if sys.version_info[0] < 3:
full_filename = full_filename.encode(glocale.getfilesystemencoding())
fd = open(full_filename, "r")
else:
fd = io.open(full_filename, 'r', encoding = 'utf-8')
fd = io.open(full_filename, 'r', encoding = 'utf-8')
stream = fd.read()
fd.close()
if os.path.exists(os.path.join(os.path.dirname(full_filename),

View File

@ -31,6 +31,7 @@
#-------------------------------------------------------------------------
import os
from xml.sax.saxutils import escape
import io
def escxml(string):
"""
@ -148,7 +149,7 @@ class StyleSheetList(object):
"""
Saves the current StyleSheet definitions to the associated file.
"""
xml_file = open(self.__file, "w")
xml_file = io.open(self.__file, "w", encoding='utf-8')
xml_file.write("<?xml version=\"1.0\"?>\n")
xml_file.write('<stylelist>\n')
@ -211,7 +212,7 @@ class StyleSheetList(object):
if os.path.isfile(self.__file):
parser = make_parser()
parser.setContentHandler(SheetParser(self))
the_file = open(self.__file)
the_file = io.open(self.__file, encoding='utf-8')
parser.parse(the_file)
the_file.close()
except (IOError, OSError, SAXParseException):

View File

@ -31,6 +31,8 @@
# Standard Python modules
#
#-------------------------------------------------------------------------
import os
import io
from ...const import GRAMPS_LOCALE as glocale
_ = glocale.get_translation().gettext
@ -41,7 +43,6 @@ _ = glocale.get_translation().gettext
#------------------------------------------------------------------------
import logging
log = logging.getLogger(".Book")
import os
#-------------------------------------------------------------------------
#
@ -318,7 +319,7 @@ class BookList(object):
"""
Saves the current BookList to the associated file.
"""
f = open(self.file, "w")
f = io.open(self.file, "w", encoding='utf-8')
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
f.write('<booklist>\n')
for name in sorted(self.bookmap): # enable a diff of archived copies
@ -370,7 +371,7 @@ class BookList(object):
try:
p = make_parser()
p.setContentHandler(BookParser(self, self.dbase))
the_file = open(self.file)
the_file = io.open(self.file, encoding='utf-8')
p.parse(the_file)
the_file.close()
except (IOError, OSError, ValueError, SAXParseException, KeyError,

View File

@ -36,6 +36,7 @@ Report option handling, including saving and parsing.
import os
import copy
from xml.sax.saxutils import escape
import io
def escxml(d):
return escape(d, { '"' : '&quot;' } )
@ -475,7 +476,7 @@ class OptionListCollection(_options.OptionListCollection):
if os.path.isfile(self.filename):
p = make_parser()
p.setContentHandler(OptionParser(self))
the_file = open(self.filename)
the_file = io.open(self.filename, encoding = 'utf-8')
p.parse(the_file)
the_file.close()
except (IOError, OSError, SAXParseException):
@ -965,7 +966,7 @@ class DocOptionListCollection(_options.OptionListCollection):
if os.path.isfile(self.filename):
p = make_parser()
p.setContentHandler(DocOptionParser(self))
the_file = open(self.filename)
the_file = io.open(self.filename, encoding = 'utf-8')
p.parse(the_file)
the_file.close()
except (IOError, OSError, SAXParseException):