From d943b0c339fe3d35ffdf9f580ccb7a55915c6854 Mon Sep 17 00:00:00 2001 From: "Feng, Bob C" Date: Wed, 23 Jan 2019 10:16:00 +0800 Subject: BaseTools: Handle the bytes and str difference Deal with bytes and str is different, remove the unicode(), correct open file parameter. Using utcfromtimestamp instead of fromtimestamp. Cc: Bob Feng Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan Tested-by: Laszlo Ersek Tested-by: Ard Biesheuvel Reviewed-by: Liming Gao Reviewed-by: Bob Feng --- BaseTools/Source/Python/Trim/Trim.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'BaseTools/Source/Python/Trim/Trim.py') diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py index 51010bf326..428bf0d681 100644 --- a/BaseTools/Source/Python/Trim/Trim.py +++ b/BaseTools/Source/Python/Trim/Trim.py @@ -245,7 +245,7 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong): # save to file try: - f = open (Target, 'wb') + f = open (Target, 'w') except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target) f.writelines(NewLines) @@ -458,7 +458,7 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None) # Use a instance of BytesIO to cache data - fStringIO = BytesIO('') + fStringIO = BytesIO() for Item in VfrUniOffsetList: if (Item[0].find("Strings") != -1): @@ -467,9 +467,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): # GUID + Offset # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } } # - UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66] - UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid] - fStringIO.write(''.join(UniGuid)) + UniGuid = b'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f' + fStringIO.write(UniGuid) UniValue = pack ('Q', int (Item[1], 16)) fStringIO.write (UniValue) else: @@ -478,9 +477,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile): # GUID + Offset # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }; # - VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2] - VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid] - fStringIO.write(''.join(VfrGuid)) + VfrGuid = b'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2' + fStringIO.write(VfrGuid) type (Item[1]) VfrValue = pack ('Q', int (Item[1], 16)) fStringIO.write (VfrValue) @@ -562,7 +560,7 @@ def TrimEdkSourceCode(Source, Target): CreateDirectory(os.path.dirname(Target)) try: - f = open (Source, 'rb') + f = open (Source, 'r') except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source) # read whole file @@ -581,7 +579,7 @@ def TrimEdkSourceCode(Source, Target): return try: - f = open (Target, 'wb') + f = open (Target, 'w') except: EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target) f.write(NewLines) -- cgit v1.2.3