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....@intel.com>
Cc: Liming Gao <liming....@intel.com>
Signed-off-by: Gary Lin <g...@suse.com>
---
 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/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 ++++----
 23 files changed, 59 insertions(+), 67 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
 
-try:
-    from io import StringIO
-except ImportError:
-    from StringIO import StringIO
-
 class ConvertOneArg:
     """Converts utf-16 to utf-8 for one command line argument.
 
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 94c5b80cb23b..8fa5c6f306f3 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -26,7 +26,7 @@ import uuid
 import GenC
 import GenMake
 import GenDepex
-from StringIO import StringIO
+from io import BytesIO
 
 from StrGather import *
 from BuildEngine import BuildRule
@@ -3438,8 +3438,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
@@ -3714,8 +3714,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):
diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py 
b/BaseTools/Source/Python/AutoGen/GenDepex.py
index e89191a72b9f..d3b1eae181c2 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
@@ -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
 
diff --git a/BaseTools/Source/Python/AutoGen/GenPcdDb.py 
b/BaseTools/Source/Python/AutoGen/GenPcdDb.py
index 35c709fa71f9..d3790cc42cca 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 IMPLIED.
 #
 from builtins import range
-from StringIO import StringIO
+from io import BytesIO
 from Common.Misc import *
 from Common.StringUtils import StringToArray
 from struct import pack
@@ -889,7 +889,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):
diff --git a/BaseTools/Source/Python/AutoGen/IdfClassObject.py 
b/BaseTools/Source/Python/AutoGen/IdfClassObject.py
index e5b933c2036f..b656bd83e3ba 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.StringUtils import GetLineNo
 from Common.Misc import PathClass
diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py 
b/BaseTools/Source/Python/AutoGen/StrGather.py
index 9620a5f2ea71..77b7aaa31a0a 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
 
@@ -342,7 +342,7 @@ def CreateCFileContent(BaseName, UniObjectClass, 
IsCompatibleMode, UniBinBuffer,
         if Language not in UniLanguageListFiltered:
             continue
         
-        StringBuffer = StringIO()
+        StringBuffer = BytesIO()
         StrStringValue = ''
         ArrayLength = 0
         NumberOfUseOtherLangDef = 0
diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py 
b/BaseTools/Source/Python/AutoGen/UniClassObject.py
index 438f3394d55b..c7dd510a20de 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.StringUtils import GetLineNo
 from Common.Misc import PathClass
@@ -321,7 +321,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)
@@ -336,7 +336,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)
diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py 
b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
index 20356c6bcfab..e6cbf449ec8a 100644
--- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
+++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
@@ -18,7 +18,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
 from Common.DataType import *
 
@@ -163,7 +163,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()
diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py 
b/BaseTools/Source/Python/BPDG/GenVpd.py
index 6dbc2c421730..83acac1f9ae0 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -15,7 +15,7 @@
 
 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, "File 
open failed for %s" % self.MapFileName, None)
 
-        # Use a instance of StringIO to cache data
-        fStringIO = StringIO.StringIO('')
+        # Use a instance of BytesIO to cache data
+        fStringIO = BytesIO('')
 
         # Write the header of map file.
         try :
diff --git a/BaseTools/Source/Python/GenFds/AprioriSection.py 
b/BaseTools/Source/Python/GenFds/AprioriSection.py
index 1288349c7c4b..5d1e56b7f1da 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
@@ -52,7 +52,7 @@ class AprioriSection (AprioriSectionClassObject):
     def GenFfs (self, FvName, Dict = {}, IsMakefile = False):
         DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881"
         PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6"
-        Buffer = StringIO.StringIO('')
+        Buffer = BytesIO('')
         AprioriFileGuid = DXE_GUID
         if self.AprioriType == "PEI":
             AprioriFileGuid = PEI_GUID
diff --git a/BaseTools/Source/Python/GenFds/Capsule.py 
b/BaseTools/Source/Python/GenFds/Capsule.py
index fbd48f3c6d76..b02661d99855 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 = StringIO.StringIO()
+        Header = 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 = StringIO.StringIO()
+        FwMgrHdr = BytesIO()
         if 'CAPSULE_HEADER_INIT_VERSION' in self.TokensDict:
             FwMgrHdr.write(pack('=I', 
int(self.TokensDict['CAPSULE_HEADER_INIT_VERSION'], 16)))
         else:
@@ -132,7 +132,7 @@ class Capsule (CapsuleClassObject) :
         #
 
         PreSize = FwMgrHdrSize
-        Content = StringIO.StringIO()
+        Content = BytesIO()
         for driver in self.CapsuleDataList:
             FileName = driver.GenCapsuleSubItem()
             FwMgrHdr.write(pack('=Q', PreSize))
@@ -247,7 +247,7 @@ class Capsule (CapsuleClassObject) :
     def GenCapInf(self):
         self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
                                    self.UiCapsuleName +  "_Cap" + '.inf')
-        CapInfFile = StringIO.StringIO() #open (self.CapInfFileName , 'w+')
+        CapInfFile = BytesIO() #open (self.CapInfFileName , 'w+')
 
         CapInfFile.writelines("[options]" + T_CHAR_LF)
 
diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py 
b/BaseTools/Source/Python/GenFds/CapsuleData.py
index 9dc55e5dbf7b..83b2731110bc 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') == -1:
             if self.FvName.upper() in 
GenFdsGlobalVariable.FdfParser.Profile.FvDict:
                 FvObj = 
GenFdsGlobalVariable.FdfParser.Profile.FvDict[self.FvName.upper()]
-                FdBuffer = StringIO.StringIO('')
+                FdBuffer = BytesIO('')
                 FvObj.CapsuleName = self.CapsuleName
                 FvFile = FvObj.AddToBuffer(FdBuffer)
                 FvObj.CapsuleName = None
diff --git a/BaseTools/Source/Python/GenFds/Fd.py 
b/BaseTools/Source/Python/GenFds/Fd.py
index b2a14a1e1313..3305a470edfa 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
@@ -75,7 +75,7 @@ class FD(FDClassObject):
                 HasCapsuleRegion = True
                 break
         if HasCapsuleRegion:
-            TempFdBuffer = StringIO.StringIO('')
+            TempFdBuffer = BytesIO('')
             PreviousRegionStart = -1
             PreviousRegionSize = 1
 
@@ -104,7 +104,7 @@ class FD(FDClassObject):
                 GenFdsGlobalVariable.VerboseLogger('Call each region\'s 
AddToBuffer function')
                 RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, 
self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, 
self.DefineVarDict)
         
-        FdBuffer = StringIO.StringIO('')
+        FdBuffer = BytesIO('')
         PreviousRegionStart = -1
         PreviousRegionSize = 1
         for RegionObj in self.RegionList :
diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py 
b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
index c3bccb47be2c..74c4b3d8adb6 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
 
 from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -83,7 +83,7 @@ class FileStatement (FileStatementClassObject) :
         Dict.update(self.DefineVarDict)
         SectionAlignments = None
         if self.FvName is not None :
-            Buffer = StringIO.StringIO('')
+            Buffer = BytesIO('')
             if self.FvName.upper() not in 
GenFdsGlobalVariable.FdfParser.Profile.FvDict:
                 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT 
described in FDF file!" % (self.FvName))
             Fv = 
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 9eb99d659bfd..ef34dbf00754 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
@@ -1088,7 +1088,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
     def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):
 
         # Use a instance of StringIO to cache data
-        fStringIO = StringIO.StringIO('')  
+        fStringIO = BytesIO('')
         
         for Item in VfrUniOffsetList:
             if (Item[0].find("Strings") != -1):
diff --git a/BaseTools/Source/Python/GenFds/Fv.py 
b/BaseTools/Source/Python/GenFds/Fv.py
index 93bf05e40667..31ae60396556 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 *
 
 import Ffs
@@ -266,7 +266,7 @@ class FV (FvClassObject):
         #
         self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
                                    self.UiFvName + '.inf')
-        self.FvInfFile = StringIO.StringIO()
+        self.FvInfFile = BytesIO()
 
         #
         # Add [Options]
@@ -408,7 +408,7 @@ class FV (FvClassObject):
             #
             if TotalSize > 0:
                 FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, 
self.UiFvName + '.ext')
-                FvExtHeaderFile = StringIO.StringIO()
+                FvExtHeaderFile = BytesIO()
                 FvExtHeaderFile.write(Buffer)
                 Changed = SaveFileOnChange(FvExtHeaderFileName, 
FvExtHeaderFile.getvalue(), True)
                 FvExtHeaderFile.close()
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py 
b/BaseTools/Source/Python/GenFds/FvImageSection.py
index 77bf6a700623..b4f1f3340e99 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
@@ -98,7 +98,7 @@ class FvImageSection(FvImageSectionClassObject):
         # Generate Fv
         #
         if self.FvName is not None:
-            Buffer = StringIO.StringIO('')
+            Buffer = BytesIO('')
             Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)
             if Fv is not None:
                 self.Fv = Fv
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py 
b/BaseTools/Source/Python/GenFds/GenFds.py
index 1abebea5fdc6..04fc17906a57 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -28,7 +28,7 @@ from Workspace.WorkspaceDatabase import WorkspaceDatabase
 from Workspace.BuildClassObject import PcdClassObject
 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 *
@@ -543,13 +543,13 @@ class GenFds :
         if GenFds.OnlyGenerateThisFv is not None and 
GenFds.OnlyGenerateThisFv.upper() in 
GenFdsGlobalVariable.FdfParser.Profile.FvDict:
             FvObj = 
GenFdsGlobalVariable.FdfParser.Profile.FvDict[GenFds.OnlyGenerateThisFv.upper()]
             if FvObj is not None:
-                Buffer = StringIO.StringIO()
+                Buffer = BytesIO()
                 FvObj.AddToBuffer(Buffer)
                 Buffer.close()
                 return
         elif GenFds.OnlyGenerateThisFv is None:
             for FvObj in 
GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():
-                Buffer = StringIO.StringIO('')
+                Buffer = BytesIO('')
                 FvObj.AddToBuffer(Buffer)
                 Buffer.close()
         
@@ -695,7 +695,7 @@ class GenFds :
 
     def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):
         GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, 
"Guid.xref")
-        GuidXRefFile = StringIO.StringIO('')
+        GuidXRefFile = BytesIO('')
         GuidDict = {}
         ModuleList = []
         FileGuidList = []
diff --git a/BaseTools/Source/Python/GenFds/OptionRom.py 
b/BaseTools/Source/Python/GenFds/OptionRom.py
index b05841529940..755eb01da7e1 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
 
 import OptRomInfStatement
 from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -138,5 +137,3 @@ class OverrideAttribs:
         self.PciDeviceId = None
         self.PciRevision = None
         self.NeedCompress = None
-        
-        
\ No newline at end of file
diff --git a/BaseTools/Source/Python/GenFds/Region.py 
b/BaseTools/Source/Python/GenFds/Region.py
index a662692ad5d4..1b127345bcfb 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
@@ -128,7 +128,7 @@ class Region(RegionClassObject):
                         if self.FvAddress % FvAlignValue != 0:
                             EdkLogger.error("GenFds", GENFDS_ERROR,
                                             "FV (%s) is NOT %s Aligned!" % 
(FvObj.UiFvName, FvObj.FvAlignment))
-                        FvBuffer = StringIO.StringIO('')
+                        FvBuffer = BytesIO('')
                         FvBaseAddress = '0x%X' % self.FvAddress
                         BlockSize = None
                         BlockNum = None
@@ -136,7 +136,8 @@ class Region(RegionClassObject):
                         if Flag:
                             continue
 
-                        if FvBuffer.len > Size:
+                        FvBufferLen = len(FvBuffer.getvalue())
+                        if FvBufferLen > Size:
                             FvBuffer.close()
                             EdkLogger.error("GenFds", GENFDS_ERROR,
                                             "Size of FV (%s) is larger than 
Region Size 0x%X specified." % (RegionData, Size))
@@ -145,8 +146,8 @@ class Region(RegionClassObject):
                         #
                         Buffer.write(FvBuffer.getvalue())
                         FvBuffer.close()
-                        FvOffset = FvOffset + FvBuffer.len
-                        Size = Size - FvBuffer.len
+                        FvOffset = FvOffset + FvBufferLen
+                        Size = Size - FvBufferLen
                         continue
                     else:
                         EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is 
NOT described in FDF file!" % (RegionData))
diff --git a/BaseTools/Source/Python/Trim/Trim.py 
b/BaseTools/Source/Python/Trim/Trim.py
index d725e7ad2da0..e7f69db0beab 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
 
 from optparse import OptionParser
 from optparse import make_option
@@ -456,8 +456,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
     except:
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" 
%OutputFile, None)
 
-    # Use a instance of StringIO to cache data
-    fStringIO = StringIO.StringIO('')
+    # Use a instance of BytesIO to cache data
+    fStringIO = BytesIO('')
 
     for Item in VfrUniOffsetList:
         if (Item[0].find("Strings") != -1):
diff --git a/BaseTools/Source/Python/build/BuildReport.py 
b/BaseTools/Source/Python/build/BuildReport.py
index c9648a9299dd..897167cd11d6 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
@@ -2169,7 +2169,7 @@ class BuildReport(object):
     def GenerateReport(self, BuildDuration, AutoGenTime, MakeTime, GenFdsTime):
         if self.ReportFile:
             try:
-                File = StringIO('')
+                File = BytesIO('')
                 for (Wa, MaList) in self.ReportList:
                     PlatformReport(Wa, MaList, 
self.ReportType).GenerateReport(File, BuildDuration, AutoGenTime, MakeTime, 
GenFdsTime, self.ReportType)
                 Content = FileLinesSplit(File.getvalue(), gLineMaxLength)
diff --git a/BaseTools/Source/Python/build/build.py 
b/BaseTools/Source/Python/build/build.py
index bf1f853d56be..08e81016de8b 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
@@ -1782,7 +1782,7 @@ class Build():
                             if not Ma.IsLibrary:
                                 ModuleList[Ma.Guid.upper()] = Ma
 
-                    MapBuffer = StringIO('')
+                    MapBuffer = BytesIO('')
                     if self.LoadFixAddress != 0:
                         #
                         # Rebase module to the preferred memory address before 
GenFds
@@ -1940,7 +1940,7 @@ class Build():
                             if not Ma.IsLibrary:
                                 ModuleList[Ma.Guid.upper()] = Ma
 
-                    MapBuffer = StringIO('')
+                    MapBuffer = BytesIO('')
                     if self.LoadFixAddress != 0:
                         #
                         # Rebase module to the preferred memory address before 
GenFds
@@ -2127,7 +2127,7 @@ class Build():
                     #
                     # Rebase module to the preferred memory address before 
GenFds
                     #
-                    MapBuffer = StringIO('')
+                    MapBuffer = BytesIO('')
                     if self.LoadFixAddress != 0:
                         self._CollectModuleMapBuffer(MapBuffer, ModuleList)
 
-- 
2.17.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to