From f0b32f0b791dfc9944486f7abacc96b39f03a4c5 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 3 Mar 2021 18:14:17 +1100 Subject: [PATCH] ci: Fix missing sys.stdout.encoding in python2 runners Regression in dad02307767d0490bab982fa366f5236828bb4c5 --- tools/ci/python_packages/tiny_test_fw/DUT.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/ci/python_packages/tiny_test_fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py index 95c672764b..a93fa3903e 100644 --- a/tools/ci/python_packages/tiny_test_fw/DUT.py +++ b/tools/ci/python_packages/tiny_test_fw/DUT.py @@ -81,10 +81,13 @@ def _decode_data(data): if isinstance(data, bytes): # convert bytes to string. This is a bit of a hack, we know that we want to log this # later so encode to the stdout encoding with backslash escapes for anything non-encodable + encoding = sys.stdout.encoding + if encoding is None: + encoding = 'ascii' try: - return data.decode(sys.stdout.encoding, "backslashreplace") - except UnicodeDecodeError: # Python <3.5 doesn't support backslashreplace - return data.decode(sys.stdout.encoding, "replace") + return data.decode(encoding, "backslashreplace") + except (UnicodeDecodeError, TypeError): # Python <3.5 doesn't support backslashreplace + return data.decode(encoding, "replace") return data