From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=zhijux.fan@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A7B9921959CB2 for ; Thu, 28 Mar 2019 22:54:56 -0700 (PDT) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2019 22:54:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,283,1549958400"; d="dat'59?scan'59,208,59";a="333093410" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 28 Mar 2019 22:54:56 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 28 Mar 2019 22:54:55 -0700 Received: from shsmsx108.ccr.corp.intel.com (10.239.4.97) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 28 Mar 2019 22:54:55 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.158]) by SHSMSX108.ccr.corp.intel.com ([169.254.8.57]) with mapi id 14.03.0415.000; Fri, 29 Mar 2019 13:53:41 +0800 From: "Fan, ZhijuX" To: "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Feng, Bob C" Thread-Topic: [edk2][PATCH] BaseTools:Coding problems caused by special characters Thread-Index: AdTl88E8RpeFh89hTUO6DNyBrOPPnQ== Date: Fri, 29 Mar 2019 05:53:40 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [PATCH] BaseTools:Coding problems caused by special characters X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2019 05:54:56 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1670 During BaseTools compiling under Chinese or Japanese language Windows, python exception occurring. UnicodeDecodeError: 'ascii' codec can't decode byte 0xbd in position 3528: ordinal not in range(128) Cc: Bob Feng Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/C/Makefiles/NmakeSubdirs.py | 2 +- BaseTools/Source/Python/Capsule/GenerateCapsule.py | 8 ++++= ---- BaseTools/Source/Python/Common/Misc.py | 2 +- BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py | 2 +- .../Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py | 6 +++-= -- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/BaseTools/Source/C/Makefiles/NmakeSubdirs.py b/BaseTools/Sourc= e/C/Makefiles/NmakeSubdirs.py index 29bb5dfa72..abcbea89a4 100644 --- a/BaseTools/Source/C/Makefiles/NmakeSubdirs.py +++ b/BaseTools/Source/C/Makefiles/NmakeSubdirs.py @@ -44,7 +44,7 @@ def RunCommand(WorkDir=3DNone, *Args, **kwargs): stdout, stderr =3D p.communicate() message =3D "" if stdout is not None: - message =3D stdout.decode() #for compatibility in python 2 and 3 + message =3D stdout.decode(encoding=3D'utf-8', errors=3D'ignore') #= for compatibility in python 2 and 3 =20 if p.returncode !=3D 0: raise RuntimeError("Error while execute command \'{0}\' in direcot= ry {1}\n{2}".format(" ".join(Args), WorkDir, message)) diff --git a/BaseTools/Source/Python/Capsule/GenerateCapsule.py b/BaseTools= /Source/Python/Capsule/GenerateCapsule.py index 7b08918857..5ce5daef68 100644 --- a/BaseTools/Source/Python/Capsule/GenerateCapsule.py +++ b/BaseTools/Source/Python/Capsule/GenerateCapsule.py @@ -94,7 +94,7 @@ def SignPayloadSignTool (Payload, ToolPath, PfxFile): =20 if Process.returncode !=3D 0: shutil.rmtree (TempDirectoryName) - print (Result[1].decode()) + print (Result[1].decode(encoding=3D'utf-8', errors=3D'ignore')) raise ValueError ('GenerateCapsule: error: signtool failed.') =20 # @@ -132,12 +132,12 @@ def SignPayloadOpenSsl (Payload, ToolPath, SignerPriv= ateCertFile, OtherPublicCer try: Process =3D subprocess.Popen (Command, stdin =3D subprocess.PIPE, = stdout =3D subprocess.PIPE, stderr =3D subprocess.PIPE, shell =3D True) Result =3D Process.communicate(input =3D Payload) - Signature =3D Result[0] + Signature =3D Result[0].decode(encoding=3D'utf-8', errors=3D'ignor= e') except: raise ValueError ('GenerateCapsule: error: can not run openssl.') =20 if Process.returncode !=3D 0: - print (Result[1].decode()) + print (Result[1].decode(encoding=3D'utf-8', errors=3D'ignore')) raise ValueError ('GenerateCapsule: error: openssl failed.') =20 return Signature @@ -186,7 +186,7 @@ def VerifyPayloadOpenSsl (Payload, CertData, ToolPath, = SignerPrivateCertFile, Ot =20 if Process.returncode !=3D 0: shutil.rmtree (TempDirectoryName) - print (Result[1].decode()) + print (Result[1].decode(encoding=3D'utf-8', errors=3D'ignore')) raise ValueError ('GenerateCapsule: error: openssl failed.') =20 shutil.rmtree (TempDirectoryName) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index c7daf5417c..47f8e45222 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1032,7 +1032,7 @@ def ParseFieldValue (Value): p.stderr.close() if err: raise BadExpression("DevicePath: %s" % str(err)) - out =3D out.decode() + out =3D out.decode(encoding=3D'utf-8', errors=3D'ignore') Size =3D len(out.split()) out =3D ','.join(out.split()) return '{' + out + '}', Size diff --git a/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py b/BaseTools/Sou= rce/Python/Pkcs7Sign/Pkcs7Sign.py index 003f052a90..706bf28e14 100644 --- a/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py +++ b/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py @@ -122,7 +122,7 @@ if __name__ =3D=3D '__main__': if Process.returncode !=3D 0: print('ERROR: Open SSL command not available. Please verify PATH or s= et OPENSSL_PATH') sys.exit(Process.returncode) - print(Version[0].decode()) + print(Version[0].decode(encoding=3D'utf-8', errors=3D'ignore')) =20 # # Read input file into a buffer and save input filename diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Generat= eKeys.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateK= eys.py index c0b661d03c..3cc14e3bb9 100644 --- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.p= y +++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.p= y @@ -84,7 +84,7 @@ if __name__ =3D=3D '__main__': if Process.returncode !=3D 0: print('ERROR: Open SSL command not available. Please verify PATH or s= et OPENSSL_PATH') sys.exit(Process.returncode) - print(Version[0].decode()) + print(Version[0].decode(encoding=3D'utf-8', errors=3D'ignore')) =20 args.PemFileName =3D [] =20 @@ -125,7 +125,7 @@ if __name__ =3D=3D '__main__': # Extract public key from private key into STDOUT # Process =3D subprocess.Popen('%s rsa -in %s -modulus -noout' % (OpenSs= lCommand, Item), stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.PIPE, shell= =3DTrue) - PublicKeyHexString =3D Process.communicate()[0].split(b'=3D')[1].strip= () + PublicKeyHexString =3D Process.communicate()[0].decode(encoding=3D'utf= -8', errors=3D'ignore').split(b'=3D')[1].strip() if Process.returncode !=3D 0: print('ERROR: Unable to extract public key from private key') sys.exit(Process.returncode) @@ -138,7 +138,7 @@ if __name__ =3D=3D '__main__': # Process =3D subprocess.Popen('%s dgst -sha256 -binary' % (OpenSslComma= nd), stdin=3Dsubprocess.PIPE, stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess= .PIPE, shell=3DTrue) Process.stdin.write (PublicKey) - PublicKeyHash =3D PublicKeyHash + Process.communicate()[0] + PublicKeyHash =3D PublicKeyHash + Process.communicate()[0].decode(enco= ding=3D'utf-8', errors=3D'ignore') if Process.returncode !=3D 0: print('ERROR: Unable to extract SHA 256 hash of public key') sys.exit(Process.returncode) --=20 2.14.1.windows.1