1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-09-23 12:21:54 +01:00

Add a fallback for sys.stdout.encoding uses

In some environments (e.g. nosetest), sys.stdout.encoding can be None.
Add a fallback to handle these cases.
This commit is contained in:
Valentin Schneider
2018-09-20 12:37:52 -07:00
committed by Marc Bonnici
parent d86d67f49c
commit 5d97c3186b
8 changed files with 11 additions and 11 deletions

View File

@@ -152,7 +152,7 @@ class ApkInfo(object):
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
if sys.version_info[0] == 3:
output = output.decode(sys.stdout.encoding, 'replace')
output = output.decode(sys.stdout.encoding or 'utf-8', 'replace')
except subprocess.CalledProcessError as e:
raise HostError('Error parsing APK file {}. `aapt` says:\n{}'
.format(apk_path, e.output))

View File

@@ -280,7 +280,7 @@ class SshConnection(object):
# the regex removes line breaks potential introduced when writing
# command to shell.
if sys.version_info[0] == 3:
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding, 'replace'))
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding or 'utf-8', 'replace'))
else:
output = process_backspaces(self.conn.before)
output = re.sub(r'\r([^\n])', r'\1', output)

View File

@@ -153,11 +153,11 @@ if sys.version_info[0] == 3:
if isinstance(value, regex_type):
if isinstance(value.pattern, bytes):
return value
return re.compile(value.pattern.encode(sys.stdout.encoding),
return re.compile(value.pattern.encode(sys.stdout.encoding or 'utf-8'),
value.flags & ~re.UNICODE)
else:
if isinstance(value, str):
value = value.encode(sys.stdout.encoding)
value = value.encode(sys.stdout.encoding or 'utf-8')
return re.compile(value)
else:
def regex(value):

View File

@@ -25,6 +25,6 @@ def get_commit():
if p.returncode:
return None
if sys.version_info[0] == 3 and isinstance(std, bytes):
return std[:8].decode(sys.stdout.encoding, 'replace')
return std[:8].decode(sys.stdout.encoding or 'utf-8', 'replace')
else:
return std[:8]