BaseTools: Remove the deprecated hash_key()

Replace "has_key()" with "in" to be compatible with python3.
Based on "futurize -f lib2to3.fixes.fix_has_key"

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Gary Lin 2018-06-25 18:31:29 +08:00 committed by Yonghong Zhu
parent 890d8ede68
commit 27c4ceb41c
18 changed files with 39 additions and 40 deletions

View File

@ -140,7 +140,7 @@ class BaseINIFile(object):
sObj = self.GetSectionInstance(self, name, (len(sname_arr) > 1)) sObj = self.GetSectionInstance(self, name, (len(sname_arr) > 1))
sObj._start = index sObj._start = index
sObjs.append(sObj) sObjs.append(sObj)
if not self._sections.has_key(name.lower()): if name.lower() not in self._sections:
self._sections[name.lower()] = [sObj] self._sections[name.lower()] = [sObj]
else: else:
self._sections[name.lower()].append(sObj) self._sections[name.lower()].append(sObj)

View File

@ -26,7 +26,7 @@ class SurfaceObject(object):
""" """
obj = object.__new__(cls, *args, **kwargs) obj = object.__new__(cls, *args, **kwargs)
if not cls._objs.has_key("None"): if "None" not in cls._objs:
cls._objs["None"] = [] cls._objs["None"] = []
cls._objs["None"].append(obj) cls._objs["None"].append(obj)
@ -47,7 +47,7 @@ class SurfaceObject(object):
self.GetFileObj().Destroy(self) self.GetFileObj().Destroy(self)
del self._fileObj del self._fileObj
# dereference self from _objs arrary # dereference self from _objs arrary
assert self._objs.has_key(key), "when destory, object is not in obj list" assert key in self._objs, "when destory, object is not in obj list"
assert self in self._objs[key], "when destory, object is not in obj list" assert self in self._objs[key], "when destory, object is not in obj list"
self._objs[key].remove(self) self._objs[key].remove(self)
if len(self._objs[key]) == 0: if len(self._objs[key]) == 0:
@ -95,7 +95,7 @@ class SurfaceObject(object):
if self not in cls._objs["None"]: if self not in cls._objs["None"]:
ErrorMsg("Sufrace object does not be create into None list") ErrorMsg("Sufrace object does not be create into None list")
cls._objs["None"].remove(self) cls._objs["None"].remove(self)
if not cls._objs.has_key(relativePath): if relativePath not in cls._objs:
cls._objs[relativePath] = [] cls._objs[relativePath] = []
cls._objs[relativePath].append(self) cls._objs[relativePath].append(self)

View File

@ -61,7 +61,7 @@ class INFFile(ini.BaseINIFile):
classname = self.GetProduceLibraryClass() classname = self.GetProduceLibraryClass()
if classname is not None: if classname is not None:
libobjdict = INFFile._libobjs libobjdict = INFFile._libobjs
if libobjdict.has_key(classname): if classname in libobjdict:
if self not in libobjdict[classname]: if self not in libobjdict[classname]:
libobjdict[classname].append(self) libobjdict[classname].append(self)
else: else:
@ -169,7 +169,7 @@ class INFLibraryClassObject(INFSectionObject):
def Parse(self): def Parse(self):
self._classname = self.GetLineByOffset(self._start).split('#')[0].strip() self._classname = self.GetLineByOffset(self._start).split('#')[0].strip()
objdict = INFLibraryClassObject._objs objdict = INFLibraryClassObject._objs
if objdict.has_key(self._classname): if self._classname in objdict:
objdict[self._classname].append(self) objdict[self._classname].append(self)
else: else:
objdict[self._classname] = [self] objdict[self._classname] = [self]
@ -241,7 +241,7 @@ class INFSourceObject(INFSectionObject):
self.mFilename = os.path.basename(self.GetSourceFullPath()) self.mFilename = os.path.basename(self.GetSourceFullPath())
objdict = INFSourceObject._objs objdict = INFSourceObject._objs
if not objdict.has_key(self.mFilename): if self.mFilename not in objdict:
objdict[self.mFilename] = [self] objdict[self.mFilename] = [self]
else: else:
objdict[self.mFilename].append(self) objdict[self.mFilename].append(self)
@ -303,7 +303,7 @@ class INFPcdObject(INFSectionObject):
self.mDefaultValue = arr[1].strip() self.mDefaultValue = arr[1].strip()
objdict = INFPcdObject._objs objdict = INFPcdObject._objs
if objdict.has_key(self.GetName()): if self.GetName() in objdict:
if self not in objdict[self.GetName()]: if self not in objdict[self.GetName()]:
objdict[self.GetName()].append(self) objdict[self.GetName()].append(self)
else: else:

View File

@ -1798,8 +1798,8 @@ class PlatformAutoGen(AutoGen):
# retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file. # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
BPDGToolName = None BPDGToolName = None
for ToolDef in self.ToolDefinition.values(): for ToolDef in self.ToolDefinition.values():
if ToolDef.has_key(TAB_GUID) and ToolDef[TAB_GUID] == self.Platform.VpdToolGuid: if TAB_GUID in ToolDef and ToolDef[TAB_GUID] == self.Platform.VpdToolGuid:
if not ToolDef.has_key("PATH"): if "PATH" not in ToolDef:
EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid) EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)
BPDGToolName = ToolDef["PATH"] BPDGToolName = ToolDef["PATH"]
break break

View File

@ -211,7 +211,7 @@ class VpdInfoFile:
# #
# @param vpd A given VPD PCD # @param vpd A given VPD PCD
def GetOffset(self, vpd): def GetOffset(self, vpd):
if not self._VpdArray.has_key(vpd): if vpd not in self._VpdArray:
return None return None
if len(self._VpdArray[vpd]) == 0: if len(self._VpdArray[vpd]) == 0:

View File

@ -438,14 +438,14 @@ def GenLibraryClasses(ModuleObject):
Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version
if len(BinaryFile.SupArchList) == 0: if len(BinaryFile.SupArchList) == 0:
if LibraryClassDict.has_key('COMMON') and Statement not in LibraryClassDict['COMMON']: if 'COMMON' in LibraryClassDict and Statement not in LibraryClassDict['COMMON']:
LibraryClassDict['COMMON'].append(Statement) LibraryClassDict['COMMON'].append(Statement)
else: else:
LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES'] LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']
LibraryClassDict['COMMON'].append(Statement) LibraryClassDict['COMMON'].append(Statement)
else: else:
for Arch in BinaryFile.SupArchList: for Arch in BinaryFile.SupArchList:
if LibraryClassDict.has_key(Arch): if Arch in LibraryClassDict:
if Statement not in LibraryClassDict[Arch]: if Statement not in LibraryClassDict[Arch]:
LibraryClassDict[Arch].append(Statement) LibraryClassDict[Arch].append(Statement)
else: else:
@ -917,14 +917,14 @@ def GenAsBuiltPacthPcdSections(ModuleObject):
if FileNameObjList: if FileNameObjList:
ArchList = FileNameObjList[0].GetSupArchList() ArchList = FileNameObjList[0].GetSupArchList()
if len(ArchList) == 0: if len(ArchList) == 0:
if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON): if DT.TAB_ARCH_COMMON in PatchPcdDict:
if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]: if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:
PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement) PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)
else: else:
PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement] PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]
else: else:
for Arch in ArchList: for Arch in ArchList:
if PatchPcdDict.has_key(Arch): if Arch in PatchPcdDict:
if Statement not in PatchPcdDict[Arch]: if Statement not in PatchPcdDict[Arch]:
PatchPcdDict[Arch].append(Statement) PatchPcdDict[Arch].append(Statement)
else: else:
@ -967,13 +967,13 @@ def GenAsBuiltPcdExSections(ModuleObject):
ArchList = FileNameObjList[0].GetSupArchList() ArchList = FileNameObjList[0].GetSupArchList()
if len(ArchList) == 0: if len(ArchList) == 0:
if PcdExDict.has_key('COMMON'): if 'COMMON' in PcdExDict:
PcdExDict['COMMON'].append(Statement) PcdExDict['COMMON'].append(Statement)
else: else:
PcdExDict['COMMON'] = [Statement] PcdExDict['COMMON'] = [Statement]
else: else:
for Arch in ArchList: for Arch in ArchList:
if PcdExDict.has_key(Arch): if Arch in PcdExDict:
if Statement not in PcdExDict[Arch]: if Statement not in PcdExDict[Arch]:
PcdExDict[Arch].append(Statement) PcdExDict[Arch].append(Statement)
else: else:
@ -1071,7 +1071,7 @@ def GenBuildOptions(ModuleObject):
for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList: for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:
Statement = '#' + BuilOptionItem.AsBuiltOptionFlags Statement = '#' + BuilOptionItem.AsBuiltOptionFlags
if len(BinaryFile.SupArchList) == 0: if len(BinaryFile.SupArchList) == 0:
if BuildOptionDict.has_key('COMMON'): if 'COMMON' in BuildOptionDict:
if Statement not in BuildOptionDict['COMMON']: if Statement not in BuildOptionDict['COMMON']:
BuildOptionDict['COMMON'].append(Statement) BuildOptionDict['COMMON'].append(Statement)
else: else:
@ -1079,7 +1079,7 @@ def GenBuildOptions(ModuleObject):
BuildOptionDict['COMMON'].append(Statement) BuildOptionDict['COMMON'].append(Statement)
else: else:
for Arch in BinaryFile.SupArchList: for Arch in BinaryFile.SupArchList:
if BuildOptionDict.has_key(Arch): if Arch in BuildOptionDict:
if Statement not in BuildOptionDict[Arch]: if Statement not in BuildOptionDict[Arch]:
BuildOptionDict[Arch].append(Statement) BuildOptionDict[Arch].append(Statement)
else: else:

View File

@ -272,7 +272,7 @@ class InfBinariesObject(InfSectionCommonDef):
pass pass
if InfBianryVerItemObj is not None: if InfBianryVerItemObj is not None:
if self.Binaries.has_key((InfBianryVerItemObj)): if (InfBianryVerItemObj) in self.Binaries:
BinariesList = self.Binaries[InfBianryVerItemObj] BinariesList = self.Binaries[InfBianryVerItemObj]
BinariesList.append((InfBianryVerItemObj, VerComment)) BinariesList.append((InfBianryVerItemObj, VerComment))
self.Binaries[InfBianryVerItemObj] = BinariesList self.Binaries[InfBianryVerItemObj] = BinariesList
@ -522,7 +522,7 @@ class InfBinariesObject(InfSectionCommonDef):
# pass # pass
if InfBianryCommonItemObj is not None: if InfBianryCommonItemObj is not None:
if self.Binaries.has_key((InfBianryCommonItemObj)): if (InfBianryCommonItemObj) in self.Binaries:
BinariesList = self.Binaries[InfBianryCommonItemObj] BinariesList = self.Binaries[InfBianryCommonItemObj]
BinariesList.append((InfBianryCommonItemObj, ItemComment)) BinariesList.append((InfBianryCommonItemObj, ItemComment))
self.Binaries[InfBianryCommonItemObj] = BinariesList self.Binaries[InfBianryCommonItemObj] = BinariesList
@ -673,7 +673,7 @@ class InfBinariesObject(InfSectionCommonDef):
# pass # pass
if InfBianryUiItemObj is not None: if InfBianryUiItemObj is not None:
if self.Binaries.has_key((InfBianryUiItemObj)): if (InfBianryUiItemObj) in self.Binaries:
BinariesList = self.Binaries[InfBianryUiItemObj] BinariesList = self.Binaries[InfBianryUiItemObj]
BinariesList.append((InfBianryUiItemObj, UiComment)) BinariesList.append((InfBianryUiItemObj, UiComment))
self.Binaries[InfBianryUiItemObj] = BinariesList self.Binaries[InfBianryUiItemObj] = BinariesList

View File

@ -957,7 +957,7 @@ class InfDefObject(InfSectionCommonDef):
SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip() SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip()
Name = "SPEC" Name = "SPEC"
Value = SpecValue + " = " + Value Value = SpecValue + " = " + Value
if self.Defines.has_key(ArchListString): if ArchListString in self.Defines:
DefineList = self.Defines[ArchListString] DefineList = self.Defines[ArchListString]
LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName() LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo() LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()

View File

@ -338,7 +338,7 @@ class InfGuidObject():
# #
pass pass
if self.Guids.has_key((InfGuidItemObj)): if (InfGuidItemObj) in self.Guids:
GuidList = self.Guids[InfGuidItemObj] GuidList = self.Guids[InfGuidItemObj]
GuidList.append(InfGuidItemObj) GuidList.append(InfGuidItemObj)
self.Guids[InfGuidItemObj] = GuidList self.Guids[InfGuidItemObj] = GuidList

View File

@ -238,7 +238,7 @@ class InfLibraryClassObject():
LibItemObj.SetVersion(LibItem[1]) LibItemObj.SetVersion(LibItem[1])
LibItemObj.SetSupArchList(__SupArchList) LibItemObj.SetSupArchList(__SupArchList)
if self.LibraryClasses.has_key((LibItemObj)): if (LibItemObj) in self.LibraryClasses:
LibraryList = self.LibraryClasses[LibItemObj] LibraryList = self.LibraryClasses[LibItemObj]
LibraryList.append(LibItemObj) LibraryList.append(LibItemObj)
self.LibraryClasses[LibItemObj] = LibraryList self.LibraryClasses[LibItemObj] = LibraryList

View File

@ -114,7 +114,7 @@ class InfSpecialCommentObject(InfSectionCommonDef):
Type == DT.TYPE_EVENT_SECTION or \ Type == DT.TYPE_EVENT_SECTION or \
Type == DT.TYPE_BOOTMODE_SECTION: Type == DT.TYPE_BOOTMODE_SECTION:
for Item in SepcialSectionList: for Item in SepcialSectionList:
if self.SpecialComments.has_key(Type): if Type in self.SpecialComments:
ObjList = self.SpecialComments[Type] ObjList = self.SpecialComments[Type]
ObjList.append(Item) ObjList.append(Item)
self.SpecialComments[Type] = ObjList self.SpecialComments[Type] = ObjList

View File

@ -171,7 +171,7 @@ class InfPackageObject():
# #
pass pass
if self.Packages.has_key((PackageItemObj)): if (PackageItemObj) in self.Packages:
PackageList = self.Packages[PackageItemObj] PackageList = self.Packages[PackageItemObj]
PackageList.append(PackageItemObj) PackageList.append(PackageItemObj)
self.Packages[PackageItemObj] = PackageList self.Packages[PackageItemObj] = PackageList

View File

@ -411,7 +411,7 @@ class InfPcdObject():
else: else:
PcdItemObj.SetSupportArchList(SupArchList) PcdItemObj.SetSupportArchList(SupArchList)
if self.Pcds.has_key((PcdTypeItem, PcdItemObj)): if (PcdTypeItem, PcdItemObj) in self.Pcds:
PcdsList = self.Pcds[PcdTypeItem, PcdItemObj] PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]
PcdsList.append(PcdItemObj) PcdsList.append(PcdItemObj)
self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList
@ -456,7 +456,7 @@ class InfPcdObject():
PackageInfo) PackageInfo)
PcdTypeItem = KeysList[0][0] PcdTypeItem = KeysList[0][0]
if self.Pcds.has_key((PcdTypeItem, PcdItemObj)): if (PcdTypeItem, PcdItemObj) in self.Pcds:
PcdsList = self.Pcds[PcdTypeItem, PcdItemObj] PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]
PcdsList.append(PcdItemObj) PcdsList.append(PcdItemObj)
self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList

View File

@ -327,7 +327,7 @@ class InfPpiObject():
# #
pass pass
if self.Ppis.has_key((InfPpiItemObj)): if (InfPpiItemObj) in self.Ppis:
PpiList = self.Ppis[InfPpiItemObj] PpiList = self.Ppis[InfPpiItemObj]
PpiList.append(InfPpiItemObj) PpiList.append(InfPpiItemObj)
self.Ppis[InfPpiItemObj] = PpiList self.Ppis[InfPpiItemObj] = PpiList

View File

@ -296,7 +296,7 @@ class InfProtocolObject():
# #
pass pass
if self.Protocols.has_key((InfProtocolItemObj)): if (InfProtocolItemObj) in self.Protocols:
ProcotolList = self.Protocols[InfProtocolItemObj] ProcotolList = self.Protocols[InfProtocolItemObj]
ProcotolList.append(InfProtocolItemObj) ProcotolList.append(InfProtocolItemObj)
self.Protocols[InfProtocolItemObj] = ProcotolList self.Protocols[InfProtocolItemObj] = ProcotolList

View File

@ -224,7 +224,7 @@ class InfSourcesObject(InfSectionCommonDef):
ItemObj.SetSupArchList(__SupArchList) ItemObj.SetSupArchList(__SupArchList)
if self.Sources.has_key((ItemObj)): if (ItemObj) in self.Sources:
SourceContent = self.Sources[ItemObj] SourceContent = self.Sources[ItemObj]
SourceContent.append(ItemObj) SourceContent.append(ItemObj)
self.Sources[ItemObj] = SourceContent self.Sources[ItemObj] = SourceContent
@ -237,4 +237,3 @@ class InfSourcesObject(InfSectionCommonDef):
def GetSources(self): def GetSources(self):
return self.Sources return self.Sources

View File

@ -103,7 +103,7 @@ class InfUserExtensionObject():
# Line=LineNo, # Line=LineNo,
# ExtraData=None) # ExtraData=None)
if self.UserExtension.has_key(IdContentItem): if IdContentItem in self.UserExtension:
# #
# Each UserExtensions section header must have a unique set # Each UserExtensions section header must have a unique set
# of UserId, IdString and Arch values. # of UserId, IdString and Arch values.

View File

@ -77,7 +77,7 @@ TmpTableDict = {}
# Otherwise, False is returned # Otherwise, False is returned
# #
def IsToolInPath(tool): def IsToolInPath(tool):
if os.environ.has_key('PATHEXT'): if 'PATHEXT' in os.environ:
extns = os.environ['PATHEXT'].split(os.path.pathsep) extns = os.environ['PATHEXT'].split(os.path.pathsep)
else: else:
extns = ('',) extns = ('',)