python: Better check for keys in dicts

Python 3 lost the dict.has_key() method. Instead it requires using the
"in" operator.

This is also compatible with Python 2.

Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Mathieu Bridon
2018-07-05 15:17:35 +02:00
committed by Dylan Baker
parent 9b34742495
commit 1d209275c2
7 changed files with 21 additions and 23 deletions

View File

@@ -64,7 +64,7 @@ class glx_enum(gl_XML.gl_enum):
else:
mode = 1
if not self.functions.has_key(n):
if n not in self.functions:
self.functions[ n ] = [c, mode]
return

View File

@@ -842,7 +842,7 @@ generic_%u_byte( GLint rop, const void * ptr )
def printPixelFunction(self, f):
if self.pixel_stubs.has_key( f.name ):
if f.name in self.pixel_stubs:
# Normally gl_function::get_parameter_string could be
# used. However, this call needs to have the missing
# dimensions (e.g., a fake height value for

View File

@@ -71,7 +71,7 @@ class glx_enum_function(object):
for enum_name in enum_dict:
e = enum_dict[ enum_name ]
if e.functions.has_key( match_name ):
if match_name in e.functions:
[count, mode] = e.functions[ match_name ]
if mode_set and mode != self.mode:
@@ -79,11 +79,11 @@ class glx_enum_function(object):
self.mode = mode
if self.enums.has_key( e.value ):
if e.value in self.enums:
if e.name not in self.enums[ e.value ]:
self.enums[ e.value ].append( e )
else:
if not self.count.has_key( count ):
if count not in self.count:
self.count[ count ] = []
self.enums[ e.value ] = [ e ]
@@ -131,7 +131,7 @@ class glx_enum_function(object):
for a in self.enums:
count += 1
if self.count.has_key(-1):
if -1 in self.count:
return 0
# Determine if there is some mask M, such that M = (2^N) - 1,
@@ -356,7 +356,7 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
sig = ef.signature()
if enum_sigs.has_key( sig ):
if sig in enum_sigs:
aliases.append( [func.name, enum_sigs[ sig ]] )
else:
enum_sigs[ sig ] = func.name
@@ -477,10 +477,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
sig = ef.signature()
if not enum_functions.has_key(func.name):
if func.name not in enum_functions:
enum_functions[ func.name ] = sig
if not enum_sigs.has_key( sig ):
if sig not in enum_sigs:
enum_sigs[ sig ] = ef
@@ -496,7 +496,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
if func.server_handcode: continue
if not func.has_variable_size_request(): continue
if enum_functions.has_key(func.name):
if func.name in enum_functions:
sig = enum_functions[func.name]
ef = enum_sigs[ sig ]
@@ -621,7 +621,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
# already be emitted, don't emit this function. Instead, add
# it to the list of function aliases.
if self.counter_sigs.has_key(sig):
if sig in self.counter_sigs:
n = self.counter_sigs[sig];
alias = [f.name, n]
else:

View File

@@ -943,7 +943,7 @@ class gl_api(object):
temp_name = child.get( "name" )
self.category_dict[ temp_name ] = [cat_name, cat_number]
if self.functions_by_name.has_key( func_name ):
if func_name in self.functions_by_name:
func = self.functions_by_name[ func_name ]
func.process_element( child )
else:
@@ -980,7 +980,7 @@ class gl_api(object):
if (cat == None) or (cat == cat_name):
[func_cat_type, key] = classify_category(cat_name, cat_number)
if not lists[func_cat_type].has_key(key):
if key not in lists[func_cat_type]:
lists[func_cat_type][key] = {}
lists[func_cat_type][key][func.name] = func
@@ -1057,7 +1057,7 @@ class gl_api(object):
def get_category_for_name( self, name ):
if self.category_dict.has_key(name):
if name in self.category_dict:
return self.category_dict[name]
else:
return ["<unknown category>", None]

View File

@@ -135,7 +135,7 @@ typedef struct {
for n in func.entry_points:
cat, num = api.get_category_for_name(n)
if (cat.startswith("es") or cat.startswith("GL_OES")):
if not categories.has_key(cat):
if cat not in categories:
categories[cat] = []
proto = 'GLAPI %s GLAPIENTRY %s(%s);' \
% (func.return_type, "gl" + n, func.get_parameter_string(n))

View File

@@ -168,7 +168,7 @@ def abi_parse_xml(xml):
else:
attrs['handcode'] = None
if entry_dict.has_key(name):
if name in entry_dict:
raise Exception('%s is duplicated' % (name))
cols = []
@@ -180,8 +180,7 @@ def abi_parse_xml(xml):
ent = ABIEntry(cols, attrs, func)
entry_dict[ent.name] = ent
entries = entry_dict.values()
entries.sort()
entries = sorted(entry_dict.values())
return entries
@@ -246,12 +245,11 @@ def abi_parse(filename):
raise Exception('invalid slot in %s' % (line))
ent = ABIEntry(cols, attrs)
if entry_dict.has_key(ent.name):
if ent.name in entry_dict:
raise Exception('%s is duplicated' % (ent.name))
entry_dict[ent.name] = ent
entries = entry_dict.values()
entries.sort()
entries = sorted(entry_dict.values())
return entries

View File

@@ -42,7 +42,7 @@ def escapeCString (s):
# open quote
q = u'\u201d'
r = r + q
elif escapeSeqs.has_key(s[i]):
elif s[i] in escapeSeqs:
r = r + escapeSeqs[s[i]]
else:
r = r + s[i]
@@ -90,7 +90,7 @@ def expandCString (s):
escape = False
r = r + chr(num)
else:
if escapeSeqs.has_key(s[i]):
if s[i] in escapeSeqs:
r = r + escapeSeqs[s[i]]
escape = False
elif s[i] >= '0' and s[i] <= '7':