[glib] glib-mkenums: Python2: use locale encoding when redirecting stdout
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] glib-mkenums: Python2: use locale encoding when redirecting stdout
- Date: Wed, 26 Jul 2017 20:28:48 +0000 (UTC)
commit 867b5e6f902e945e8a02a3d2d35d698e19f8f892
Author: Christoph Reiter <creiter src gnome org>
Date: Wed Jul 26 11:26:00 2017 +0200
glib-mkenums: Python2: use locale encoding when redirecting stdout
In case of Python 2 and stdout being redirected to a file, sys.stdout.encoding
is None and it defaults ASCII for encoding text.
To match the behaviour of Python 3, which uses the locale encoding also when
redirecting to a file, wrap sys.stdout with a StreamWriter using the
locale encoding.
https://bugzilla.gnome.org/show_bug.cgi?id=785113
gobject/glib-mkenums.in | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in
index fccc000..9fae3a8 100755
--- a/gobject/glib-mkenums.in
+++ b/gobject/glib-mkenums.in
@@ -16,6 +16,8 @@ import sys
import tempfile
import io
import errno
+import codecs
+import locale
VERSION_STR = '''glib-mkenums version @VERSION@
glib-genmarshal comes with ABSOLUTELY NO WARRANTY.
@@ -24,7 +26,13 @@ the GNU General Public License which can be found in the
GLib source package. Sources, examples and contact
information are available at http://www.gtk.org'''
-output_stream = sys.stdout
+# Python 2 defaults to ASCII in case stdout is redirected.
+# This should make it match Python 3, which uses the locale encoding.
+if sys.stdout.encoding is None:
+ output_stream = codecs.getwriter(
+ locale.getpreferredencoding())(sys.stdout)
+else:
+ output_stream = sys.stdout
# pylint: disable=too-few-public-methods
class Color:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]