From nobody Mon Dec 23 15:28:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1517474256736682.4224580212503; Thu, 1 Feb 2018 00:37:36 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 07FCF21E0BA0B; Thu, 1 Feb 2018 00:31:35 -0800 (PST) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 45C7F21E0B9E2 for ; Thu, 1 Feb 2018 00:31:33 -0800 (PST) Received: from localhost.localdomain (unknown.telstraglobal.net [134.159.103.118]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Thu, 01 Feb 2018 09:37:07 +0100 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=195.135.221.5; helo=smtp.nue.novell.com; envelope-from=glin@suse.com; receiver=edk2-devel@lists.01.org From: Gary Lin To: edk2-devel@lists.01.org Date: Thu, 1 Feb 2018 16:36:03 +0800 Message-Id: <20180201083608.16036-16-glin@suse.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180201083608.16036-1-glin@suse.com> References: <20180201083608.16036-1-glin@suse.com> Subject: [edk2] [PATCH v2 15/20] BaseTools: Replace StringIO.StringIO with io.BytesIO X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Cc: Liming Gao Signed-off-by: Gary Lin --- BaseTools/Scripts/ConvertUni.py | 5 ----- BaseTools/Source/Python/AutoGen/AutoGen.py | 10 +++++----- BaseTools/Source/Python/AutoGen/GenDepex.py | 4 ++-- BaseTools/Source/Python/AutoGen/GenPcdDb.py | 4 ++-- BaseTools/Source/Python/AutoGen/IdfClassObject.py | 1 - BaseTools/Source/Python/AutoGen/StrGather.py | 4 ++-- BaseTools/Source/Python/AutoGen/UniClassObject.py | 6 +++--- BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py | 4 ++-- BaseTools/Source/Python/BPDG/GenVpd.py | 6 +++--- BaseTools/Source/Python/Eot/FvImage.py | 1 - BaseTools/Source/Python/GenFds/AprioriSection.py | 4 ++-- BaseTools/Source/Python/GenFds/Capsule.py | 10 +++++----- BaseTools/Source/Python/GenFds/CapsuleData.py | 4 ++-- BaseTools/Source/Python/GenFds/Fd.py | 6 +++--- BaseTools/Source/Python/GenFds/FfsFileStatement.py | 4 ++-- BaseTools/Source/Python/GenFds/FfsInfStatement.py | 4 ++-- BaseTools/Source/Python/GenFds/Fv.py | 6 +++--- BaseTools/Source/Python/GenFds/FvImageSection.py | 4 ++-- BaseTools/Source/Python/GenFds/GenFds.py | 8 ++++---- BaseTools/Source/Python/GenFds/OptionRom.py | 3 --- BaseTools/Source/Python/GenFds/Region.py | 11 ++++++----- BaseTools/Source/Python/Trim/Trim.py | 6 +++--- BaseTools/Source/Python/build/BuildReport.py | 4 ++-- BaseTools/Source/Python/build/build.py | 8 ++++---- 24 files changed, 59 insertions(+), 68 deletions(-) diff --git a/BaseTools/Scripts/ConvertUni.py b/BaseTools/Scripts/ConvertUni= .py index 2af55dfc6702..67bbe41b1f18 100755 --- a/BaseTools/Scripts/ConvertUni.py +++ b/BaseTools/Scripts/ConvertUni.py @@ -23,11 +23,6 @@ import codecs import os import sys =20 -try: - from io import StringIO -except ImportError: - from StringIO import StringIO - class ConvertOneArg: """Converts utf-16 to utf-8 for one command line argument. =20 diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/= Python/AutoGen/AutoGen.py index 5af16e6d68d7..2bc925aa1e08 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -24,7 +24,7 @@ import uuid import GenC import GenMake import GenDepex -from StringIO import StringIO +from io import BytesIO =20 from StrGather import * from BuildEngine import BuildRule @@ -3603,8 +3603,8 @@ class ModuleAutoGen(AutoGen): def _GetAutoGenFileList(self): UniStringAutoGenC =3D True IdfStringAutoGenC =3D True - UniStringBinBuffer =3D StringIO() - IdfGenBinBuffer =3D StringIO() + UniStringBinBuffer =3D BytesIO() + IdfGenBinBuffer =3D BytesIO() if self.BuildType =3D=3D 'UEFI_HII': UniStringAutoGenC =3D False IdfStringAutoGenC =3D False @@ -3888,8 +3888,8 @@ class ModuleAutoGen(AutoGen): except: EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed = for %s" % UniVfrOffsetFileName, None) =20 - # Use a instance of StringIO to cache data - fStringIO =3D StringIO('') =20 + # Use a instance of BytesIO to cache data + fStringIO =3D BytesIO('') =20 for Item in VfrUniOffsetList: if (Item[0].find("Strings") !=3D -1): diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py b/BaseTools/Source= /Python/AutoGen/GenDepex.py index 0f6a1700f541..bb516b651266 100644 --- a/BaseTools/Source/Python/AutoGen/GenDepex.py +++ b/BaseTools/Source/Python/AutoGen/GenDepex.py @@ -17,7 +17,7 @@ import Common.LongFilePathOs as os import re import traceback from Common.LongFilePathSupport import OpenLongFilePath as open -from StringIO import StringIO +from io import BytesIO from struct import pack from Common.BuildToolError import * from Common.Misc import SaveFileOnChange @@ -344,7 +344,7 @@ class DependencyExpression: # @retval False If file exists and is not changed. # def Generate(self, File=3DNone): - Buffer =3D StringIO() + Buffer =3D BytesIO() if len(self.PostfixNotation) =3D=3D 0: return False =20 diff --git a/BaseTools/Source/Python/AutoGen/GenPcdDb.py b/BaseTools/Source= /Python/AutoGen/GenPcdDb.py index 85e6f44502a2..716ec8ca3f52 100644 --- a/BaseTools/Source/Python/AutoGen/GenPcdDb.py +++ b/BaseTools/Source/Python/AutoGen/GenPcdDb.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. # from builtins import range -from StringIO import StringIO +from io import BytesIO from Common.Misc import * from Common.String import StringToArray from struct import pack @@ -976,7 +976,7 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH): DbFileName =3D os.path.join(Info.PlatformInfo.BuildDir, "FV", Phas= e + "PcdDataBase.raw") else: DbFileName =3D os.path.join(Info.OutputDir, Phase + "PcdDataBase.r= aw") - DbFile =3D StringIO() + DbFile =3D BytesIO() DbFile.write(PcdDbBuffer) Changed =3D SaveFileOnChange(DbFileName, DbFile.getvalue(), True) def CreatePcdDataBase(PcdDBData): diff --git a/BaseTools/Source/Python/AutoGen/IdfClassObject.py b/BaseTools/= Source/Python/AutoGen/IdfClassObject.py index d6d4703370aa..db1e5ee6a32d 100644 --- a/BaseTools/Source/Python/AutoGen/IdfClassObject.py +++ b/BaseTools/Source/Python/AutoGen/IdfClassObject.py @@ -14,7 +14,6 @@ # Import Modules # import Common.EdkLogger as EdkLogger -import StringIO from Common.BuildToolError import * from Common.String import GetLineNo from Common.Misc import PathClass diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Sourc= e/Python/AutoGen/StrGather.py index 718cd60514b4..b61450c02831 100644 --- a/BaseTools/Source/Python/AutoGen/StrGather.py +++ b/BaseTools/Source/Python/AutoGen/StrGather.py @@ -19,7 +19,7 @@ import re import Common.EdkLogger as EdkLogger from Common.BuildToolError import * from UniClassObject import * -from StringIO import StringIO +from io import BytesIO from struct import pack, unpack from Common.LongFilePathSupport import OpenLongFilePath as open =20 @@ -382,7 +382,7 @@ def CreateCFileContent(BaseName, UniObjectClass, IsComp= atibleMode, UniBinBuffer, if Language not in UniLanguageListFiltered: continue =20 - StringBuffer =3D StringIO() + StringBuffer =3D BytesIO() StrStringValue =3D '' ArrayLength =3D 0 NumberOfUseOtherLangDef =3D 0 diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/= Source/Python/AutoGen/UniClassObject.py index cab7623bc4e6..5c4ccd7a8b77 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -21,7 +21,7 @@ from builtins import range import Common.LongFilePathOs as os, codecs, re import distutils.util import Common.EdkLogger as EdkLogger -import StringIO +from io import BytesIO from Common.BuildToolError import * from Common.String import GetLineNo from Common.Misc import PathClass @@ -308,7 +308,7 @@ class UniFileClassObject(object): =20 self.VerifyUcs2Data(FileIn, FileName, Encoding) =20 - UniFile =3D StringIO.StringIO(FileIn) + UniFile =3D BytesIO(FileIn) Info =3D codecs.lookup(Encoding) (Reader, Writer) =3D (Info.streamreader, Info.streamwriter) return codecs.StreamReaderWriter(UniFile, Reader, Writer) @@ -322,7 +322,7 @@ class UniFileClassObject(object): FileDecoded =3D codecs.decode(FileIn, Encoding) Ucs2Info.encode(FileDecoded) except: - UniFile =3D StringIO.StringIO(FileIn) + UniFile =3D BytesIO(FileIn) Info =3D codecs.lookup(Encoding) (Reader, Writer) =3D (Info.streamreader, Info.streamwriter) File =3D codecs.StreamReaderWriter(UniFile, Reader, Writer) diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/B= aseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py index ff355d05d79f..60027390e820 100644 --- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py +++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py @@ -19,7 +19,7 @@ from builtins import range import os from Common.RangeExpression import RangeExpression from Common.Misc import * -from StringIO import StringIO +from io import BytesIO from struct import pack =20 class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object): @@ -181,7 +181,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object): Buffer +=3D b realLength +=3D 1 =20 - DbFile =3D StringIO() + DbFile =3D BytesIO() if Phase =3D=3D 'DXE' and os.path.exists(BinFilePath): BinFile =3D open(BinFilePath, "rb") BinBuffer =3D BinFile.read() diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Pyth= on/BPDG/GenVpd.py index 1bb37d744ec9..54b2cc54f578 100644 --- a/BaseTools/Source/Python/BPDG/GenVpd.py +++ b/BaseTools/Source/Python/BPDG/GenVpd.py @@ -15,7 +15,7 @@ =20 from builtins import range import Common.LongFilePathOs as os -import StringIO +from io import BytesIO import StringTable as st import array import re @@ -674,8 +674,8 @@ class GenVPD : # Open failed EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "Fil= e open failed for %s" % self.MapFileName, None) =20 - # Use a instance of StringIO to cache data - fStringIO =3D StringIO.StringIO('') + # Use a instance of BytesIO to cache data + fStringIO =3D BytesIO('') =20 # Write the header of map file. try : diff --git a/BaseTools/Source/Python/Eot/FvImage.py b/BaseTools/Source/Pyth= on/Eot/FvImage.py index 64a27217e4a8..0a1eca1ed86f 100644 --- a/BaseTools/Source/Python/Eot/FvImage.py +++ b/BaseTools/Source/Python/Eot/FvImage.py @@ -24,7 +24,6 @@ import codecs import copy =20 from UserDict import IterableUserDict -from cStringIO import StringIO from array import array from Common.LongFilePathSupport import OpenLongFilePath as open from CommonDataClass import * diff --git a/BaseTools/Source/Python/GenFds/AprioriSection.py b/BaseTools/S= ource/Python/GenFds/AprioriSection.py index b678079b3785..65919270af15 100644 --- a/BaseTools/Source/Python/GenFds/AprioriSection.py +++ b/BaseTools/Source/Python/GenFds/AprioriSection.py @@ -18,7 +18,7 @@ from builtins import range from struct import * import Common.LongFilePathOs as os -import StringIO +from io import BytesIO import FfsFileStatement from GenFdsGlobalVariable import GenFdsGlobalVariable from CommonDataClass.FdfClass import AprioriSectionClassObject @@ -51,7 +51,7 @@ class AprioriSection (AprioriSectionClassObject): def GenFfs (self, FvName, Dict =3D {}, IsMakefile =3D False): DXE_GUID =3D "FC510EE7-FFDC-11D4-BD41-0080C73C8881" PEI_GUID =3D "1B45CC0A-156A-428A-AF62-49864DA0E6E6" - Buffer =3D StringIO.StringIO('') + Buffer =3D BytesIO('') AprioriFileGuid =3D DXE_GUID if self.AprioriType =3D=3D "PEI": AprioriFileGuid =3D PEI_GUID diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/P= ython/GenFds/Capsule.py index e03d78995737..60019195df27 100644 --- a/BaseTools/Source/Python/GenFds/Capsule.py +++ b/BaseTools/Source/Python/GenFds/Capsule.py @@ -19,7 +19,7 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable from CommonDataClass.FdfClass import CapsuleClassObject import Common.LongFilePathOs as os import subprocess -import StringIO +from io import BytesIO from Common.Misc import SaveFileOnChange from GenFds import GenFds from Common.Misc import PackRegistryFormatGuid @@ -66,7 +66,7 @@ class Capsule (CapsuleClassObject) : # UINT32 CapsuleImageSize; # } EFI_CAPSULE_HEADER; # - Header =3D StringIO.StringIO() + Header =3D BytesIO() # # Use FMP capsule GUID: 6DCBD5ED-E82D-4C44-BDA1-7194199AD92A # @@ -97,7 +97,7 @@ class Capsule (CapsuleClassObject) : # // UINT64 ItemOffsetList[]; # } EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER; # - FwMgrHdr =3D StringIO.StringIO() + FwMgrHdr =3D BytesIO() if 'CAPSULE_HEADER_INIT_VERSION' in self.TokensDict: FwMgrHdr.write(pack('=3DI', int(self.TokensDict['CAPSULE_HEADE= R_INIT_VERSION'], 16))) else: @@ -132,7 +132,7 @@ class Capsule (CapsuleClassObject) : # =20 PreSize =3D FwMgrHdrSize - Content =3D StringIO.StringIO() + Content =3D BytesIO() for driver in self.CapsuleDataList: FileName =3D driver.GenCapsuleSubItem() FwMgrHdr.write(pack('=3DQ', PreSize)) @@ -247,7 +247,7 @@ class Capsule (CapsuleClassObject) : def GenCapInf(self): self.CapInfFileName =3D os.path.join(GenFdsGlobalVariable.FvDir, self.UiCapsuleName + "_Cap" + '.inf') - CapInfFile =3D StringIO.StringIO() #open (self.CapInfFileName , 'w= +') + CapInfFile =3D BytesIO() #open (self.CapInfFileName , 'w+') =20 CapInfFile.writelines("[options]" + T_CHAR_LF) =20 diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py b/BaseTools/Sour= ce/Python/GenFds/CapsuleData.py index 1fa202149b25..f0a55d81120b 100644 --- a/BaseTools/Source/Python/GenFds/CapsuleData.py +++ b/BaseTools/Source/Python/GenFds/CapsuleData.py @@ -17,7 +17,7 @@ # import Ffs from GenFdsGlobalVariable import GenFdsGlobalVariable -import StringIO +from io import BytesIO from struct import pack import os from Common.Misc import SaveFileOnChange @@ -82,7 +82,7 @@ class CapsuleFv (CapsuleData): if self.FvName.find('.fv') =3D=3D -1: if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profi= le.FvDict.keys(): FvObj =3D GenFdsGlobalVariable.FdfParser.Profile.FvDict.ge= t(self.FvName.upper()) - FdBuffer =3D StringIO.StringIO('') + FdBuffer =3D BytesIO('') FvObj.CapsuleName =3D self.CapsuleName FvFile =3D FvObj.AddToBuffer(FdBuffer) FvObj.CapsuleName =3D None diff --git a/BaseTools/Source/Python/GenFds/Fd.py b/BaseTools/Source/Python= /GenFds/Fd.py index 21060625217e..acd73f6449f6 100644 --- a/BaseTools/Source/Python/GenFds/Fd.py +++ b/BaseTools/Source/Python/GenFds/Fd.py @@ -18,7 +18,7 @@ import Region import Fv import Common.LongFilePathOs as os -import StringIO +from io import BytesIO import sys from struct import * from GenFdsGlobalVariable import GenFdsGlobalVariable @@ -74,7 +74,7 @@ class FD(FDClassObject): HasCapsuleRegion =3D True break if HasCapsuleRegion: - TempFdBuffer =3D StringIO.StringIO('') + TempFdBuffer =3D BytesIO('') PreviousRegionStart =3D -1 PreviousRegionSize =3D 1 =20 @@ -103,7 +103,7 @@ class FD(FDClassObject): GenFdsGlobalVariable.VerboseLogger('Call each region\'s Ad= dToBuffer function') RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, sel= f.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, = self.DefineVarDict) =20 - FdBuffer =3D StringIO.StringIO('') + FdBuffer =3D BytesIO('') PreviousRegionStart =3D -1 PreviousRegionSize =3D 1 for RegionObj in self.RegionList : diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools= /Source/Python/GenFds/FfsFileStatement.py index cbfea730ef18..1293c8a107f0 100644 --- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py @@ -19,7 +19,7 @@ from builtins import range import Ffs import Rule import Common.LongFilePathOs as os -import StringIO +from io import BytesIO import subprocess =20 from GenFdsGlobalVariable import GenFdsGlobalVariable @@ -83,7 +83,7 @@ class FileStatement (FileStatementClassObject) : Dict.update(self.DefineVarDict) SectionAlignments =3D None if self.FvName !=3D None : - Buffer =3D StringIO.StringIO('') + Buffer =3D BytesIO('') if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.P= rofile.FvDict.keys(): EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT de= scribed in FDF file!" % (self.FvName)) Fv =3D GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.= FvName.upper()) diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/= Source/Python/GenFds/FfsInfStatement.py index 3a781d6d3a97..d6edd1f0971e 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -18,7 +18,7 @@ # import Rule import Common.LongFilePathOs as os -import StringIO +from io import BytesIO from struct import * from GenFdsGlobalVariable import GenFdsGlobalVariable import Ffs @@ -1091,7 +1091,7 @@ class FfsInfStatement(FfsInfStatementClassObject): def __GenUniVfrOffsetFile(self, VfrUniOffsetList, UniVfrOffsetFileName= ): =20 # Use a instance of StringIO to cache data - fStringIO =3D StringIO.StringIO('') =20 + fStringIO =3D BytesIO('') =20 for Item in VfrUniOffsetList: if (Item[0].find("Strings") !=3D -1): diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python= /GenFds/Fv.py index c64c0c80e299..88a520998eae 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -18,7 +18,7 @@ from builtins import range import Common.LongFilePathOs as os import subprocess -import StringIO +from io import BytesIO from struct import * =20 import Ffs @@ -268,7 +268,7 @@ class FV (FvClassObject): # self.InfFileName =3D os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.inf') - self.FvInfFile =3D StringIO.StringIO() + self.FvInfFile =3D BytesIO() =20 # # Add [Options] @@ -427,7 +427,7 @@ class FV (FvClassObject): # if TotalSize > 0: FvExtHeaderFileName =3D os.path.join(GenFdsGlobalVariable.= FvDir, self.UiFvName + '.ext') - FvExtHeaderFile =3D StringIO.StringIO() + FvExtHeaderFile =3D BytesIO() FvExtHeaderFile.write(Buffer) Changed =3D SaveFileOnChange(FvExtHeaderFileName, FvExtHea= derFile.getvalue(), True) FvExtHeaderFile.close() diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/S= ource/Python/GenFds/FvImageSection.py index ac5d5891df70..7416ce1b7d8a 100644 --- a/BaseTools/Source/Python/GenFds/FvImageSection.py +++ b/BaseTools/Source/Python/GenFds/FvImageSection.py @@ -16,7 +16,7 @@ # Import Modules # import Section -import StringIO +from io import BytesIO from Ffs import Ffs import subprocess from GenFdsGlobalVariable import GenFdsGlobalVariable @@ -97,7 +97,7 @@ class FvImageSection(FvImageSectionClassObject): # Generate Fv # if self.FvName !=3D None: - Buffer =3D StringIO.StringIO('') + Buffer =3D BytesIO('') Fv =3D GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.= FvName) if Fv !=3D None: self.Fv =3D Fv diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Py= thon/GenFds/GenFds.py index cb8dabbe038d..ebebcd7980e4 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -29,7 +29,7 @@ from Workspace.BuildClassObject import PcdClassObject from Workspace.BuildClassObject import ModuleBuildClassObject import RuleComplexFile from EfiSection import EfiSection -import StringIO +from io import BytesIO import Common.TargetTxtClassObject as TargetTxtClassObject import Common.ToolDefClassObject as ToolDefClassObject from Common.DataType import * @@ -591,13 +591,13 @@ class GenFds : if GenFds.OnlyGenerateThisFv !=3D None and GenFds.OnlyGenerateThis= Fv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): FvObj =3D GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(Ge= nFds.OnlyGenerateThisFv.upper()) if FvObj !=3D None: - Buffer =3D StringIO.StringIO() + Buffer =3D BytesIO() FvObj.AddToBuffer(Buffer) Buffer.close() return elif GenFds.OnlyGenerateThisFv =3D=3D None: for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.ke= ys(): - Buffer =3D StringIO.StringIO('') + Buffer =3D BytesIO('') FvObj =3D GenFdsGlobalVariable.FdfParser.Profile.FvDict[Fv= Name] FvObj.AddToBuffer(Buffer) Buffer.close() @@ -749,7 +749,7 @@ class GenFds : =20 def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj): GuidXRefFileName =3D os.path.join(GenFdsGlobalVariable.FvDir, "Gui= d.xref") - GuidXRefFile =3D StringIO.StringIO('') + GuidXRefFile =3D BytesIO('') GuidDict =3D {} ModuleList =3D [] FileGuidList =3D [] diff --git a/BaseTools/Source/Python/GenFds/OptionRom.py b/BaseTools/Source= /Python/GenFds/OptionRom.py index 2e61a38c1d33..946cdf812a24 100644 --- a/BaseTools/Source/Python/GenFds/OptionRom.py +++ b/BaseTools/Source/Python/GenFds/OptionRom.py @@ -17,7 +17,6 @@ # import Common.LongFilePathOs as os import subprocess -import StringIO =20 import OptRomInfStatement from GenFdsGlobalVariable import GenFdsGlobalVariable @@ -138,5 +137,3 @@ class OverrideAttribs: self.PciDeviceId =3D None self.PciRevision =3D None self.NeedCompress =3D None - =20 - =20 \ No newline at end of file diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Py= thon/GenFds/Region.py index 5b9b203cf475..6ace73abe904 100644 --- a/BaseTools/Source/Python/GenFds/Region.py +++ b/BaseTools/Source/Python/GenFds/Region.py @@ -18,7 +18,7 @@ from builtins import range from struct import * from GenFdsGlobalVariable import GenFdsGlobalVariable -import StringIO +from io import BytesIO import string from CommonDataClass.FdfClass import RegionClassObject import Common.LongFilePathOs as os @@ -127,7 +127,7 @@ class Region(RegionClassObject): if self.FvAddress % FvAlignValue !=3D 0: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT %s Aligned!" %= (FvObj.UiFvName, FvObj.FvAlignment)) - FvBuffer =3D StringIO.StringIO('') + FvBuffer =3D BytesIO('') FvBaseAddress =3D '0x%X' % self.FvAddress BlockSize =3D None BlockNum =3D None @@ -135,7 +135,8 @@ class Region(RegionClassObject): if Flag: continue =20 - if FvBuffer.len > Size: + FvBufferLen =3D len(FvBuffer.getvalue()) + if FvBufferLen > Size: FvBuffer.close() EdkLogger.error("GenFds", GENFDS_ERROR, "Size of FV (%s) is larger tha= n Region Size 0x%X specified." % (RegionData, Size)) @@ -144,8 +145,8 @@ class Region(RegionClassObject): # Buffer.write(FvBuffer.getvalue()) FvBuffer.close() - FvOffset =3D FvOffset + FvBuffer.len - Size =3D Size - FvBuffer.len + FvOffset =3D FvOffset + FvBufferLen + Size =3D Size - FvBufferLen continue else: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) i= s NOT described in FDF file!" % (RegionData)) diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python= /Trim/Trim.py index af1bf9de3e00..87edfbe31fbf 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -18,7 +18,7 @@ from builtins import range import Common.LongFilePathOs as os import sys import re -import StringIO +from io import BytesIO =20 from optparse import OptionParser from optparse import make_option @@ -455,8 +455,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %= s" %OutputFile, None) =20 - # Use a instance of StringIO to cache data - fStringIO =3D StringIO.StringIO('') + # Use a instance of BytesIO to cache data + fStringIO =3D BytesIO('') =20 for Item in VfrUniOffsetList: if (Item[0].find("Strings") !=3D -1): diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Sourc= e/Python/build/BuildReport.py index 10b480d619c5..be57bcd40ba8 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -28,7 +28,7 @@ import hashlib import subprocess import threading from datetime import datetime -from StringIO import StringIO +from io import BytesIO from Common import EdkLogger from Common.Misc import SaveFileOnChange from Common.Misc import GuidStructureByteArrayToGuidString @@ -2062,7 +2062,7 @@ class BuildReport(object): def GenerateReport(self, BuildDuration, AutoGenTime, MakeTime, GenFdsT= ime): if self.ReportFile: try: - File =3D StringIO('') + File =3D BytesIO('') for (Wa, MaList) in self.ReportList: PlatformReport(Wa, MaList, self.ReportType).GenerateRe= port(File, BuildDuration, AutoGenTime, MakeTime, GenFdsTime, self.ReportTyp= e) Content =3D FileLinesSplit(File.getvalue(), gLineMaxLength) diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Pyth= on/build/build.py index 03983c34beae..66b46fab5c26 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -19,7 +19,7 @@ from __future__ import print_function import Common.LongFilePathOs as os import re -import StringIO +from io import BytesIO import sys import glob import time @@ -1784,7 +1784,7 @@ class Build(): if not Ma.IsLibrary: ModuleList[Ma.Guid.upper()] =3D Ma =20 - MapBuffer =3D StringIO('') + MapBuffer =3D BytesIO('') if self.LoadFixAddress !=3D 0: # # Rebase module to the preferred memory address be= fore GenFds @@ -1934,7 +1934,7 @@ class Build(): if not Ma.IsLibrary: ModuleList[Ma.Guid.upper()] =3D Ma =20 - MapBuffer =3D StringIO('') + MapBuffer =3D BytesIO('') if self.LoadFixAddress !=3D 0: # # Rebase module to the preferred memory address be= fore GenFds @@ -2122,7 +2122,7 @@ class Build(): # # Rebase module to the preferred memory address before= GenFds # - MapBuffer =3D StringIO('') + MapBuffer =3D BytesIO('') if self.LoadFixAddress !=3D 0: self._CollectModuleMapBuffer(MapBuffer, ModuleList) =20 --=20 2.16.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel