[edk2-devel] [PATCH 1/2] BaseTools: fix ucs-2 lookup on python 3.9

Cole posted 2 patches 5 years, 6 months ago
[edk2-devel] [PATCH 1/2] BaseTools: fix ucs-2 lookup on python 3.9
Posted by Cole 5 years, 6 months ago
python3.9 changed/fixed codec.register behavior to always replace
hyphen with underscore for passed in codec names:

  https://bugs.python.org/issue37751

So the custom Ucs2Search needs to be adapted to handle 'ucs_2' in
addition to existing 'ucs-2' for back compat.

This fixes test failures on python3.9, example:

======================================================================
FAIL: testUtf16InUniFile (CheckUnicodeSourceFiles.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/edk2-edk2-stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line 375, in PreProcess
    FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path))
  File "/builddir/build/BUILD/edk2-edk2-stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line 303, in OpenUniFile
    UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding)
  File "/builddir/build/BUILD/edk2-edk2-stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line 312, in VerifyUcs2Data
    Ucs2Info = codecs.lookup('ucs-2')
LookupError: unknown encoding: ucs-2

Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
 BaseTools/Source/Python/AutoGen/UniClassObject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py
index b2895f7e5c..883c2356e0 100644
--- a/BaseTools/Source/Python/AutoGen/UniClassObject.py
+++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py
@@ -152,7 +152,7 @@ class Ucs2Codec(codecs.Codec):
 

 TheUcs2Codec = Ucs2Codec()

 def Ucs2Search(name):

-    if name == 'ucs-2':

+    if name in ['ucs-2', 'ucs_2']:

         return codecs.CodecInfo(

             name=name,

             encode=TheUcs2Codec.encode,

-- 
2.26.2


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64002): https://edk2.groups.io/g/devel/message/64002
Mute This Topic: https://groups.io/mt/76131665/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 1/2] BaseTools: fix ucs-2 lookup on python 3.9
Posted by Yuwei Chen 5 years, 5 months ago
Reviewed-by: Yuwei Chen<yuwei.chen@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Cole
> Sent: Wednesday, August 12, 2020 1:28 AM
> To: devel@edk2.groups.io
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming
> <liming.gao@intel.com>; Cole Robinson <crobinso@redhat.com>
> Subject: [edk2-devel] [PATCH 1/2] BaseTools: fix ucs-2 lookup on python 3.9
> 
> python3.9 changed/fixed codec.register behavior to always replace hyphen
> with underscore for passed in codec names:
> 
>   https://bugs.python.org/issue37751
> 
> So the custom Ucs2Search needs to be adapted to handle 'ucs_2' in addition
> to existing 'ucs-2' for back compat.
> 
> This fixes test failures on python3.9, example:
> 
> ==========================================================
> ============
> FAIL: testUtf16InUniFile (CheckUnicodeSourceFiles.Tests)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/builddir/build/BUILD/edk2-edk2-
> stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line
> 375, in PreProcess
>     FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path))
>   File "/builddir/build/BUILD/edk2-edk2-
> stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line
> 303, in OpenUniFile
>     UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding)
>   File "/builddir/build/BUILD/edk2-edk2-
> stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line
> 312, in VerifyUcs2Data
>     Ucs2Info = codecs.lookup('ucs-2')
> LookupError: unknown encoding: ucs-2
> 
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
>  BaseTools/Source/Python/AutoGen/UniClassObject.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py
> b/BaseTools/Source/Python/AutoGen/UniClassObject.py
> index b2895f7e5c..883c2356e0 100644
> --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py
> +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py
> @@ -152,7 +152,7 @@ class Ucs2Codec(codecs.Codec):
> 
>  TheUcs2Codec = Ucs2Codec()
>  def Ucs2Search(name):
> -    if name == 'ucs-2':
> +    if name in ['ucs-2', 'ucs_2']:
>          return codecs.CodecInfo(
>              name=name,
>              encode=TheUcs2Codec.encode,
> --
> 2.26.2
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64131): https://edk2.groups.io/g/devel/message/64131
Mute This Topic: https://groups.io/mt/76131665/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 1/2] BaseTools: fix ucs-2 lookup on python 3.9
Posted by Bob Feng 5 years, 5 months ago
Reviewed-by: Bob Feng <bob.c.feng@intel.com>

-----Original Message-----
From: Cole Robinson <crobinso@redhat.com> 
Sent: Wednesday, August 12, 2020 1:28 AM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>; Cole Robinson <crobinso@redhat.com>
Subject: [PATCH 1/2] BaseTools: fix ucs-2 lookup on python 3.9

python3.9 changed/fixed codec.register behavior to always replace hyphen with underscore for passed in codec names:

  https://bugs.python.org/issue37751

So the custom Ucs2Search needs to be adapted to handle 'ucs_2' in addition to existing 'ucs-2' for back compat.

This fixes test failures on python3.9, example:

======================================================================
FAIL: testUtf16InUniFile (CheckUnicodeSourceFiles.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/edk2-edk2-stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line 375, in PreProcess
    FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path))
  File "/builddir/build/BUILD/edk2-edk2-stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line 303, in OpenUniFile
    UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding)
  File "/builddir/build/BUILD/edk2-edk2-stable202002/BaseTools/Source/Python/AutoGen/UniClassObject.py", line 312, in VerifyUcs2Data
    Ucs2Info = codecs.lookup('ucs-2')
LookupError: unknown encoding: ucs-2

Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
 BaseTools/Source/Python/AutoGen/UniClassObject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py
index b2895f7e5c..883c2356e0 100644
--- a/BaseTools/Source/Python/AutoGen/UniClassObject.py
+++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py
@@ -152,7 +152,7 @@ class Ucs2Codec(codecs.Codec):
  TheUcs2Codec = Ucs2Codec() def Ucs2Search(name):-    if name == 'ucs-2':+    if name in ['ucs-2', 'ucs_2']:         return codecs.CodecInfo(             name=name,             encode=TheUcs2Codec.encode,-- 
2.26.2


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64267): https://edk2.groups.io/g/devel/message/64267
Mute This Topic: https://groups.io/mt/76131665/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-