fix unicode decode error on windows

This commit is contained in:
Liu
2017-10-02 19:34:27 +08:00
parent 560ba8fef7
commit 3962406ef7
2 changed files with 13 additions and 1 deletions
+5
View File
@@ -4,6 +4,7 @@ from __future__ import absolute_import, division
import os
import sys
import locale
from pip._vendor.six import text_type
@@ -72,6 +73,10 @@ if sys.version_info >= (3,):
try:
return s.decode(sys.__stdout__.encoding)
except UnicodeDecodeError:
if sys.__stdout__.encoding == 'utf-8':
encoding = locale.getdefaultlocale()[1]
if encoding is not None and encoding.lower() != 'utf-8':
return s.decode(encoding)
return s.decode('utf_8')
def native_str(s, replace=False):
+8 -1
View File
@@ -2,6 +2,8 @@ import os
import subprocess
import shlex
import signal
import sys
import locale
from pexpect.popen_spawn import PopenSpawn
@@ -46,9 +48,14 @@ class Command(object):
@property
def _default_pexpect_kwargs(self):
encoding = 'utf-8'
if sys.platform == 'win32':
default_encoding = locale.getdefaultlocale()[1]
if default_encoding is not None:
encoding = default_encoding
return {
'env': os.environ.copy(),
'encoding': 'utf-8',
'encoding': encoding,
'timeout': self.timeout
}