mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-07 17:20:21 +01:00
python: Do not mix bytes and unicode strings
Mixing the two is a long-standing recipe for errors in Python 2, so much so that Python 3 now completely separates them. This commit stops treating both as if they were the same, and in the process makes the script compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr> Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
This commit is contained in:
parent
c644b2d7a7
commit
14f1ab998f
1 changed files with 10 additions and 1 deletions
|
|
@ -35,6 +35,12 @@ import traceback
|
|||
|
||||
from nir_opcodes import opcodes
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
string_type = unicode
|
||||
|
||||
else:
|
||||
string_type = str
|
||||
|
||||
_type_re = re.compile(r"(?P<type>int|uint|bool|float)?(?P<bits>\d+)?")
|
||||
|
||||
def type_bits(type_str):
|
||||
|
|
@ -66,11 +72,14 @@ class VarSet(object):
|
|||
class Value(object):
|
||||
@staticmethod
|
||||
def create(val, name_base, varset):
|
||||
if isinstance(val, bytes):
|
||||
val = val.decode('utf-8')
|
||||
|
||||
if isinstance(val, tuple):
|
||||
return Expression(val, name_base, varset)
|
||||
elif isinstance(val, Expression):
|
||||
return val
|
||||
elif isinstance(val, (str, unicode)):
|
||||
elif isinstance(val, string_type):
|
||||
return Variable(val, name_base, varset)
|
||||
elif isinstance(val, (bool, int, long, float)):
|
||||
return Constant(val, name_base)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue