String encoding was broken during redirection of stdout.

The encoding now defaults to UTF-8 whenever stdout does not point to a
proper terminal.
This commit is contained in:
Adam Waldenberg 2013-05-20 01:48:17 +02:00
parent cf40f16119
commit fe3f067d6a
3 changed files with 7 additions and 0 deletions

View file

@ -18,6 +18,7 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from __future__ import unicode_literals
from outputable import Outputable
import codecs
import extensions

View file

@ -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()

View file

@ -18,6 +18,7 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
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)