BaseTools: Replace StringIO.StringIO with io.BytesIO
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>
This commit is contained in:
@@ -25,7 +25,7 @@ import uuid
|
||||
import GenC
|
||||
import GenMake
|
||||
import GenDepex
|
||||
from StringIO import StringIO
|
||||
from io import BytesIO
|
||||
|
||||
from StrGather import *
|
||||
from BuildEngine import BuildRule
|
||||
@@ -3437,8 +3437,8 @@ class ModuleAutoGen(AutoGen):
|
||||
def _GetAutoGenFileList(self):
|
||||
UniStringAutoGenC = True
|
||||
IdfStringAutoGenC = True
|
||||
UniStringBinBuffer = StringIO()
|
||||
IdfGenBinBuffer = StringIO()
|
||||
UniStringBinBuffer = BytesIO()
|
||||
IdfGenBinBuffer = BytesIO()
|
||||
if self.BuildType == 'UEFI_HII':
|
||||
UniStringAutoGenC = False
|
||||
IdfStringAutoGenC = False
|
||||
@@ -3713,8 +3713,8 @@ class ModuleAutoGen(AutoGen):
|
||||
except:
|
||||
EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName, None)
|
||||
|
||||
# Use a instance of StringIO to cache data
|
||||
fStringIO = StringIO('')
|
||||
# Use a instance of BytesIO to cache data
|
||||
fStringIO = BytesIO('')
|
||||
|
||||
for Item in VfrUniOffsetList:
|
||||
if (Item[0].find("Strings") != -1):
|
||||
|
@@ -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
|
||||
@@ -345,7 +345,7 @@ class DependencyExpression:
|
||||
# @retval False If file exists and is not changed.
|
||||
#
|
||||
def Generate(self, File=None):
|
||||
Buffer = StringIO()
|
||||
Buffer = BytesIO()
|
||||
if len(self.PostfixNotation) == 0:
|
||||
return False
|
||||
|
||||
|
@@ -10,7 +10,7 @@
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
from StringIO import StringIO
|
||||
from io import BytesIO
|
||||
from Common.Misc import *
|
||||
from Common.StringUtils import StringToArray
|
||||
from struct import pack
|
||||
@@ -888,7 +888,7 @@ def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):
|
||||
DbFileName = os.path.join(Info.PlatformInfo.BuildDir, TAB_FV_DIRECTORY, Phase + "PcdDataBase.raw")
|
||||
else:
|
||||
DbFileName = os.path.join(Info.OutputDir, Phase + "PcdDataBase.raw")
|
||||
DbFile = StringIO()
|
||||
DbFile = BytesIO()
|
||||
DbFile.write(PcdDbBuffer)
|
||||
Changed = SaveFileOnChange(DbFileName, DbFile.getvalue(), True)
|
||||
def CreatePcdDataBase(PcdDBData):
|
||||
|
@@ -14,7 +14,6 @@
|
||||
# Import Modules
|
||||
#
|
||||
import Common.EdkLogger as EdkLogger
|
||||
import StringIO
|
||||
from Common.BuildToolError import *
|
||||
from Common.StringUtils import GetLineNo
|
||||
from Common.Misc import PathClass
|
||||
|
@@ -18,7 +18,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
|
||||
|
||||
@@ -341,7 +341,7 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer,
|
||||
if Language not in UniLanguageListFiltered:
|
||||
continue
|
||||
|
||||
StringBuffer = StringIO()
|
||||
StringBuffer = BytesIO()
|
||||
StrStringValue = ''
|
||||
ArrayLength = 0
|
||||
NumberOfUseOtherLangDef = 0
|
||||
|
@@ -20,7 +20,7 @@ from __future__ import print_function
|
||||
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.StringUtils import GetLineNo
|
||||
from Common.Misc import PathClass
|
||||
@@ -320,7 +320,7 @@ class UniFileClassObject(object):
|
||||
|
||||
UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding)
|
||||
|
||||
UniFile = StringIO.StringIO(FileIn)
|
||||
UniFile = BytesIO(FileIn)
|
||||
Info = codecs.lookup(Encoding)
|
||||
(Reader, Writer) = (Info.streamreader, Info.streamwriter)
|
||||
return codecs.StreamReaderWriter(UniFile, Reader, Writer)
|
||||
@@ -335,7 +335,7 @@ class UniFileClassObject(object):
|
||||
FileDecoded = codecs.decode(FileIn, Encoding)
|
||||
Ucs2Info.encode(FileDecoded)
|
||||
except:
|
||||
UniFile = StringIO.StringIO(FileIn)
|
||||
UniFile = BytesIO(FileIn)
|
||||
Info = codecs.lookup(Encoding)
|
||||
(Reader, Writer) = (Info.streamreader, Info.streamwriter)
|
||||
File = codecs.StreamReaderWriter(UniFile, Reader, Writer)
|
||||
|
@@ -17,7 +17,7 @@
|
||||
import os
|
||||
from Common.RangeExpression import RangeExpression
|
||||
from Common.Misc import *
|
||||
from StringIO import StringIO
|
||||
from io import BytesIO
|
||||
from struct import pack
|
||||
from Common.DataType import *
|
||||
|
||||
@@ -162,7 +162,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
|
||||
Buffer += b
|
||||
realLength += 1
|
||||
|
||||
DbFile = StringIO()
|
||||
DbFile = BytesIO()
|
||||
if Phase == 'DXE' and os.path.exists(BinFilePath):
|
||||
BinFile = open(BinFilePath, "rb")
|
||||
BinBuffer = BinFile.read()
|
||||
|
Reference in New Issue
Block a user