BaseTools: Remove the deprecated hash_key()
authorGary Lin <glin@suse.com>
Mon, 25 Jun 2018 10:31:29 +0000 (18:31 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 27 Jun 2018 08:33:23 +0000 (16:33 +0800)
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>
18 files changed:
BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/basemodel/ini.py
BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/baseobject.py
BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/inf.py
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/Common/VpdInfoFile.py
BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools/Source/Python/UPT/Object/Parser/InfBinaryObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfDefineObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfGuidObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfLibraryClassesObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfMisc.py
BaseTools/Source/Python/UPT/Object/Parser/InfPackagesObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfPpiObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfProtocolObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfSoucesObject.py
BaseTools/Source/Python/UPT/Object/Parser/InfUserExtensionObject.py
BaseTools/Source/Python/build/build.py

index ea83327..ccfef6b 100644 (file)
@@ -140,7 +140,7 @@ class BaseINIFile(object):
                     sObj = self.GetSectionInstance(self, name, (len(sname_arr) > 1))\r
                     sObj._start = index\r
                     sObjs.append(sObj)\r
-                    if not self._sections.has_key(name.lower()):\r
+                    if name.lower() not in self._sections:\r
                         self._sections[name.lower()] = [sObj]\r
                     else:\r
                         self._sections[name.lower()].append(sObj)\r
index 7c120d8..b49c87c 100644 (file)
@@ -26,7 +26,7 @@ class SurfaceObject(object):
 \r
         """\r
         obj = object.__new__(cls, *args, **kwargs)\r
-        if not cls._objs.has_key("None"):\r
+        if "None" not in cls._objs:\r
             cls._objs["None"] = []\r
         cls._objs["None"].append(obj)\r
 \r
@@ -47,7 +47,7 @@ class SurfaceObject(object):
         self.GetFileObj().Destroy(self)\r
         del self._fileObj\r
         # dereference self from _objs arrary\r
-        assert self._objs.has_key(key), "when destory, object is not in obj list"\r
+        assert key in self._objs, "when destory, object is not in obj list"\r
         assert self in self._objs[key], "when destory, object is not in obj list"\r
         self._objs[key].remove(self)\r
         if len(self._objs[key]) == 0:\r
@@ -95,7 +95,7 @@ class SurfaceObject(object):
         if self not in cls._objs["None"]:\r
             ErrorMsg("Sufrace object does not be create into None list")\r
         cls._objs["None"].remove(self)\r
-        if not cls._objs.has_key(relativePath):\r
+        if relativePath not in cls._objs:\r
             cls._objs[relativePath] = []\r
         cls._objs[relativePath].append(self)\r
 \r
index 32b2685..793e95e 100644 (file)
@@ -61,7 +61,7 @@ class INFFile(ini.BaseINIFile):
         classname = self.GetProduceLibraryClass()\r
         if classname is not None:\r
             libobjdict = INFFile._libobjs\r
-            if libobjdict.has_key(classname):\r
+            if classname in libobjdict:\r
                 if self not in libobjdict[classname]:\r
                     libobjdict[classname].append(self)\r
             else:\r
@@ -169,7 +169,7 @@ class INFLibraryClassObject(INFSectionObject):
     def Parse(self):\r
         self._classname = self.GetLineByOffset(self._start).split('#')[0].strip()\r
         objdict = INFLibraryClassObject._objs\r
-        if objdict.has_key(self._classname):\r
+        if self._classname in objdict:\r
             objdict[self._classname].append(self)\r
         else:\r
             objdict[self._classname] = [self]\r
@@ -241,7 +241,7 @@ class INFSourceObject(INFSectionObject):
 \r
         self.mFilename = os.path.basename(self.GetSourceFullPath())\r
         objdict = INFSourceObject._objs\r
-        if not objdict.has_key(self.mFilename):\r
+        if self.mFilename not in objdict:\r
             objdict[self.mFilename] = [self]\r
         else:\r
             objdict[self.mFilename].append(self)\r
@@ -303,7 +303,7 @@ class INFPcdObject(INFSectionObject):
             self.mDefaultValue = arr[1].strip()\r
 \r
         objdict = INFPcdObject._objs\r
-        if objdict.has_key(self.GetName()):\r
+        if self.GetName() in objdict:\r
             if self not in objdict[self.GetName()]:\r
                 objdict[self.GetName()].append(self)\r
         else:\r
index d748590..dbcf662 100644 (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.\r
             BPDGToolName = None\r
             for ToolDef in self.ToolDefinition.values():\r
-                if ToolDef.has_key(TAB_GUID) and ToolDef[TAB_GUID] == self.Platform.VpdToolGuid:\r
-                    if not ToolDef.has_key("PATH"):\r
+                if TAB_GUID in ToolDef and ToolDef[TAB_GUID] == self.Platform.VpdToolGuid:\r
+                    if "PATH" not in ToolDef:\r
                         EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
                     BPDGToolName = ToolDef["PATH"]\r
                     break\r
index 435b23f..ddabe9f 100644 (file)
@@ -211,7 +211,7 @@ class VpdInfoFile:
     #\r
     #  @param vpd    A given VPD PCD \r
     def GetOffset(self, vpd):\r
-        if not self._VpdArray.has_key(vpd):\r
+        if vpd not in self._VpdArray:\r
             return None\r
         \r
         if len(self._VpdArray[vpd]) == 0:\r
index bfd422b..b97b319 100644 (file)
@@ -438,14 +438,14 @@ def GenLibraryClasses(ModuleObject):
                 Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version\r
 \r
                 if len(BinaryFile.SupArchList) == 0:\r
-                    if LibraryClassDict.has_key('COMMON') and Statement not in LibraryClassDict['COMMON']:\r
+                    if 'COMMON' in LibraryClassDict and Statement not in LibraryClassDict['COMMON']:\r
                         LibraryClassDict['COMMON'].append(Statement)\r
                     else:\r
                         LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']\r
                         LibraryClassDict['COMMON'].append(Statement)\r
                 else:\r
                     for Arch in BinaryFile.SupArchList:\r
-                        if LibraryClassDict.has_key(Arch):\r
+                        if Arch in LibraryClassDict:\r
                             if Statement not in LibraryClassDict[Arch]:\r
                                 LibraryClassDict[Arch].append(Statement)\r
                             else:\r
@@ -917,14 +917,14 @@ def GenAsBuiltPacthPcdSections(ModuleObject):
             if FileNameObjList:\r
                 ArchList = FileNameObjList[0].GetSupArchList()\r
             if len(ArchList) == 0:\r
-                if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON):\r
+                if DT.TAB_ARCH_COMMON in PatchPcdDict:\r
                     if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:\r
                         PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)\r
                 else:\r
                     PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]\r
             else:\r
                 for Arch in ArchList:\r
-                    if PatchPcdDict.has_key(Arch):\r
+                    if Arch in PatchPcdDict:\r
                         if Statement not in PatchPcdDict[Arch]:\r
                             PatchPcdDict[Arch].append(Statement)\r
                     else:\r
@@ -967,13 +967,13 @@ def GenAsBuiltPcdExSections(ModuleObject):
                 ArchList = FileNameObjList[0].GetSupArchList()\r
 \r
             if len(ArchList) == 0:\r
-                if PcdExDict.has_key('COMMON'):\r
+                if 'COMMON' in PcdExDict:\r
                     PcdExDict['COMMON'].append(Statement)\r
                 else:\r
                     PcdExDict['COMMON'] = [Statement]\r
             else:\r
                 for Arch in ArchList:\r
-                    if PcdExDict.has_key(Arch):\r
+                    if Arch in PcdExDict:\r
                         if Statement not in PcdExDict[Arch]:\r
                             PcdExDict[Arch].append(Statement)\r
                     else:\r
@@ -1071,7 +1071,7 @@ def GenBuildOptions(ModuleObject):
             for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:\r
                 Statement = '#' + BuilOptionItem.AsBuiltOptionFlags\r
                 if len(BinaryFile.SupArchList) == 0:\r
-                    if BuildOptionDict.has_key('COMMON'):\r
+                    if 'COMMON' in BuildOptionDict:\r
                         if Statement not in BuildOptionDict['COMMON']:\r
                             BuildOptionDict['COMMON'].append(Statement)\r
                     else:\r
@@ -1079,7 +1079,7 @@ def GenBuildOptions(ModuleObject):
                         BuildOptionDict['COMMON'].append(Statement)\r
                 else:\r
                     for Arch in BinaryFile.SupArchList:\r
-                        if BuildOptionDict.has_key(Arch):\r
+                        if Arch in BuildOptionDict:\r
                             if Statement not in BuildOptionDict[Arch]:\r
                                 BuildOptionDict[Arch].append(Statement)\r
                         else:\r
index 33b142d..cc2fc49 100644 (file)
@@ -272,7 +272,7 @@ class InfBinariesObject(InfSectionCommonDef):
                                 pass\r
 \r
             if InfBianryVerItemObj is not None:\r
-                if self.Binaries.has_key((InfBianryVerItemObj)):\r
+                if (InfBianryVerItemObj) in self.Binaries:\r
                     BinariesList = self.Binaries[InfBianryVerItemObj]\r
                     BinariesList.append((InfBianryVerItemObj, VerComment))\r
                     self.Binaries[InfBianryVerItemObj] = BinariesList\r
@@ -522,7 +522,7 @@ class InfBinariesObject(InfSectionCommonDef):
 #                                pass\r
 \r
             if InfBianryCommonItemObj is not None:\r
-                if self.Binaries.has_key((InfBianryCommonItemObj)):\r
+                if (InfBianryCommonItemObj) in self.Binaries:\r
                     BinariesList = self.Binaries[InfBianryCommonItemObj]\r
                     BinariesList.append((InfBianryCommonItemObj, ItemComment))\r
                     self.Binaries[InfBianryCommonItemObj] = BinariesList\r
@@ -673,7 +673,7 @@ class InfBinariesObject(InfSectionCommonDef):
 #                                        pass\r
 \r
                     if InfBianryUiItemObj is not None:\r
-                        if self.Binaries.has_key((InfBianryUiItemObj)):\r
+                        if (InfBianryUiItemObj) in self.Binaries:\r
                             BinariesList = self.Binaries[InfBianryUiItemObj]\r
                             BinariesList.append((InfBianryUiItemObj, UiComment))\r
                             self.Binaries[InfBianryUiItemObj] = BinariesList\r
index 3995546..9d27a92 100644 (file)
@@ -957,7 +957,7 @@ class InfDefObject(InfSectionCommonDef):
                     SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip()\r
                     Name = "SPEC"\r
                     Value = SpecValue + " = " + Value\r
-                if self.Defines.has_key(ArchListString):\r
+                if ArchListString in self.Defines:\r
                     DefineList = self.Defines[ArchListString]                 \r
                     LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()\r
                     LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()\r
index fb8d1f5..4dfe75a 100644 (file)
@@ -338,7 +338,7 @@ class InfGuidObject():
                                 #\r
                                 pass\r
                                                 \r
-            if self.Guids.has_key((InfGuidItemObj)):           \r
+            if (InfGuidItemObj) in self.Guids:\r
                 GuidList = self.Guids[InfGuidItemObj]                 \r
                 GuidList.append(InfGuidItemObj)\r
                 self.Guids[InfGuidItemObj] = GuidList\r
@@ -350,4 +350,4 @@ class InfGuidObject():
         return True\r
     \r
     def GetGuid(self):\r
-        return self.Guids
\ No newline at end of file
+        return self.Guids\r
index e588c6b..5de1832 100644 (file)
@@ -238,7 +238,7 @@ class InfLibraryClassObject():
                 LibItemObj.SetVersion(LibItem[1])\r
                 LibItemObj.SetSupArchList(__SupArchList)\r
 \r
-            if self.LibraryClasses.has_key((LibItemObj)):\r
+            if (LibItemObj) in self.LibraryClasses:\r
                 LibraryList = self.LibraryClasses[LibItemObj]\r
                 LibraryList.append(LibItemObj)\r
                 self.LibraryClasses[LibItemObj] = LibraryList\r
index 37f8cb2..4ed739d 100644 (file)
@@ -114,7 +114,7 @@ class InfSpecialCommentObject(InfSectionCommonDef):
            Type == DT.TYPE_EVENT_SECTION or \\r
            Type == DT.TYPE_BOOTMODE_SECTION:\r
             for Item in SepcialSectionList:\r
-                if self.SpecialComments.has_key(Type):           \r
+                if Type in self.SpecialComments:\r
                     ObjList = self.SpecialComments[Type]\r
                     ObjList.append(Item)\r
                     self.SpecialComments[Type] = ObjList\r
@@ -145,4 +145,4 @@ def ErrorInInf(Message=None, ErrorCode=None, LineInfo=None, RaiseError=True):
                  File=LineInfo[0], \r
                  Line=LineInfo[1],\r
                  ExtraData=LineInfo[2], \r
-                 RaiseError=RaiseError)
\ No newline at end of file
+                 RaiseError=RaiseError)\r
index 01c854a..bfac2b6 100644 (file)
@@ -171,7 +171,7 @@ class InfPackageObject():
                                 #\r
                                 pass\r
                                             \r
-            if self.Packages.has_key((PackageItemObj)):   \r
+            if (PackageItemObj) in self.Packages:\r
                 PackageList = self.Packages[PackageItemObj]\r
                 PackageList.append(PackageItemObj)\r
                 self.Packages[PackageItemObj] = PackageList\r
@@ -184,4 +184,4 @@ class InfPackageObject():
     \r
     def GetPackages(self, Arch = None):\r
         if Arch is None:\r
-            return self.Packages
\ No newline at end of file
+            return self.Packages\r
index 62c1e84..3b9dfae 100644 (file)
@@ -411,7 +411,7 @@ class InfPcdObject():
                 else:\r
                     PcdItemObj.SetSupportArchList(SupArchList)\r
 \r
-                if self.Pcds.has_key((PcdTypeItem, PcdItemObj)):\r
+                if (PcdTypeItem, PcdItemObj) in self.Pcds:\r
                     PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]\r
                     PcdsList.append(PcdItemObj)\r
                     self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList\r
@@ -456,7 +456,7 @@ class InfPcdObject():
                                                       PackageInfo)\r
 \r
             PcdTypeItem = KeysList[0][0]\r
-            if self.Pcds.has_key((PcdTypeItem, PcdItemObj)):\r
+            if (PcdTypeItem, PcdItemObj) in self.Pcds:\r
                 PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]\r
                 PcdsList.append(PcdItemObj)\r
                 self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList\r
index eb6b692..0f865c5 100644 (file)
@@ -327,7 +327,7 @@ class InfPpiObject():
                                 # \r
                                 pass\r
             \r
-            if self.Ppis.has_key((InfPpiItemObj)):           \r
+            if (InfPpiItemObj) in self.Ppis:\r
                 PpiList = self.Ppis[InfPpiItemObj]\r
                 PpiList.append(InfPpiItemObj)\r
                 self.Ppis[InfPpiItemObj] = PpiList\r
@@ -340,4 +340,4 @@ class InfPpiObject():
         \r
     \r
     def GetPpi(self):\r
-        return self.Ppis
\ No newline at end of file
+        return self.Ppis\r
index eb03095..6cadeb5 100644 (file)
@@ -296,7 +296,7 @@ class InfProtocolObject():
                                 #\r
                                 pass      \r
                                       \r
-            if self.Protocols.has_key((InfProtocolItemObj)):           \r
+            if (InfProtocolItemObj) in self.Protocols:\r
                 ProcotolList = self.Protocols[InfProtocolItemObj]\r
                 ProcotolList.append(InfProtocolItemObj)\r
                 self.Protocols[InfProtocolItemObj] = ProcotolList\r
index 2302dd5..285e89a 100644 (file)
@@ -224,7 +224,7 @@ class InfSourcesObject(InfSectionCommonDef):
                 \r
             ItemObj.SetSupArchList(__SupArchList) \r
                                                                                                       \r
-            if self.Sources.has_key((ItemObj)):           \r
+            if (ItemObj) in self.Sources:\r
                 SourceContent = self.Sources[ItemObj]\r
                 SourceContent.append(ItemObj)\r
                 self.Sources[ItemObj] = SourceContent\r
@@ -237,4 +237,3 @@ class InfSourcesObject(InfSectionCommonDef):
      \r
     def GetSources(self):\r
         return self.Sources\r
-    
\ No newline at end of file
index 27a1c6a..f9db294 100644 (file)
@@ -103,7 +103,7 @@ class InfUserExtensionObject():
 #                            Line=LineNo,\r
 #                            ExtraData=None)\r
             \r
-            if self.UserExtension.has_key(IdContentItem):           \r
+            if IdContentItem in self.UserExtension:\r
                 #\r
                 # Each UserExtensions section header must have a unique set \r
                 # of UserId, IdString and Arch values.\r
@@ -130,4 +130,4 @@ class InfUserExtensionObject():
         return True\r
         \r
     def GetUserExtension(self):\r
-        return self.UserExtension
\ No newline at end of file
+        return self.UserExtension\r
index 416aa73..344b006 100644 (file)
@@ -77,7 +77,7 @@ TmpTableDict = {}
 #   Otherwise, False is returned\r
 #\r
 def IsToolInPath(tool):\r
-    if os.environ.has_key('PATHEXT'):\r
+    if 'PATHEXT' in os.environ:\r
         extns = os.environ['PATHEXT'].split(os.path.pathsep)\r
     else:\r
         extns = ('',)\r