public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v1 1/1] BaseTools: Resolve invalid escape sequence
@ 2023-10-31  6:23 Joey Vagedes via groups.io
  2023-11-07 16:59 ` Rebecca Cran
  0 siblings, 1 reply; 2+ messages in thread
From: Joey Vagedes via groups.io @ 2023-10-31  6:23 UTC (permalink / raw)
  To: devel; +Cc: Rebecca Cran, Liming Gao, Bob Feng, Yuwei Chen

Resolves an invalid escape sequence in a regex string that occurs
because the string was not marked as a raw string, so backslash
characters create unexpected escape sequences.

This was brought to light due to Python 3.12 now detecting invalid
escape sequences and generates a warning. It is best practice to
always use raw strings for regex strings.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Joey Vagedes <joeyvagedes@gmail.com>
---
 BaseTools/Scripts/BinToPcd.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Scripts/BinToPcd.py b/BaseTools/Scripts/BinToPcd.py
index 460c08b7f7cd..43fc458b0426 100644
--- a/BaseTools/Scripts/BinToPcd.py
+++ b/BaseTools/Scripts/BinToPcd.py
@@ -10,13 +10,12 @@ BinToPcd
 '''
 from __future__ import print_function
 
-import sys
 import argparse
-import re
-import xdrlib
 import io
-import struct
 import math
+import re
+import struct
+import sys
 
 #
 # Globals for help information
@@ -38,13 +37,13 @@ if __name__ == '__main__':
         return Value
 
     def ValidatePcdName (Argument):
-        if re.split ('[a-zA-Z\_][a-zA-Z0-9\_]*\.[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
+        if re.split (r'[a-zA-Z\_][a-zA-Z0-9\_]*\.[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
             Message = '{Argument} is not in the form <PcdTokenSpaceGuidCName>.<PcdCName>'.format (Argument = Argument)
             raise argparse.ArgumentTypeError (Message)
         return Argument
 
     def ValidateGuidName (Argument):
-        if re.split ('[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
+        if re.split (r'[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
             Message = '{Argument} is not a valid GUID C name'.format (Argument = Argument)
             raise argparse.ArgumentTypeError (Message)
         return Argument
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110448): https://edk2.groups.io/g/devel/message/110448
Mute This Topic: https://groups.io/mt/102305837/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH v1 1/1] BaseTools: Resolve invalid escape sequence
  2023-10-31  6:23 [edk2-devel] [PATCH v1 1/1] BaseTools: Resolve invalid escape sequence Joey Vagedes via groups.io
@ 2023-11-07 16:59 ` Rebecca Cran
  0 siblings, 0 replies; 2+ messages in thread
From: Rebecca Cran @ 2023-11-07 16:59 UTC (permalink / raw)
  To: Joey Vagedes, devel; +Cc: Liming Gao, Bob Feng, Yuwei Chen

Reviewed-by: Rebecca Cran <rebecca@bsdio.com>


On 10/31/2023 12:23 AM, Joey Vagedes wrote:
> Resolves an invalid escape sequence in a regex string that occurs
> because the string was not marked as a raw string, so backslash
> characters create unexpected escape sequences.
>
> This was brought to light due to Python 3.12 now detecting invalid
> escape sequences and generates a warning. It is best practice to
> always use raw strings for regex strings.
>
> Cc: Rebecca Cran <rebecca@bsdio.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> Signed-off-by: Joey Vagedes <joeyvagedes@gmail.com>
> ---
>   BaseTools/Scripts/BinToPcd.py | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/BaseTools/Scripts/BinToPcd.py b/BaseTools/Scripts/BinToPcd.py
> index 460c08b7f7cd..43fc458b0426 100644
> --- a/BaseTools/Scripts/BinToPcd.py
> +++ b/BaseTools/Scripts/BinToPcd.py
> @@ -10,13 +10,12 @@ BinToPcd
>   '''
>
>   from __future__ import print_function
>
>   
>
> -import sys
>
>   import argparse
>
> -import re
>
> -import xdrlib
>
>   import io
>
> -import struct
>
>   import math
>
> +import re
>
> +import struct
>
> +import sys
>
>   
>
>   #
>
>   # Globals for help information
>
> @@ -38,13 +37,13 @@ if __name__ == '__main__':
>           return Value
>
>   
>
>       def ValidatePcdName (Argument):
>
> -        if re.split ('[a-zA-Z\_][a-zA-Z0-9\_]*\.[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
>
> +        if re.split (r'[a-zA-Z\_][a-zA-Z0-9\_]*\.[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
>
>               Message = '{Argument} is not in the form <PcdTokenSpaceGuidCName>.<PcdCName>'.format (Argument = Argument)
>
>               raise argparse.ArgumentTypeError (Message)
>
>           return Argument
>
>   
>
>       def ValidateGuidName (Argument):
>
> -        if re.split ('[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
>
> +        if re.split (r'[a-zA-Z\_][a-zA-Z0-9\_]*', Argument) != ['', '']:
>
>               Message = '{Argument} is not a valid GUID C name'.format (Argument = Argument)
>
>               raise argparse.ArgumentTypeError (Message)
>
>           return Argument
>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110866): https://edk2.groups.io/g/devel/message/110866
Mute This Topic: https://groups.io/mt/102305837/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-07 16:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-31  6:23 [edk2-devel] [PATCH v1 1/1] BaseTools: Resolve invalid escape sequence Joey Vagedes via groups.io
2023-11-07 16:59 ` Rebecca Cran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox