From ec0ba4185a3b8dbd8dd5e8f3451243f831d9e9fc Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Apr 2019 23:02:37 +0100 Subject: [PATCH] test: fix sampleif.py on weird systems using Python 3.6 and older Setting PYTHONIOENCODING=utf-8 would also work, but only if it is done for every test that could possibly invoke the extcap. Let's patch the script instead to force UTF-8 for its output encoding. Thanks to Greg for the suggestion at https://stackoverflow.com/a/4374457/427545 Change-Id: I2e39e65e49465392c5b077c8b13ed931073661fb Reviewed-on: https://code.wireshark.org/review/32868 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- test/sampleif.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/sampleif.py b/test/sampleif.py index b9c6df983c..4cb367cfca 100755 --- a/test/sampleif.py +++ b/test/sampleif.py @@ -6,7 +6,7 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # -import argparse, os, sys +import argparse, codecs, os, sys parser = argparse.ArgumentParser() @@ -39,6 +39,11 @@ def extcap_config(): def main(): + # In Python 3.6 and older, the encoding of stdout depends on the locale. + # Do not rely on that and force a sane encoding instead. Python 3.7 has + # improved, see https://www.python.org/dev/peps/pep-0540/ + sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) + args = parser.parse_args() if args.extcap_interfaces: return extcap_interfaces()