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/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals
from outputable import Outputable from outputable import Outputable
import codecs import codecs
import extensions import extensions

View file

@ -50,6 +50,7 @@ class Runner:
def output(self): def output(self):
terminal.skip_escapes(not sys.stdout.isatty()) terminal.skip_escapes(not sys.stdout.isatty())
terminal.set_stdout_encoding()
previous_directory = os.getcwd() previous_directory = os.getcwd()
os.chdir(self.repo) os.chdir(self.repo)
format.output_header() format.output_header()

View file

@ -18,6 +18,7 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function from __future__ import print_function
import codecs
import os import os
import platform import platform
import sys import sys
@ -101,3 +102,7 @@ def get_size():
return (width, height) return (width, height)
return (80, 25) 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)