ext_gpu_shader4: add compiler tests for everything
[piglit.git] / framework / compat.py
blob85030b8e68eeea08843f611c7b8b8fa2706fe8f4
1 # coding=utf-8
2 # Copyright (c) 2016 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """A small library that contains libraries equivalent to six
24 This function is pending upstreaming in six.
26 """
28 from __future__ import (
29 absolute_import, division, print_function, unicode_literals
32 import six
34 def python_2_bool_compatible(class_):
35 """A decorator to fix __bool__/__nonzero__ name changes."""
36 if six.PY2:
37 try:
38 class_.__nonzero__ = class_.__bool__
39 except AttributeError:
40 raise ValueError(
41 "@python_2_bool_compatible cannot be applied to {} because "
42 "it doesn't define __bool__().".format(class_.__name__))
43 return class_
46 # Some version of six don't have this function
47 try:
48 from six import python_2_unicode_compatible
49 except ImportError:
50 def python_2_unicode_compatible(class_):
51 """A decorator to fix __str/__bytes__/__unicode__ name changes."""
52 if six.PY2:
53 failed = False
54 try:
55 class_.__unicode__ = class_.__str__
56 except AttributeError:
57 failed = True
59 try:
60 class_.__str__ = class_.__bytes__
61 except AttributeError:
62 if failed:
63 raise ValueError(
64 "@python_2_unicode_compatible cannot be applied to {} "
65 "because it doesn't define __str__() "
66 "or __bytes__().".format(class_.__name__))
67 return class_
70 try:
71 from six import viewvalues
72 except ImportError:
73 if six.PY2:
74 viewvalues = lambda d: d.viewvalues()
75 elif six.PY3:
76 viewvalues = lambda d: d.values()