]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Replace StringIO.StringIO with io.BytesIO
authorGary Lin <glin@suse.com>
Mon, 25 Jun 2018 10:31:36 +0000 (18:31 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 27 Jun 2018 08:33:28 +0000 (16:33 +0800)
Replace StringIO.StringIO with io.BytesIO to be compatible with python3.
This commit also removes "import StringIO" from those python scripts
that don't really use it.

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>
23 files changed:
BaseTools/Scripts/ConvertUni.py
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/AutoGen/GenDepex.py
BaseTools/Source/Python/AutoGen/GenPcdDb.py
BaseTools/Source/Python/AutoGen/IdfClassObject.py
BaseTools/Source/Python/AutoGen/StrGather.py
BaseTools/Source/Python/AutoGen/UniClassObject.py
BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
BaseTools/Source/Python/BPDG/GenVpd.py
BaseTools/Source/Python/GenFds/AprioriSection.py
BaseTools/Source/Python/GenFds/Capsule.py
BaseTools/Source/Python/GenFds/CapsuleData.py
BaseTools/Source/Python/GenFds/Fd.py
BaseTools/Source/Python/GenFds/FfsFileStatement.py
BaseTools/Source/Python/GenFds/FfsInfStatement.py
BaseTools/Source/Python/GenFds/Fv.py
BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools/Source/Python/GenFds/GenFds.py
BaseTools/Source/Python/GenFds/OptionRom.py
BaseTools/Source/Python/GenFds/Region.py
BaseTools/Source/Python/Trim/Trim.py
BaseTools/Source/Python/build/BuildReport.py
BaseTools/Source/Python/build/build.py

index 2af55dfc670246d117190003367b4f48e8fcb73c..67bbe41b1f18f5b81e875c26432653ffae79363b 100755 (executable)
@@ -23,11 +23,6 @@ import codecs
 import os\r
 import sys\r
 \r
 import os\r
 import sys\r
 \r
-try:\r
-    from io import StringIO\r
-except ImportError:\r
-    from StringIO import StringIO\r
-\r
 class ConvertOneArg:\r
     """Converts utf-16 to utf-8 for one command line argument.\r
 \r
 class ConvertOneArg:\r
     """Converts utf-16 to utf-8 for one command line argument.\r
 \r
index a7e1edb8435c371531e7a80b604a4cd16eb76bee..2022454004330244f4b63763980dff637203ad1e 100644 (file)
@@ -25,7 +25,7 @@ import uuid
 import GenC\r
 import GenMake\r
 import GenDepex\r
 import GenC\r
 import GenMake\r
 import GenDepex\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 \r
 from StrGather import *\r
 from BuildEngine import BuildRule\r
 \r
 from StrGather import *\r
 from BuildEngine import BuildRule\r
@@ -3437,8 +3437,8 @@ class ModuleAutoGen(AutoGen):
     def _GetAutoGenFileList(self):\r
         UniStringAutoGenC = True\r
         IdfStringAutoGenC = True\r
     def _GetAutoGenFileList(self):\r
         UniStringAutoGenC = True\r
         IdfStringAutoGenC = True\r
-        UniStringBinBuffer = StringIO()\r
-        IdfGenBinBuffer = StringIO()\r
+        UniStringBinBuffer = BytesIO()\r
+        IdfGenBinBuffer = BytesIO()\r
         if self.BuildType == 'UEFI_HII':\r
             UniStringAutoGenC = False\r
             IdfStringAutoGenC = False\r
         if self.BuildType == 'UEFI_HII':\r
             UniStringAutoGenC = False\r
             IdfStringAutoGenC = False\r
@@ -3713,8 +3713,8 @@ class ModuleAutoGen(AutoGen):
         except:\r
             EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName, None)\r
 \r
         except:\r
             EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName, None)\r
 \r
-        # Use a instance of StringIO to cache data\r
-        fStringIO = StringIO('')  \r
+        # Use a instance of BytesIO to cache data\r
+        fStringIO = BytesIO('')\r
 \r
         for Item in VfrUniOffsetList:\r
             if (Item[0].find("Strings") != -1):\r
 \r
         for Item in VfrUniOffsetList:\r
             if (Item[0].find("Strings") != -1):\r
index e89191a72b9fcc2c408bc252ddae16c1a3e78a19..d3b1eae181c234912f641edf06979c841128bc2b 100644 (file)
@@ -17,7 +17,7 @@ import Common.LongFilePathOs as os
 import re\r
 import traceback\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 import re\r
 import traceback\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from struct import pack\r
 from Common.BuildToolError import *\r
 from Common.Misc import SaveFileOnChange\r
 from struct import pack\r
 from Common.BuildToolError import *\r
 from Common.Misc import SaveFileOnChange\r
@@ -345,7 +345,7 @@ class DependencyExpression:
     #   @retval False   If file exists and is not changed.\r
     #\r
     def Generate(self, File=None):\r
     #   @retval False   If file exists and is not changed.\r
     #\r
     def Generate(self, File=None):\r
-        Buffer = StringIO()\r
+        Buffer = BytesIO()\r
         if len(self.PostfixNotation) == 0:\r
             return False\r
 \r
         if len(self.PostfixNotation) == 0:\r
             return False\r
 \r
index 07ba29a158be180711bd5d260474ecfc71ee7567..9fcd7fcc97a97e44d8e61db7d4e75b05553013e3 100644 (file)
@@ -10,7 +10,7 @@
 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #\r
 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from Common.Misc import *\r
 from Common.StringUtils import StringToArray\r
 from struct import pack\r
 from Common.Misc import *\r
 from Common.StringUtils import StringToArray\r
 from struct import pack\r
@@ -888,7 +888,7 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):
         DbFileName = os.path.join(Info.PlatformInfo.BuildDir, TAB_FV_DIRECTORY, Phase + "PcdDataBase.raw")\r
     else:\r
         DbFileName = os.path.join(Info.OutputDir, Phase + "PcdDataBase.raw")\r
         DbFileName = os.path.join(Info.PlatformInfo.BuildDir, TAB_FV_DIRECTORY, Phase + "PcdDataBase.raw")\r
     else:\r
         DbFileName = os.path.join(Info.OutputDir, Phase + "PcdDataBase.raw")\r
-    DbFile = StringIO()\r
+    DbFile = BytesIO()\r
     DbFile.write(PcdDbBuffer)\r
     Changed = SaveFileOnChange(DbFileName, DbFile.getvalue(), True)\r
 def CreatePcdDataBase(PcdDBData):\r
     DbFile.write(PcdDbBuffer)\r
     Changed = SaveFileOnChange(DbFileName, DbFile.getvalue(), True)\r
 def CreatePcdDataBase(PcdDBData):\r
index e5b933c2036fc07fd9e4e6f3687b63095ca7ecb2..b656bd83e3ba27b2dd959d81a49e183ac65e8c6b 100644 (file)
@@ -14,7 +14,6 @@
 # Import Modules\r
 #\r
 import Common.EdkLogger as EdkLogger\r
 # Import Modules\r
 #\r
 import Common.EdkLogger as EdkLogger\r
-import StringIO\r
 from Common.BuildToolError import *\r
 from Common.StringUtils import GetLineNo\r
 from Common.Misc import PathClass\r
 from Common.BuildToolError import *\r
 from Common.StringUtils import GetLineNo\r
 from Common.Misc import PathClass\r
index 9f70d4e5b717195a7baa0a3dd321bf11c1baa737..0e74f3bfb7cb767bc8d22293f02ac888cd04764e 100644 (file)
@@ -18,7 +18,7 @@ import re
 import Common.EdkLogger as EdkLogger\r
 from Common.BuildToolError import *\r
 from UniClassObject import *\r
 import Common.EdkLogger as EdkLogger\r
 from Common.BuildToolError import *\r
 from UniClassObject import *\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from struct import pack, unpack\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 from struct import pack, unpack\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
@@ -341,7 +341,7 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer,
         if Language not in UniLanguageListFiltered:\r
             continue\r
         \r
         if Language not in UniLanguageListFiltered:\r
             continue\r
         \r
-        StringBuffer = StringIO()\r
+        StringBuffer = BytesIO()\r
         StrStringValue = ''\r
         ArrayLength = 0\r
         NumberOfUseOtherLangDef = 0\r
         StrStringValue = ''\r
         ArrayLength = 0\r
         NumberOfUseOtherLangDef = 0\r
index 3a931c6f27663a600baa6ca9140f7548c84cc9a3..88810f1ccc0d9b2fa3e2f4d7d0d6d520526765eb 100644 (file)
@@ -20,7 +20,7 @@ from __future__ import print_function
 import Common.LongFilePathOs as os, codecs, re\r
 import distutils.util\r
 import Common.EdkLogger as EdkLogger\r
 import Common.LongFilePathOs as os, codecs, re\r
 import distutils.util\r
 import Common.EdkLogger as EdkLogger\r
-import StringIO\r
+from io import BytesIO\r
 from Common.BuildToolError import *\r
 from Common.StringUtils import GetLineNo\r
 from Common.Misc import PathClass\r
 from Common.BuildToolError import *\r
 from Common.StringUtils import GetLineNo\r
 from Common.Misc import PathClass\r
@@ -320,7 +320,7 @@ class UniFileClassObject(object):
 \r
         UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding)\r
 \r
 \r
         UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding)\r
 \r
-        UniFile = StringIO.StringIO(FileIn)\r
+        UniFile = BytesIO(FileIn)\r
         Info = codecs.lookup(Encoding)\r
         (Reader, Writer) = (Info.streamreader, Info.streamwriter)\r
         return codecs.StreamReaderWriter(UniFile, Reader, Writer)\r
         Info = codecs.lookup(Encoding)\r
         (Reader, Writer) = (Info.streamreader, Info.streamwriter)\r
         return codecs.StreamReaderWriter(UniFile, Reader, Writer)\r
@@ -335,7 +335,7 @@ class UniFileClassObject(object):
             FileDecoded = codecs.decode(FileIn, Encoding)\r
             Ucs2Info.encode(FileDecoded)\r
         except:\r
             FileDecoded = codecs.decode(FileIn, Encoding)\r
             Ucs2Info.encode(FileDecoded)\r
         except:\r
-            UniFile = StringIO.StringIO(FileIn)\r
+            UniFile = BytesIO(FileIn)\r
             Info = codecs.lookup(Encoding)\r
             (Reader, Writer) = (Info.streamreader, Info.streamwriter)\r
             File = codecs.StreamReaderWriter(UniFile, Reader, Writer)\r
             Info = codecs.lookup(Encoding)\r
             (Reader, Writer) = (Info.streamreader, Info.streamwriter)\r
             File = codecs.StreamReaderWriter(UniFile, Reader, Writer)\r
index 64d4965e96620de06b99ed31509cc44fb80309c0..49fbdf3246a584fd895ce26f335230e71aad786b 100644 (file)
@@ -17,7 +17,7 @@
 import os\r
 from Common.RangeExpression import RangeExpression\r
 from Common.Misc import *\r
 import os\r
 from Common.RangeExpression import RangeExpression\r
 from Common.Misc import *\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from struct import pack\r
 from Common.DataType import *\r
 \r
 from struct import pack\r
 from Common.DataType import *\r
 \r
@@ -162,7 +162,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
                             Buffer += b\r
                             realLength += 1\r
         \r
                             Buffer += b\r
                             realLength += 1\r
         \r
-        DbFile = StringIO()\r
+        DbFile = BytesIO()\r
         if Phase == 'DXE' and os.path.exists(BinFilePath):\r
             BinFile = open(BinFilePath, "rb")\r
             BinBuffer = BinFile.read()\r
         if Phase == 'DXE' and os.path.exists(BinFilePath):\r
             BinFile = open(BinFilePath, "rb")\r
             BinBuffer = BinFile.read()\r
index 807d0fa8d86ff780658fbb48f3dd4b129f3f3678..3bae803467a882d3fe6a9890425b44644960b847 100644 (file)
@@ -14,7 +14,7 @@
 #\r
 \r
 import Common.LongFilePathOs as os\r
 #\r
 \r
 import Common.LongFilePathOs as os\r
-import StringIO\r
+from io import BytesIO\r
 import StringTable as st\r
 import array\r
 import re\r
 import StringTable as st\r
 import array\r
 import re\r
@@ -673,8 +673,8 @@ class GenVPD :
             # Open failed\r
             EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" % self.MapFileName, None)\r
 \r
             # Open failed\r
             EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" % self.MapFileName, None)\r
 \r
-        # Use a instance of StringIO to cache data\r
-        fStringIO = StringIO.StringIO('')\r
+        # Use a instance of BytesIO to cache data\r
+        fStringIO = BytesIO('')\r
 \r
         # Write the header of map file.\r
         try :\r
 \r
         # Write the header of map file.\r
         try :\r
index 3d28c7d778cbd08b8cd1d06b29ec11ea5548838b..b3e7b5fc64a39c1f7690b49ac52ce645c214dfd3 100644 (file)
@@ -17,7 +17,7 @@
 #\r
 from struct import *\r
 import Common.LongFilePathOs as os\r
 #\r
 from struct import *\r
 import Common.LongFilePathOs as os\r
-import StringIO\r
+from io import BytesIO\r
 import FfsFileStatement\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from CommonDataClass.FdfClass import AprioriSectionClassObject\r
 import FfsFileStatement\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from CommonDataClass.FdfClass import AprioriSectionClassObject\r
@@ -51,7 +51,7 @@ class AprioriSection (AprioriSectionClassObject):
     def GenFfs (self, FvName, Dict = {}, IsMakefile = False):\r
         DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881"\r
         PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6"\r
     def GenFfs (self, FvName, Dict = {}, IsMakefile = False):\r
         DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881"\r
         PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6"\r
-        Buffer = StringIO.StringIO('')\r
+        Buffer = BytesIO('')\r
         AprioriFileGuid = DXE_GUID\r
         if self.AprioriType == "PEI":\r
             AprioriFileGuid = PEI_GUID\r
         AprioriFileGuid = DXE_GUID\r
         if self.AprioriType == "PEI":\r
             AprioriFileGuid = PEI_GUID\r
index fbd48f3c6d7663bb37633f8a923190fc6274f05c..b02661d99855e5be0595a1e68156e94cd6780c78 100644 (file)
@@ -19,7 +19,7 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable
 from CommonDataClass.FdfClass import CapsuleClassObject\r
 import Common.LongFilePathOs as os\r
 import subprocess\r
 from CommonDataClass.FdfClass import CapsuleClassObject\r
 import Common.LongFilePathOs as os\r
 import subprocess\r
-import StringIO\r
+from io import BytesIO\r
 from Common.Misc import SaveFileOnChange\r
 from GenFds import GenFds\r
 from Common.Misc import PackRegistryFormatGuid\r
 from Common.Misc import SaveFileOnChange\r
 from GenFds import GenFds\r
 from Common.Misc import PackRegistryFormatGuid\r
@@ -66,7 +66,7 @@ class Capsule (CapsuleClassObject) :
         #     UINT32            CapsuleImageSize;\r
         # } EFI_CAPSULE_HEADER;\r
         #\r
         #     UINT32            CapsuleImageSize;\r
         # } EFI_CAPSULE_HEADER;\r
         #\r
-        Header = StringIO.StringIO()\r
+        Header = BytesIO()\r
         #\r
         # Use FMP capsule GUID: 6DCBD5ED-E82D-4C44-BDA1-7194199AD92A\r
         #\r
         #\r
         # Use FMP capsule GUID: 6DCBD5ED-E82D-4C44-BDA1-7194199AD92A\r
         #\r
@@ -97,7 +97,7 @@ class Capsule (CapsuleClassObject) :
         #     // UINT64 ItemOffsetList[];\r
         # } EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER;\r
         #\r
         #     // UINT64 ItemOffsetList[];\r
         # } EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER;\r
         #\r
-        FwMgrHdr = StringIO.StringIO()\r
+        FwMgrHdr = BytesIO()\r
         if 'CAPSULE_HEADER_INIT_VERSION' in self.TokensDict:\r
             FwMgrHdr.write(pack('=I', int(self.TokensDict['CAPSULE_HEADER_INIT_VERSION'], 16)))\r
         else:\r
         if 'CAPSULE_HEADER_INIT_VERSION' in self.TokensDict:\r
             FwMgrHdr.write(pack('=I', int(self.TokensDict['CAPSULE_HEADER_INIT_VERSION'], 16)))\r
         else:\r
@@ -132,7 +132,7 @@ class Capsule (CapsuleClassObject) :
         #\r
 \r
         PreSize = FwMgrHdrSize\r
         #\r
 \r
         PreSize = FwMgrHdrSize\r
-        Content = StringIO.StringIO()\r
+        Content = BytesIO()\r
         for driver in self.CapsuleDataList:\r
             FileName = driver.GenCapsuleSubItem()\r
             FwMgrHdr.write(pack('=Q', PreSize))\r
         for driver in self.CapsuleDataList:\r
             FileName = driver.GenCapsuleSubItem()\r
             FwMgrHdr.write(pack('=Q', PreSize))\r
@@ -247,7 +247,7 @@ class Capsule (CapsuleClassObject) :
     def GenCapInf(self):\r
         self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
                                    self.UiCapsuleName +  "_Cap" + '.inf')\r
     def GenCapInf(self):\r
         self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
                                    self.UiCapsuleName +  "_Cap" + '.inf')\r
-        CapInfFile = StringIO.StringIO() #open (self.CapInfFileName , 'w+')\r
+        CapInfFile = BytesIO() #open (self.CapInfFileName , 'w+')\r
 \r
         CapInfFile.writelines("[options]" + T_CHAR_LF)\r
 \r
 \r
         CapInfFile.writelines("[options]" + T_CHAR_LF)\r
 \r
index 9dc55e5dbf7b1df4fc4df74df6a97ba56f2dfbb6..83b2731110bcead8a4ecb97c74b1336dba64adda 100644 (file)
@@ -17,7 +17,7 @@
 #\r
 import Ffs\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 #\r
 import Ffs\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
-import StringIO\r
+from io import BytesIO\r
 from struct import pack\r
 import os\r
 from Common.Misc import SaveFileOnChange\r
 from struct import pack\r
 import os\r
 from Common.Misc import SaveFileOnChange\r
@@ -82,7 +82,7 @@ class CapsuleFv (CapsuleData):
         if self.FvName.find('.fv') == -1:\r
             if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
                 FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[self.FvName.upper()]\r
         if self.FvName.find('.fv') == -1:\r
             if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
                 FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[self.FvName.upper()]\r
-                FdBuffer = StringIO.StringIO('')\r
+                FdBuffer = BytesIO('')\r
                 FvObj.CapsuleName = self.CapsuleName\r
                 FvFile = FvObj.AddToBuffer(FdBuffer)\r
                 FvObj.CapsuleName = None\r
                 FvObj.CapsuleName = self.CapsuleName\r
                 FvFile = FvObj.AddToBuffer(FdBuffer)\r
                 FvObj.CapsuleName = None\r
index b2a14a1e1313a12701490dc7036fad1d11701391..3305a470edfa8f3527b5d781baecb33c58c357bb 100644 (file)
@@ -18,7 +18,7 @@
 import Region\r
 import Fv\r
 import Common.LongFilePathOs as os\r
 import Region\r
 import Fv\r
 import Common.LongFilePathOs as os\r
-import StringIO\r
+from io import BytesIO\r
 import sys\r
 from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import sys\r
 from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
@@ -75,7 +75,7 @@ class FD(FDClassObject):
                 HasCapsuleRegion = True\r
                 break\r
         if HasCapsuleRegion:\r
                 HasCapsuleRegion = True\r
                 break\r
         if HasCapsuleRegion:\r
-            TempFdBuffer = StringIO.StringIO('')\r
+            TempFdBuffer = BytesIO('')\r
             PreviousRegionStart = -1\r
             PreviousRegionSize = 1\r
 \r
             PreviousRegionStart = -1\r
             PreviousRegionSize = 1\r
 \r
@@ -104,7 +104,7 @@ class FD(FDClassObject):
                 GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r
                 RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
         \r
                 GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r
                 RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
         \r
-        FdBuffer = StringIO.StringIO('')\r
+        FdBuffer = BytesIO('')\r
         PreviousRegionStart = -1\r
         PreviousRegionSize = 1\r
         for RegionObj in self.RegionList :\r
         PreviousRegionStart = -1\r
         PreviousRegionSize = 1\r
         for RegionObj in self.RegionList :\r
index ba8e0465ef34721defca9355978dba5df7cc2691..f5de57d0ac8207798ba5bf745cbb7d087418c1eb 100644 (file)
@@ -18,7 +18,7 @@
 import Ffs\r
 import Rule\r
 import Common.LongFilePathOs as os\r
 import Ffs\r
 import Rule\r
 import Common.LongFilePathOs as os\r
-import StringIO\r
+from io import BytesIO\r
 import subprocess\r
 \r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import subprocess\r
 \r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
@@ -82,7 +82,7 @@ class FileStatement (FileStatementClassObject) :
         Dict.update(self.DefineVarDict)\r
         SectionAlignments = None\r
         if self.FvName is not None :\r
         Dict.update(self.DefineVarDict)\r
         SectionAlignments = None\r
         if self.FvName is not None :\r
-            Buffer = StringIO.StringIO('')\r
+            Buffer = BytesIO('')\r
             if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r
             if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
                 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r
index 9eb99d659bfd0b8b9d5328823b80fb97ff7da8d8..ef34dbf007548cdd98fd7c5bc22b944b4f23d6c8 100644 (file)
@@ -18,7 +18,7 @@
 #\r
 import Rule\r
 import Common.LongFilePathOs as os\r
 #\r
 import Rule\r
 import Common.LongFilePathOs as os\r
-import StringIO\r
+from io import BytesIO\r
 from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import Ffs\r
 from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 import Ffs\r
@@ -1088,7 +1088,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):\r
 \r
         # Use a instance of StringIO to cache data\r
     def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):\r
 \r
         # Use a instance of StringIO to cache data\r
-        fStringIO = StringIO.StringIO('')  \r
+        fStringIO = BytesIO('')\r
         \r
         for Item in VfrUniOffsetList:\r
             if (Item[0].find("Strings") != -1):\r
         \r
         for Item in VfrUniOffsetList:\r
             if (Item[0].find("Strings") != -1):\r
index fb82634ccd7e648915419188873f5ffd899b3c2e..d980020680f869e84aee691681c845e85b716fc3 100644 (file)
@@ -17,7 +17,7 @@
 #\r
 import Common.LongFilePathOs as os\r
 import subprocess\r
 #\r
 import Common.LongFilePathOs as os\r
 import subprocess\r
-import StringIO\r
+from io import BytesIO\r
 from struct import *\r
 \r
 import Ffs\r
 from struct import *\r
 \r
 import Ffs\r
@@ -265,7 +265,7 @@ class FV (FvClassObject):
         #\r
         self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
                                    self.UiFvName + '.inf')\r
         #\r
         self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
                                    self.UiFvName + '.inf')\r
-        self.FvInfFile = StringIO.StringIO()\r
+        self.FvInfFile = BytesIO()\r
 \r
         #\r
         # Add [Options]\r
 \r
         #\r
         # Add [Options]\r
@@ -407,7 +407,7 @@ class FV (FvClassObject):
             #\r
             if TotalSize > 0:\r
                 FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext')\r
             #\r
             if TotalSize > 0:\r
                 FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext')\r
-                FvExtHeaderFile = StringIO.StringIO()\r
+                FvExtHeaderFile = BytesIO()\r
                 FvExtHeaderFile.write(Buffer)\r
                 Changed = SaveFileOnChange(FvExtHeaderFileName, FvExtHeaderFile.getvalue(), True)\r
                 FvExtHeaderFile.close()\r
                 FvExtHeaderFile.write(Buffer)\r
                 Changed = SaveFileOnChange(FvExtHeaderFileName, FvExtHeaderFile.getvalue(), True)\r
                 FvExtHeaderFile.close()\r
index 77bf6a7006237c21f53fd3db20c123978e32de1e..b4f1f3340e99c9f61ff29d4a1602fb817f05e476 100644 (file)
@@ -16,7 +16,7 @@
 # Import Modules\r
 #\r
 import Section\r
 # Import Modules\r
 #\r
 import Section\r
-import StringIO\r
+from io import BytesIO\r
 from Ffs import Ffs\r
 import subprocess\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 from Ffs import Ffs\r
 import subprocess\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
@@ -98,7 +98,7 @@ class FvImageSection(FvImageSectionClassObject):
         # Generate Fv\r
         #\r
         if self.FvName is not None:\r
         # Generate Fv\r
         #\r
         if self.FvName is not None:\r
-            Buffer = StringIO.StringIO('')\r
+            Buffer = BytesIO('')\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
             if Fv is not None:\r
                 self.Fv = Fv\r
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
             if Fv is not None:\r
                 self.Fv = Fv\r
index 912e6c58f4020936c9790cb70573054990373e3e..acd19e5276269b27aec1517432d6b0f8000bd72e 100644 (file)
@@ -27,7 +27,7 @@ from Workspace.WorkspaceDatabase import WorkspaceDatabase
 from Workspace.BuildClassObject import PcdClassObject\r
 import RuleComplexFile\r
 from EfiSection import EfiSection\r
 from Workspace.BuildClassObject import PcdClassObject\r
 import RuleComplexFile\r
 from EfiSection import EfiSection\r
-import StringIO\r
+from io import BytesIO\r
 import Common.TargetTxtClassObject as TargetTxtClassObject\r
 import Common.ToolDefClassObject as ToolDefClassObject\r
 from Common.DataType import *\r
 import Common.TargetTxtClassObject as TargetTxtClassObject\r
 import Common.ToolDefClassObject as ToolDefClassObject\r
 from Common.DataType import *\r
@@ -542,13 +542,13 @@ class GenFds :
         if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
             FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[GenFds.OnlyGenerateThisFv.upper()]\r
             if FvObj is not None:\r
         if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
             FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[GenFds.OnlyGenerateThisFv.upper()]\r
             if FvObj is not None:\r
-                Buffer = StringIO.StringIO()\r
+                Buffer = BytesIO()\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
                 return\r
         elif GenFds.OnlyGenerateThisFv is None:\r
             for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
                 return\r
         elif GenFds.OnlyGenerateThisFv is None:\r
             for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():\r
-                Buffer = StringIO.StringIO('')\r
+                Buffer = BytesIO('')\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
         \r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
         \r
@@ -694,7 +694,7 @@ class GenFds :
 \r
     def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):\r
         GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")\r
 \r
     def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):\r
         GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")\r
-        GuidXRefFile = StringIO.StringIO('')\r
+        GuidXRefFile = BytesIO('')\r
         GuidDict = {}\r
         ModuleList = []\r
         FileGuidList = []\r
         GuidDict = {}\r
         ModuleList = []\r
         FileGuidList = []\r
index b058415299404c92cddc80dce0ed2bb7f96f7346..755eb01da7e15fc097dee86cfcb0be68ae09fe5b 100644 (file)
@@ -17,7 +17,6 @@
 #\r
 import Common.LongFilePathOs as os\r
 import subprocess\r
 #\r
 import Common.LongFilePathOs as os\r
 import subprocess\r
-import StringIO\r
 \r
 import OptRomInfStatement\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 \r
 import OptRomInfStatement\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
@@ -138,5 +137,3 @@ class OverrideAttribs:
         self.PciDeviceId = None\r
         self.PciRevision = None\r
         self.NeedCompress = None\r
         self.PciDeviceId = None\r
         self.PciRevision = None\r
         self.NeedCompress = None\r
-        \r
-        
\ No newline at end of file
index 9d632b6321e2daef8d546f04293d0393c36509ce..3b7e30ec85925b1478adf978e88131d92c9aa833 100644 (file)
@@ -17,7 +17,7 @@
 #\r
 from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
 #\r
 from struct import *\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
-import StringIO\r
+from io import BytesIO\r
 import string\r
 from CommonDataClass.FdfClass import RegionClassObject\r
 import Common.LongFilePathOs as os\r
 import string\r
 from CommonDataClass.FdfClass import RegionClassObject\r
 import Common.LongFilePathOs as os\r
@@ -127,7 +127,7 @@ class Region(RegionClassObject):
                         if self.FvAddress % FvAlignValue != 0:\r
                             EdkLogger.error("GenFds", GENFDS_ERROR,\r
                                             "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment))\r
                         if self.FvAddress % FvAlignValue != 0:\r
                             EdkLogger.error("GenFds", GENFDS_ERROR,\r
                                             "FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment))\r
-                        FvBuffer = StringIO.StringIO('')\r
+                        FvBuffer = BytesIO('')\r
                         FvBaseAddress = '0x%X' % self.FvAddress\r
                         BlockSize = None\r
                         BlockNum = None\r
                         FvBaseAddress = '0x%X' % self.FvAddress\r
                         BlockSize = None\r
                         BlockNum = None\r
@@ -135,7 +135,8 @@ class Region(RegionClassObject):
                         if Flag:\r
                             continue\r
 \r
                         if Flag:\r
                             continue\r
 \r
-                        if FvBuffer.len > Size:\r
+                        FvBufferLen = len(FvBuffer.getvalue())\r
+                        if FvBufferLen > Size:\r
                             FvBuffer.close()\r
                             EdkLogger.error("GenFds", GENFDS_ERROR,\r
                                             "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size))\r
                             FvBuffer.close()\r
                             EdkLogger.error("GenFds", GENFDS_ERROR,\r
                                             "Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size))\r
@@ -144,8 +145,8 @@ class Region(RegionClassObject):
                         #\r
                         Buffer.write(FvBuffer.getvalue())\r
                         FvBuffer.close()\r
                         #\r
                         Buffer.write(FvBuffer.getvalue())\r
                         FvBuffer.close()\r
-                        FvOffset = FvOffset + FvBuffer.len\r
-                        Size = Size - FvBuffer.len\r
+                        FvOffset = FvOffset + FvBufferLen\r
+                        Size = Size - FvBufferLen\r
                         continue\r
                     else:\r
                         EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData))\r
                         continue\r
                     else:\r
                         EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData))\r
index 97f4e87587ee15f47a1930d563bc5a5b16daac77..76944c0e25b3284d69f1b30854162b4b785ffaf5 100644 (file)
@@ -17,7 +17,7 @@
 import Common.LongFilePathOs as os\r
 import sys\r
 import re\r
 import Common.LongFilePathOs as os\r
 import sys\r
 import re\r
-import StringIO\r
+from io import BytesIO\r
 \r
 from optparse import OptionParser\r
 from optparse import make_option\r
 \r
 from optparse import OptionParser\r
 from optparse import make_option\r
@@ -455,8 +455,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None)\r
 \r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None)\r
 \r
-    # Use a instance of StringIO to cache data\r
-    fStringIO = StringIO.StringIO('')\r
+    # Use a instance of BytesIO to cache data\r
+    fStringIO = BytesIO('')\r
 \r
     for Item in VfrUniOffsetList:\r
         if (Item[0].find("Strings") != -1):\r
 \r
     for Item in VfrUniOffsetList:\r
         if (Item[0].find("Strings") != -1):\r
index c9648a9299dd158086458cc3037654e366d2b1ab..897167cd11d62fe6ad4a8ee84e6962d3f351409c 100644 (file)
@@ -28,7 +28,7 @@ import hashlib
 import subprocess\r
 import threading\r
 from datetime import datetime\r
 import subprocess\r
 import threading\r
 from datetime import datetime\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from Common import EdkLogger\r
 from Common.Misc import SaveFileOnChange\r
 from Common.Misc import GuidStructureByteArrayToGuidString\r
 from Common import EdkLogger\r
 from Common.Misc import SaveFileOnChange\r
 from Common.Misc import GuidStructureByteArrayToGuidString\r
@@ -2169,7 +2169,7 @@ class BuildReport(object):
     def GenerateReport(self, BuildDuration, AutoGenTime, MakeTime, GenFdsTime):\r
         if self.ReportFile:\r
             try:\r
     def GenerateReport(self, BuildDuration, AutoGenTime, MakeTime, GenFdsTime):\r
         if self.ReportFile:\r
             try:\r
-                File = StringIO('')\r
+                File = BytesIO('')\r
                 for (Wa, MaList) in self.ReportList:\r
                     PlatformReport(Wa, MaList, self.ReportType).GenerateReport(File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, self.ReportType)\r
                 Content = FileLinesSplit(File.getvalue(), gLineMaxLength)\r
                 for (Wa, MaList) in self.ReportList:\r
                     PlatformReport(Wa, MaList, self.ReportType).GenerateReport(File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, self.ReportType)\r
                 Content = FileLinesSplit(File.getvalue(), gLineMaxLength)\r
index bf1f853d56be0720c9bbdd0ed83da08abe1f59bc..08e81016de8b363fcddb67db8f011ce43a5e11de 100644 (file)
@@ -19,7 +19,7 @@
 from __future__ import print_function\r
 import Common.LongFilePathOs as os\r
 import re\r
 from __future__ import print_function\r
 import Common.LongFilePathOs as os\r
 import re\r
-import StringIO\r
+from io import BytesIO\r
 import sys\r
 import glob\r
 import time\r
 import sys\r
 import glob\r
 import time\r
@@ -1782,7 +1782,7 @@ class Build():
                             if not Ma.IsLibrary:\r
                                 ModuleList[Ma.Guid.upper()] = Ma\r
 \r
                             if not Ma.IsLibrary:\r
                                 ModuleList[Ma.Guid.upper()] = Ma\r
 \r
-                    MapBuffer = StringIO('')\r
+                    MapBuffer = BytesIO('')\r
                     if self.LoadFixAddress != 0:\r
                         #\r
                         # Rebase module to the preferred memory address before GenFds\r
                     if self.LoadFixAddress != 0:\r
                         #\r
                         # Rebase module to the preferred memory address before GenFds\r
@@ -1940,7 +1940,7 @@ class Build():
                             if not Ma.IsLibrary:\r
                                 ModuleList[Ma.Guid.upper()] = Ma\r
 \r
                             if not Ma.IsLibrary:\r
                                 ModuleList[Ma.Guid.upper()] = Ma\r
 \r
-                    MapBuffer = StringIO('')\r
+                    MapBuffer = BytesIO('')\r
                     if self.LoadFixAddress != 0:\r
                         #\r
                         # Rebase module to the preferred memory address before GenFds\r
                     if self.LoadFixAddress != 0:\r
                         #\r
                         # Rebase module to the preferred memory address before GenFds\r
@@ -2127,7 +2127,7 @@ class Build():
                     #\r
                     # Rebase module to the preferred memory address before GenFds\r
                     #\r
                     #\r
                     # Rebase module to the preferred memory address before GenFds\r
                     #\r
-                    MapBuffer = StringIO('')\r
+                    MapBuffer = BytesIO('')\r
                     if self.LoadFixAddress != 0:\r
                         self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
 \r
                     if self.LoadFixAddress != 0:\r
                         self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
 \r