forked from platformio/platformio-core
Use locale encoding to decode subprocess output // Resolve #2890
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
|
import locale
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@ -30,6 +31,10 @@ def get_filesystem_encoding():
|
|||||||
return sys.getfilesystemencoding() or sys.getdefaultencoding()
|
return sys.getfilesystemencoding() or sys.getdefaultencoding()
|
||||||
|
|
||||||
|
|
||||||
|
def get_locale_encoding():
|
||||||
|
return locale.getdefaultlocale()[1]
|
||||||
|
|
||||||
|
|
||||||
def get_class_attributes(cls):
|
def get_class_attributes(cls):
|
||||||
attributes = inspect.getmembers(cls, lambda a: not (inspect.isroutine(a)))
|
attributes = inspect.getmembers(cls, lambda a: not (inspect.isroutine(a)))
|
||||||
return {
|
return {
|
||||||
|
@ -19,7 +19,12 @@ from os.path import isdir, isfile, join, normpath
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from platformio import exception
|
from platformio import exception
|
||||||
from platformio.compat import WINDOWS, get_filesystem_encoding, string_types
|
from platformio.compat import (
|
||||||
|
WINDOWS,
|
||||||
|
get_filesystem_encoding,
|
||||||
|
get_locale_encoding,
|
||||||
|
string_types,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AsyncPipeBase(object):
|
class AsyncPipeBase(object):
|
||||||
@ -122,7 +127,9 @@ def exec_command(*args, **kwargs):
|
|||||||
for k, v in result.items():
|
for k, v in result.items():
|
||||||
if isinstance(result[k], bytes):
|
if isinstance(result[k], bytes):
|
||||||
try:
|
try:
|
||||||
result[k] = result[k].decode(get_filesystem_encoding())
|
result[k] = result[k].decode(
|
||||||
|
get_locale_encoding() or get_filesystem_encoding()
|
||||||
|
)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
result[k] = result[k].decode("latin-1")
|
result[k] = result[k].decode("latin-1")
|
||||||
if v and isinstance(v, string_types):
|
if v and isinstance(v, string_types):
|
||||||
|
Reference in New Issue
Block a user