Merge pull request #1 from mshal/bug-1006582

Bug 1006582 - Set output encoding in case of file redirects; r=glandium
This commit is contained in:
Mike Hommey 2014-05-30 07:18:20 +09:00
Родитель b1b4c91659 c8decd76ff
Коммит 2eab09769f
1 изменённых файлов: 10 добавлений и 0 удалений

Просмотреть файл

@ -17,9 +17,19 @@ import json
import os
import socket
import sys
import codecs
import locale
from base_server import CommandClient, PORT
from errno import ECONNREFUSED
# Set the output encoding in case the output is being redirected to a file. In
# this case, the default encoding is ASCII, but we may have unicode characters
# in stderr/stdout, which causes python to report a UnicodeEncodeError.
if not sys.stdout.encoding:
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout);
if not sys.stderr.encoding:
sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr);
if __name__ == '__main__':
cmd = sys.argv[1:]
if cmd: