From db1bd1e11497d6772658fce797faf5507038bc1a Mon Sep 17 00:00:00 2001 From: Josip Pisoj Date: Sun, 10 Feb 2013 22:52:19 +0000 Subject: [PATCH] win32_py3: open use system encoding svn: r21338 --- gramps/gen/plug/_pluginreg.py | 14 +++++++++----- gramps/gen/utils/configmanager.py | 12 +++++++++--- gramps/gui/widgets/grampletbar.py | 6 +++++- gramps/gui/widgets/grampletpane.py | 6 +++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gramps/gen/plug/_pluginreg.py b/gramps/gen/plug/_pluginreg.py index 450465899..1f5da480e 100644 --- a/gramps/gen/plug/_pluginreg.py +++ b/gramps/gen/plug/_pluginreg.py @@ -46,7 +46,7 @@ from ..const import VERSION as GRAMPSVERSION, VERSION_TUPLE from ..const import IMAGE_DIR from ..utils.trans import get_addon_translator from ..ggettext import gettext as _ -from ..constfunc import STRTYPE +from ..constfunc import STRTYPE, win #------------------------------------------------------------------------- # @@ -1093,10 +1093,14 @@ class PluginRegister(object): full_filename = full_filename.encode(sys.getfilesystemencoding()) local_gettext = get_addon_translator(full_filename).gettext try: - #execfile(full_filename, - exec(compile(open(full_filename).read(), full_filename, 'exec'), - make_environment(_=local_gettext), - {}) + if win() and not sys.version_info[0] < 3: + exec(compile(open(full_filename, encoding='utf-8').read(), + full_filename, 'exec'), make_environment(_=local_gettext), + {}) + else: + #execfile(full_filename, + exec(compile(open(full_filename).read(), full_filename, + 'exec'), make_environment(_=local_gettext), {}) except ValueError as msg: print(_('ERROR: Failed reading plugin registration %(filename)s') % \ {'filename' : filename}) diff --git a/gramps/gen/utils/configmanager.py b/gramps/gen/utils/configmanager.py index d7debd7e4..6e6e9ca59 100644 --- a/gramps/gen/utils/configmanager.py +++ b/gramps/gen/utils/configmanager.py @@ -43,7 +43,7 @@ import errno import copy import logging -from ..constfunc import STRTYPE +from ..constfunc import STRTYPE, win def safe_eval(exp): # restrict eval to empty environment @@ -255,7 +255,10 @@ class ConfigManager(object): if filename and os.path.exists(filename): parser = configparser.RawConfigParser() try: # see bugs 5356, 5490, 5591, 5651, 5718, etc. - parser.read(filename) + if win() and not sys.version_info[0] < 3: + parser.read(filename, encoding='utf8') + else: + parser.read(filename) except: msg1 = _("WARNING: could not parse file, recreating it:\n%s") print(msg1 % filename, file=sys.stderr) @@ -334,7 +337,10 @@ class ConfigManager(object): except OSError as exp: if exp.errno != errno.EEXIST: raise - key_file = open(filename, "w") + if win() and not sys.version_info[0] < 3: + key_file = open(filename, "w", encoding='utf-8') + else: + key_file = open(filename, "w") key_file.write(";; Gramps key file\n") key_file.write((";; Automatically created at %s" % time.strftime("%Y/%m/%d %H:%M:%S")) + "\n\n") diff --git a/gramps/gui/widgets/grampletbar.py b/gramps/gui/widgets/grampletbar.py index 74649ef40..2c8588e45 100644 --- a/gramps/gui/widgets/grampletbar.py +++ b/gramps/gui/widgets/grampletbar.py @@ -55,6 +55,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR from gramps.gen.config import config +from gramps.gen.constfunc import win from ..managedwindow import ManagedWindow from ..display import display_help, display_url from .grampletpane import (AVAILABLE_GRAMPLETS, @@ -190,7 +191,10 @@ class GrampletBar(Gtk.Notebook): """ filename = self.configfile try: - fp = open(filename, "w") + if win() and not sys.version_info[0] < 3: + fp = open(filename, "w", encoding='utf-8') + else: + fp = open(filename, "w") except IOError: print("Failed writing '%s'; gramplets not saved" % filename) return diff --git a/gramps/gui/widgets/grampletpane.py b/gramps/gui/widgets/grampletpane.py index 92bc889b2..5bd9d9337 100644 --- a/gramps/gui/widgets/grampletpane.py +++ b/gramps/gui/widgets/grampletpane.py @@ -39,6 +39,7 @@ from gi.repository import Pango import time import os from gramps.gen.ggettext import gettext as _ +from gramps.gen.constfunc import win import sys if sys.version_info[0] < 3: import ConfigParser as configparser @@ -1168,7 +1169,10 @@ class GrampletPane(Gtk.ScrolledWindow): return # something is the matter filename = self.configfile try: - fp = open(filename, "w") + if win() and not sys.version_info[0] < 3: + fp = open(filename, "w", encoding='utf-8') + else: + fp = open(filename, "w") except IOError: print("Failed writing '%s'; gramplets not saved" % filename) return