diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-04-15 23:02:37 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-04-16 03:28:43 +0000 |
commit | ec0ba4185a3b8dbd8dd5e8f3451243f831d9e9fc (patch) | |
tree | ba4ef53eefa606c6d75ae9323d7b778f6790e9c0 | |
parent | 27dd00b30cf284b0ceb5c5ca90a835d724482eff (diff) |
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 <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rwxr-xr-x | test/sampleif.py | 7 |
1 files changed, 6 insertions, 1 deletions
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() |