[r21753]GrampsLocale: Separate self.encoding from sys.stdout.encoding
Because python standard library functions encode to locale.getpreferredencoding or sys.getdefaultencoding, not to sys.stdout.encoding. svn: r21756
This commit is contained in:
parent
67b6abb3df
commit
f2f148b7ba
@ -211,18 +211,24 @@ class GrampsLocale(object):
|
|||||||
locale.setlocale(locale.LC_MONETARY, self.currency)
|
locale.setlocale(locale.LC_MONETARY, self.currency)
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
pass
|
pass
|
||||||
#Next, we need to know what is the encoding from the native environment:
|
#Next, we need to know what is the encoding from the native
|
||||||
self.encoding = sys.stdout.encoding or sys.getdefaultencoding()
|
#environment. This is used by python standard library funcions which
|
||||||
|
#localize their output, e.g. time.strftime():
|
||||||
|
self.encoding = locale.getpreferredencoding() or sys.getdefaultencoding()
|
||||||
#Ensure that output is encoded correctly to stdout and stderr. This is
|
#Ensure that output is encoded correctly to stdout and stderr. This is
|
||||||
#much less cumbersome and error-prone than encoding individual outputs
|
#much less cumbersome and error-prone than encoding individual outputs
|
||||||
#and better handles the differences between Python 2 and Python 3:
|
#and better handles the differences between Python 2 and Python 3:
|
||||||
|
_encoding = sys.stdout.encoding or sys.getdefaultencoding()
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
sys.stdout = codecs.getwriter(self.encoding)(sys.stdout, 'backslashreplace')
|
sys.stdout = codecs.getwriter(_encoding)(sys.stdout,
|
||||||
sys.stderr = codecs.getwriter(self.encoding)(sys.stderr, 'backslashreplace')
|
'backslashreplace')
|
||||||
|
sys.stderr = codecs.getwriter(_encoding)(sys.stderr,
|
||||||
|
'backslashreplace')
|
||||||
else:
|
else:
|
||||||
sys.stdout = codecs.getwriter(self.encoding)(sys.stdout.detach(), 'backslashreplace')
|
sys.stdout = codecs.getwriter(_encoding)(sys.stdout.detach(),
|
||||||
sys.stderr = codecs.getwriter(self.encoding)(sys.stderr.detach(), 'backslashreplace')
|
'backslashreplace')
|
||||||
|
sys.stderr = codecs.getwriter(_encoding)(sys.stderr.detach(),
|
||||||
|
'backslashreplace')
|
||||||
|
|
||||||
|
|
||||||
#GtkBuilder depends on reading Glade files as UTF-8 and crashes if it
|
#GtkBuilder depends on reading Glade files as UTF-8 and crashes if it
|
||||||
|
Loading…
Reference in New Issue
Block a user