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:
parent
c11fbe8bfc
commit
bd27233cfc
@ -43,9 +43,41 @@ from subprocess import Popen, PIPE
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .gen.const import APP_GRAMPS, USER_DIRLIST, HOME_DIR
|
||||
from .gen.constfunc import mac
|
||||
from .version import VERSION_TUPLE
|
||||
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
|
||||
@ -110,14 +142,6 @@ sys.excepthook = exc_hook
|
||||
|
||||
from .gen.mime import mime_type_is_defined
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Instantiate Localization
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
from .gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user