win32_py3: open use system encoding
svn: r21338
This commit is contained in:
@@ -46,7 +46,7 @@ from ..const import VERSION as GRAMPSVERSION, VERSION_TUPLE
|
|||||||
from ..const import IMAGE_DIR
|
from ..const import IMAGE_DIR
|
||||||
from ..utils.trans import get_addon_translator
|
from ..utils.trans import get_addon_translator
|
||||||
from ..ggettext import gettext as _
|
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())
|
full_filename = full_filename.encode(sys.getfilesystemencoding())
|
||||||
local_gettext = get_addon_translator(full_filename).gettext
|
local_gettext = get_addon_translator(full_filename).gettext
|
||||||
try:
|
try:
|
||||||
#execfile(full_filename,
|
if win() and not sys.version_info[0] < 3:
|
||||||
exec(compile(open(full_filename).read(), full_filename, 'exec'),
|
exec(compile(open(full_filename, encoding='utf-8').read(),
|
||||||
make_environment(_=local_gettext),
|
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:
|
except ValueError as msg:
|
||||||
print(_('ERROR: Failed reading plugin registration %(filename)s') % \
|
print(_('ERROR: Failed reading plugin registration %(filename)s') % \
|
||||||
{'filename' : filename})
|
{'filename' : filename})
|
||||||
|
@@ -43,7 +43,7 @@ import errno
|
|||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from ..constfunc import STRTYPE
|
from ..constfunc import STRTYPE, win
|
||||||
|
|
||||||
def safe_eval(exp):
|
def safe_eval(exp):
|
||||||
# restrict eval to empty environment
|
# restrict eval to empty environment
|
||||||
@@ -255,6 +255,9 @@ class ConfigManager(object):
|
|||||||
if filename and os.path.exists(filename):
|
if filename and os.path.exists(filename):
|
||||||
parser = configparser.RawConfigParser()
|
parser = configparser.RawConfigParser()
|
||||||
try: # see bugs 5356, 5490, 5591, 5651, 5718, etc.
|
try: # see bugs 5356, 5490, 5591, 5651, 5718, etc.
|
||||||
|
if win() and not sys.version_info[0] < 3:
|
||||||
|
parser.read(filename, encoding='utf8')
|
||||||
|
else:
|
||||||
parser.read(filename)
|
parser.read(filename)
|
||||||
except:
|
except:
|
||||||
msg1 = _("WARNING: could not parse file, recreating it:\n%s")
|
msg1 = _("WARNING: could not parse file, recreating it:\n%s")
|
||||||
@@ -334,6 +337,9 @@ class ConfigManager(object):
|
|||||||
except OSError as exp:
|
except OSError as exp:
|
||||||
if exp.errno != errno.EEXIST:
|
if exp.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
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 = open(filename, "w")
|
||||||
key_file.write(";; Gramps key file\n")
|
key_file.write(";; Gramps key file\n")
|
||||||
key_file.write((";; Automatically created at %s" %
|
key_file.write((";; Automatically created at %s" %
|
||||||
|
@@ -55,6 +55,7 @@ from gi.repository import Gtk
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR
|
from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
|
from gramps.gen.constfunc import win
|
||||||
from ..managedwindow import ManagedWindow
|
from ..managedwindow import ManagedWindow
|
||||||
from ..display import display_help, display_url
|
from ..display import display_help, display_url
|
||||||
from .grampletpane import (AVAILABLE_GRAMPLETS,
|
from .grampletpane import (AVAILABLE_GRAMPLETS,
|
||||||
@@ -190,6 +191,9 @@ class GrampletBar(Gtk.Notebook):
|
|||||||
"""
|
"""
|
||||||
filename = self.configfile
|
filename = self.configfile
|
||||||
try:
|
try:
|
||||||
|
if win() and not sys.version_info[0] < 3:
|
||||||
|
fp = open(filename, "w", encoding='utf-8')
|
||||||
|
else:
|
||||||
fp = open(filename, "w")
|
fp = open(filename, "w")
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Failed writing '%s'; gramplets not saved" % filename)
|
print("Failed writing '%s'; gramplets not saved" % filename)
|
||||||
|
@@ -39,6 +39,7 @@ from gi.repository import Pango
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from gramps.gen.ggettext import gettext as _
|
from gramps.gen.ggettext import gettext as _
|
||||||
|
from gramps.gen.constfunc import win
|
||||||
import sys
|
import sys
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
import ConfigParser as configparser
|
import ConfigParser as configparser
|
||||||
@@ -1168,6 +1169,9 @@ class GrampletPane(Gtk.ScrolledWindow):
|
|||||||
return # something is the matter
|
return # something is the matter
|
||||||
filename = self.configfile
|
filename = self.configfile
|
||||||
try:
|
try:
|
||||||
|
if win() and not sys.version_info[0] < 3:
|
||||||
|
fp = open(filename, "w", encoding='utf-8')
|
||||||
|
else:
|
||||||
fp = open(filename, "w")
|
fp = open(filename, "w")
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Failed writing '%s'; gramplets not saved" % filename)
|
print("Failed writing '%s'; gramplets not saved" % filename)
|
||||||
|
Reference in New Issue
Block a user