Bug 9178: Error loading Participants add-on in French locale

Restores setting the stdout encoding to sys.getdefaultencoding() in a
way that works with Python3 (thanks to Jack O'Connor on stackoverflow)
and in a place that sets it for the loggers, too.
This commit is contained in:
John Ralls 2016-02-08 14:04:15 -08:00
parent e7db5c9db5
commit a7306150a2

View File

@ -43,9 +43,41 @@ from subprocess import Popen, PIPE
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from .gen.const import APP_GRAMPS, USER_DIRLIST, HOME_DIR from .gen.const import APP_GRAMPS, USER_DIRLIST, HOME_DIR
from .gen.constfunc import mac
from .version import VERSION_TUPLE from .version import VERSION_TUPLE
from .gen.constfunc import win, get_env_var from .gen.constfunc import win, get_env_var
#-------------------------------------------------------------------------
#
# Instantiate Localization
#
#-------------------------------------------------------------------------
from .gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
#-------------------------------------------------------------------------
#
# Ensure that output is encoded correctly to stdout and
# stderr. This is much less cumbersome and error-prone than
# encoding individual outputs:
#
#-------------------------------------------------------------------------
try:
# They're the same using python3 on Win or Linux, but sys.stdout.encoding
# gives the wrong answer on Darwin.
if mac():
_encoding = sys.getdefaultencoding()
else:
_encoding = sys.stdout.encoding
except:
_encoding = "UTF-8"
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding=_encoding,
buffering=1, errors='backslashreplace')
sys.stderr = open(sys.stderr.fileno(), mode='w', encoding=_encoding,
buffering=1, errors='backslashreplace')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Setup logging # Setup logging
@ -110,14 +142,6 @@ sys.excepthook = exc_hook
from .gen.mime import mime_type_is_defined from .gen.mime import mime_type_is_defined
#-------------------------------------------------------------------------
#
# Instantiate Localization
#
#-------------------------------------------------------------------------
from .gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #