[r21424]Fix Py2 file encoding errors

svn: r21425
This commit is contained in:
John Ralls 2013-02-24 02:20:09 +00:00
parent ddf9dc9f14
commit 4decf95b07
2 changed files with 13 additions and 11 deletions

View File

@ -38,6 +38,8 @@ from gi.repository import Gtk
from gi.repository import Pango
import time
import os
import io
from gramps.gen.constfunc import cuni
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.get_translation().gettext
import sys
@ -1169,17 +1171,17 @@ class GrampletPane(Gtk.ScrolledWindow):
return # something is the matter
filename = self.configfile
try:
fp = open(filename, "w")
fp = io.open(filename, "w", encoding='utf-8')
except IOError:
print("Failed writing '%s'; gramplets not saved" % filename)
return
fp.write(";; Gramps gramplets file" + NL)
fp.write((";; Automatically created at %s" %
time.strftime("%Y/%m/%d %H:%M:%S")) + NL + NL)
fp.write("[Gramplet View Options]" + NL)
fp.write(("column_count=%d" + NL) % self.column_count)
fp.write(("pane_position=%d" + NL) % self.pane_position)
fp.write(("pane_orientation=%s" + NL) % self.pane_orientation)
fp.write(cuni(";; Gramps gramplets file" + NL))
fp.write(cuni((";; Automatically created at %s" %
time.strftime("%Y/%m/%d %H:%M:%S")) + NL + NL))
fp.write(cuni("[Gramplet View Options]" + NL))
fp.write(cuni(("column_count=%d" + NL) % self.column_count))
fp.write(cuni(("pane_position=%d" + NL) % self.pane_position))
fp.write(cuni(("pane_orientation=%s" + NL) % self.pane_orientation))
fp.write(NL)
# showing gramplets:
for col in range(self.column_count):

View File

@ -36,7 +36,7 @@ from __future__ import print_function
import re
import locale
from gramps.gen.constfunc import STRTYPE
from gramps.gen.constfunc import STRTYPE, cuni
"""
HTML operations.
@ -417,14 +417,14 @@ class Html(list):
elif self.indent:
tabs += indent
if self.inline: # if inline, write all list and
method('%s%s' % (tabs, self)) # nested list elements
method(cuni('%s%s' % (tabs, self))) # nested list elements
#
else:
for item in self[:]: # else write one at a time
if isinstance(item, Html): # recurse if nested Html class
item.write(method=method, indent=indent, tabs=tabs)
else:
method('%s%s' % (tabs, item)) # else write the line
method(cuni('%s%s' % (tabs, item))) # else write the line
#
def addXML(self, version=1.0, encoding="UTF-8", standalone="no"):
"""