[r21147][Bug 6364] Fix file-opening failures due to unicode content.
svn: r21395
This commit is contained in:
parent
8cea2e239a
commit
3f408af0fa
@ -1094,14 +1094,22 @@ class PluginRegister(object):
|
|||||||
full_filename = full_filename.encode(glocale.getfilesystemencoding())
|
full_filename = full_filename.encode(glocale.getfilesystemencoding())
|
||||||
local_gettext = glocale.get_addon_translator(full_filename).gettext
|
local_gettext = glocale.get_addon_translator(full_filename).gettext
|
||||||
try:
|
try:
|
||||||
if win() and not sys.version_info[0] < 3:
|
stream = open(full_filename).read()
|
||||||
exec(compile(open(full_filename, encoding='utf-8').read(),
|
except UnicodeError as err:
|
||||||
full_filename, 'exec'), make_environment(_=local_gettext),
|
if sys.version_info[0] < 3:
|
||||||
{})
|
print(_("ERROR: Failed to read file %s, %s") % (full_filename, str(err)))
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
stream = open(full_filename, encoding = 'utf-8').read()
|
||||||
|
except ValueError as err:
|
||||||
|
print(_("ERROR: Failed to read file %s, %s") % (full_filename, str(err)))
|
||||||
|
continue
|
||||||
|
try:
|
||||||
#execfile(full_filename,
|
#execfile(full_filename,
|
||||||
exec(compile(open(full_filename).read(), full_filename,
|
exec(compile(stream, full_filename, 'exec'),
|
||||||
'exec'), make_environment(_=local_gettext), {})
|
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})
|
||||||
|
@ -339,10 +339,10 @@ 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:
|
if sys.version_info[0] < 3:
|
||||||
key_file = open(filename, "w", encoding='utf-8')
|
|
||||||
else:
|
|
||||||
key_file = open(filename, "w")
|
key_file = open(filename, "w")
|
||||||
|
else:
|
||||||
|
key_file = open(filename, "w", encoding="utf-8")
|
||||||
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" %
|
||||||
time.strftime("%Y/%m/%d %H:%M:%S")) + "\n\n")
|
time.strftime("%Y/%m/%d %H:%M:%S")) + "\n\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user