From fe3f067d6a4ddd96deeef7c2b542500ed0c3f7f1 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Mon, 20 May 2013 01:48:17 +0200 Subject: [PATCH] String encoding was broken during redirection of stdout. The encoding now defaults to UTF-8 whenever stdout does not point to a proper terminal. --- changes.py | 1 + gitinspector.py | 1 + terminal.py | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/changes.py b/changes.py index b65bf45..b1a7147 100644 --- a/changes.py +++ b/changes.py @@ -18,6 +18,7 @@ # along with gitinspector. If not, see . from __future__ import print_function +from __future__ import unicode_literals from outputable import Outputable import codecs import extensions diff --git a/gitinspector.py b/gitinspector.py index e42c7cd..f061790 100755 --- a/gitinspector.py +++ b/gitinspector.py @@ -50,6 +50,7 @@ class Runner: def output(self): terminal.skip_escapes(not sys.stdout.isatty()) + terminal.set_stdout_encoding() previous_directory = os.getcwd() os.chdir(self.repo) format.output_header() diff --git a/terminal.py b/terminal.py index 3a6ddd1..69e4c02 100644 --- a/terminal.py +++ b/terminal.py @@ -18,6 +18,7 @@ # along with gitinspector. If not, see . from __future__ import print_function +import codecs import os import platform import sys @@ -101,3 +102,7 @@ def get_size(): return (width, height) return (80, 25) + +def set_stdout_encoding(): + if not sys.stdout.isatty() and sys.version_info < (3,): + sys.stdout = codecs.getwriter('utf-8')(sys.stdout)