From 86e6cf98a8493574878286522078050ac4dd505d Mon Sep 17 00:00:00 2001 From: Yunhua Feng Date: Thu, 11 Oct 2018 11:20:59 +0800 Subject: BaseTools: Handle the bytes and str difference Deal with bytes and str is different, remove the unicode() Using utcfromtimestamp instead of fromtimestamp. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Reviewed-by: Liming Gao --- BaseTools/Source/Python/Common/Misc.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'BaseTools/Source/Python/Common/Misc.py') diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 1d62a8b56b..2253b67af6 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -454,9 +454,6 @@ def RemoveDirectory(Directory, Recursively=False): # @retval False If the file content is the same # def SaveFileOnChange(File, Content, IsBinaryFile=True): - if not IsBinaryFile: - Content = Content.replace("\n", os.linesep) - if os.path.exists(File): try: if isinstance(Content, bytes): @@ -1308,7 +1305,7 @@ def ParseDevPathValue (Value): if err: raise BadExpression("DevicePath: %s" % str(err)) Size = len(out.split()) - out = ','.join(out.split()) + out = ','.join(out.decode(encoding='utf-8', errors='ignore').split()) return '{' + out + '}', Size def ParseFieldValue (Value): @@ -1347,7 +1344,7 @@ def ParseFieldValue (Value): if Value[0] == '"' and Value[-1] == '"': Value = Value[1:-1] try: - Value = "'" + uuid.UUID(Value).get_bytes_le() + "'" + Value = "{" + ','.join([str(i) for i in uuid.UUID(Value).bytes_le]) + "}" except ValueError as Message: raise BadExpression(Message) Value, Size = ParseFieldValue(Value) @@ -1871,7 +1868,7 @@ class PeImageClass(): ByteArray = array.array('B') ByteArray.fromfile(PeObject, 4) # PE signature should be 'PE\0\0' - if ByteArray.tostring() != 'PE\0\0': + if ByteArray.tostring() != b'PE\0\0': self.ErrorInfo = self.FileName + ' has no valid PE signature PE00' return -- cgit v1.2.3