diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2016-03-25 13:37:36 -0700 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2016-03-28 09:51:22 -0700 |
commit | 6a9d0146407656bcf54b61c44b3d06fa6ddb12d9 (patch) | |
tree | 9f478503bcdef0e533c00d601e0e44c72e211a98 /piglit-print-commands.py | |
parent | cc83192b948e056b1c63636e39255030dd1ceee9 (diff) |
framework: fix unicode command line arguments with python 2.x
In python 3.x input is unicode by default, but in python 2.x everything
is a byte string by default (which assumes ascii encoding), this
includes input. Currently when running with python 3.x it's possible to
use unicode for input, but python 2.x will choke when it tries to encode
the bytes into unicode using the ascii codec.
For example, this will work with python 3.x but no with python 2.x:
(The character is yuki, Japanese for snow, if memory serves)
./piglit run quick 雪 -c
This is actually pretty easy to fix, when running with python 2.x
decode each input element into unicode using utf-8 as soon as the input
is received. This fixes the above example to work.
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Tested-by: Marek Olšák <marek.olsak@amd.com>
Diffstat (limited to 'piglit-print-commands.py')
-rwxr-xr-x | piglit-print-commands.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/piglit-print-commands.py b/piglit-print-commands.py index c891e8e0a..793ffaef6 100755 --- a/piglit-print-commands.py +++ b/piglit-print-commands.py @@ -22,7 +22,9 @@ # DEALINGS IN THE SOFTWARE. -from __future__ import print_function +from __future__ import ( + absolute_import, division, print_function, unicode_literals +) import argparse import sys import os @@ -36,6 +38,7 @@ from framework.test import Test, GleanTest def main(): + input_ = [i.decode('utf-8') for i in sys.argv[1:]] parser = argparse.ArgumentParser(parents=[parsers.CONFIG]) parser.add_argument("-t", "--include-tests", default=[], @@ -52,7 +55,7 @@ def main(): parser.add_argument("testProfile", metavar="<Path to testfile>", help="Path to results folder") - args = parser.parse_args() + args = parser.parse_args(input_) options.OPTIONS.exclude_filter = args.exclude_tests options.OPTIONS.include_filter = args.include_tests |