7258: transcode os.path.join args from the fs enc to prevent a crash

fix plugin registration
fix textual, html report etc (except cairo based report)
fix web calendar report for python3
This commit is contained in:
Josip 2014-04-13 10:11:22 +02:00
parent adeeec6ab1
commit aedfc3a673
7 changed files with 23 additions and 11 deletions

View File

@ -554,7 +554,14 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
def __make_zip_backup(self, dirname): def __make_zip_backup(self, dirname):
import zipfile import zipfile
if sys.version_info[0] < 3:
from string import maketrans
title = self.get_dbname() title = self.get_dbname()
# In Windows resrved characters is "<>:"/\|?*"
reserved_char = r':,<>"/\|?* '
replace_char = "-__________"
trans = title.maketrans(reserved_char, replace_char)
title = title.translate(trans)
if not os.access(dirname, os.W_OK): if not os.access(dirname, os.W_OK):
_LOG.warning("Can't write technical DB backup for %s" % title) _LOG.warning("Can't write technical DB backup for %s" % title)

View File

@ -32,8 +32,8 @@ General option handling, including saving and parsing.
# Standard Python modules # Standard Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from __future__ import print_function from __future__ import print_function, unicode_literals
import os import os, io
import sys import sys
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -208,7 +208,7 @@ class OptionListCollection(object):
""" """
Saves the current OptionListCollection to the associated file. 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
f.write('<options>\n') f.write('<options>\n')

View File

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

View File

@ -32,6 +32,7 @@ from __future__ import print_function
from ...const import GRAMPS_LOCALE as glocale from ...const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
import io
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -159,7 +160,7 @@ class DocBackend(object):
% self.filename) % self.filename)
self._checkfilename() self._checkfilename()
try: try:
self.__file = open(self.filename, "w") self.__file = io.open(self.filename, "w", encoding="utf-8")
except IOError as msg: except IOError as msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
raise DocBackendError(errmsg) raise DocBackendError(errmsg)

View File

@ -33,7 +33,8 @@ Report option handling, including saving and parsing.
# Standard Python modules # Standard Python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os from __future__ import unicode_literals
import os, io
import copy import copy
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
@ -505,7 +506,7 @@ class OptionListCollection(_options.OptionListCollection):
if os.path.isfile(self.filename): if os.path.isfile(self.filename):
p = make_parser() p = make_parser()
p.setContentHandler(OptionParser(self)) p.setContentHandler(OptionParser(self))
the_file = open(self.filename) the_file = io.open(self.filename, encoding="utf-8")
p.parse(the_file) p.parse(the_file)
the_file.close() the_file.close()
except (IOError, OSError, SAXParseException): except (IOError, OSError, SAXParseException):
@ -1001,7 +1002,7 @@ class DocOptionListCollection(_options.OptionListCollection):
if os.path.isfile(self.filename): if os.path.isfile(self.filename):
p = make_parser() p = make_parser()
p.setContentHandler(DocOptionParser(self)) p.setContentHandler(DocOptionParser(self))
the_file = open(self.filename) the_file = io.open(self.filename, encoding="utf-8")
p.parse(the_file) p.parse(the_file)
the_file.close() the_file.close()
except (IOError, OSError, SAXParseException): except (IOError, OSError, SAXParseException):

View File

@ -155,7 +155,7 @@ class GraphvizReportDialog(ReportDialog):
yoptions=Gtk.AttachOptions.SHRINK) yoptions=Gtk.AttachOptions.SHRINK)
self.row += 1 self.row += 1
self.open_with_app = Gtk.CheckButton(build=_("Open with default viewer")) self.open_with_app = Gtk.CheckButton(_("Open with default viewer"))
self.open_with_app.set_active( self.open_with_app.set_active(
config.get('interface.open-with-default-viewer')) config.get('interface.open-with-default-viewer'))
self.tbl.attach(self.open_with_app, 2, 4, self.row, self.row+1, self.tbl.attach(self.open_with_app, 2, 4, self.row, self.row+1,

View File

@ -579,7 +579,7 @@ class WebCalReport(Report):
elif url_fname == 'fullyearlinked': elif url_fname == 'fullyearlinked':
myTitle = _('Full year at a Glance') myTitle = _('Full year at a Glance')
else: else:
myTitle = _(url_fname) myTitle = _(url_fname)
hyper = Html("a", nav_text, href = url, name = url_fname, title = myTitle) hyper = Html("a", nav_text, href = url, name = url_fname, title = myTitle)
if check_cs: if check_cs:
@ -1728,7 +1728,10 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
# sort them based on number of years # sort them based on number of years
# holidays will always be on top of event list # holidays will always be on top of event list
day_list.sort() if sys.version_info[0] < 3:
day_list.sort()
else:
day_list= sorted(day_list, key=lambda x: (isinstance(x[0], str), x[0]))
# return to its caller calendar_build() # return to its caller calendar_build()
return day_list return day_list