[Piglit] [PATCH 1/2] framework: fix unicode input for python 2.x

Jan Vesely jan.vesely at rutgers.edu
Wed Mar 30 04:24:28 UTC 2016


On Fri, 2016-03-25 at 14:28 -0700, Dylan Baker wrote:
> In python 3.x input is unicode by default, but in python 2.x
> everything
> is a byte string by default, 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 runnging with python 2.x
> decode each input element into unicode using utf-8 as soon as the
> input
> is received.
> 
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>

This breaks all partial commands with python3. only ./piglit checks
python version, the rest try to do decode unconditionally. Is this
intended?


$ python3 ./piglit-print-commands.py tests/cl.py
Traceback (most recent call last):
  File "./piglit-print-commands.py", line 89, in <module>
    main()
  File "./piglit-print-commands.py", line 41, in main
    input_ = [i.decode('utf-8') for i in sys.argv[1:]]
  File "./piglit-print-commands.py", line 41, in <listcomp>
    input_ = [i.decode('utf-8') for i in sys.argv[1:]]
AttributeError: 'str' object has no attribute 'decode'

Jan

> ---
>  piglit                   | 17 +++++++++++++----
>  piglit-print-commands.py |  7 +++++--
>  piglit-resume.py         |  6 +++++-
>  piglit-run.py            |  6 +++++-
>  piglit-summary-html.py   |  6 +++++-
>  piglit-summary.py        |  6 +++++-
>  6 files changed, 38 insertions(+), 10 deletions(-)
> 
> diff --git a/piglit b/piglit
> index 514dd3f..cc05bcc 100755
> --- a/piglit
> +++ b/piglit
> @@ -31,12 +31,16 @@ capture -h/--help and the results will not be
> useful.
>  
>  """
>  
> -from __future__ import print_function
> -
> +from __future__ import (
> +    absolute_import, division, print_function, unicode_literals
> +)
> +import argparse
>  import os
>  import os.path as path
>  import sys
> -import argparse
> +
> +import six
> +
>  
>  def setup_module_search_path():
>      """Add Piglit's data directory to Python's module search path.
> @@ -110,6 +114,11 @@ import framework.programs.summary as summary
>  
>  def main():
>      """ Parse argument and call other executables """
> +    if six.PY2:
> +        input_ = [i.decode('utf-8') for i in sys.argv[1:]]
> +    elif six.PY3:
> +        input_ = sys.argv[1:]
> +
>      parser = argparse.ArgumentParser()
>      subparsers = parser.add_subparsers()
>  
> @@ -147,7 +156,7 @@ def main():
>      # Parse the known arguments (piglit run or piglit summary html
> for
>      # example), and then pass the arguments that this parser doesn't
> know about
>      # to that executable
> -    parsed, args = parser.parse_known_args()
> +    parsed, args = parser.parse_known_args(input_)
>      returncode = parsed.func(args)
>      sys.exit(returncode)
>  
> diff --git a/piglit-print-commands.py b/piglit-print-commands.py
> index c891e8e..793ffae 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
> diff --git a/piglit-resume.py b/piglit-resume.py
> index 6b78529..c8f0fe2 100755
> --- a/piglit-resume.py
> +++ b/piglit-resume.py
> @@ -26,7 +26,11 @@ Deprecated compatability wrapper
>  
>  """
>  
> +from __future__ import (
> +    absolute_import, division, print_function, unicode_literals
> +)
>  import sys
> +
>  from framework.programs.run import resume
>  
> -resume(sys.argv[1:])
> +resume([i.decode('utf-8') for i in sys.argv[1:]])
> diff --git a/piglit-run.py b/piglit-run.py
> index 4c0f878..7f6cf1a 100755
> --- a/piglit-run.py
> +++ b/piglit-run.py
> @@ -26,7 +26,11 @@ Deprecated compatability wrapper
>  
>  """
>  
> +from __future__ import (
> +    absolute_import, division, print_function, unicode_literals
> +)
>  import sys
> +
>  from framework.programs.run import run
>  
> -run(sys.argv[1:])
> +run([i.decode('utf-8') for i in sys.argv[1:]])
> diff --git a/piglit-summary-html.py b/piglit-summary-html.py
> index 4b5278e..163d006 100755
> --- a/piglit-summary-html.py
> +++ b/piglit-summary-html.py
> @@ -22,7 +22,11 @@
>  
>  """ Deprecated compatability wrapper for html summary """
>  
> +from __future__ import (
> +    absolute_import, division, print_function, unicode_literals
> +)
>  import sys
> +
>  from framework.programs.summary import html
>  
> -html(sys.argv[1:])
> +html([i.decode('utf-8') for i in sys.argv[1:]])
> diff --git a/piglit-summary.py b/piglit-summary.py
> index d1294be..62f29ce 100755
> --- a/piglit-summary.py
> +++ b/piglit-summary.py
> @@ -22,7 +22,11 @@
>  
>  """ Deprecated compatability wrapper for console summary """
>  
> +from __future__ import (
> +    absolute_import, division, print_function, unicode_literals
> +)
>  import sys
> +
>  from framework.programs.summary import console
>  
> -console(sys.argv[1:])
> +console([i.decode('utf-8') for i in sys.argv[1:]])
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20160330/2f2c657c/attachment.sig>


More information about the Piglit mailing list