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>
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
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
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
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
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
# @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
# 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
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
# 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
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
if Language not in UniLanguageListFiltered:\r
continue\r
\r
- StringBuffer = StringIO()\r
+ StringBuffer = BytesIO()\r
StrStringValue = ''\r
ArrayLength = 0\r
NumberOfUseOtherLangDef = 0\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
\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
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
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
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
#\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
# 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
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
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
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
# 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
# // 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
#\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
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
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
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
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
HasCapsuleRegion = True\r
break\r
if HasCapsuleRegion:\r
- TempFdBuffer = StringIO.StringIO('')\r
+ TempFdBuffer = BytesIO('')\r
PreviousRegionStart = -1\r
PreviousRegionSize = 1\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
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
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
#\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
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
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
#\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
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
# 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
# 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
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
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
- Buffer = StringIO.StringIO('')\r
+ Buffer = BytesIO('')\r
FvObj.AddToBuffer(Buffer)\r
Buffer.close()\r
\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
#\r
import Common.LongFilePathOs as os\r
import subprocess\r
-import StringIO\r
\r
import OptRomInfStatement\r
from GenFdsGlobalVariable import GenFdsGlobalVariable\r
self.PciDeviceId = None\r
self.PciRevision = None\r
self.NeedCompress = None\r
- \r
-
\ No newline at end of file
#\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
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
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
#\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
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
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
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
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
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
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 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
#\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