BaseTools: Resolve regex syntax warnings
Switches regex patterns to raw text to resolve python 3.12 syntax warnings in regards to invalid escape sequences, as is suggested by the re (regex) module in python. 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 <joey.vagedes@gmail.com> Reviewed-by: Rebecca Cran <rebecca@bsdio.com>
This commit is contained in:
committed by
mergify[bot]
parent
89705ad6c6
commit
9f0061a03b
@@ -41,8 +41,8 @@ ERR_EMPTY_EXPR = 'Empty expression is not allowed.'
|
||||
ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'
|
||||
|
||||
__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
|
||||
_ReLabel = re.compile('LABEL\((\w+)\)')
|
||||
_ReOffset = re.compile('OFFSET_OF\((\w+)\)')
|
||||
_ReLabel = re.compile(r'LABEL\((\w+)\)')
|
||||
_ReOffset = re.compile(r'OFFSET_OF\((\w+)\)')
|
||||
PcdPattern = re.compile(r'^[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
|
||||
|
||||
## SplitString
|
||||
@@ -242,10 +242,10 @@ class ValueExpression(BaseExpression):
|
||||
|
||||
|
||||
SymbolPattern = re.compile("("
|
||||
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
|
||||
"&&|\|\||!(?!=)|"
|
||||
"(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"
|
||||
"(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"
|
||||
r"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
|
||||
r"&&|\|\||!(?!=)|"
|
||||
r"(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"
|
||||
r"(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"
|
||||
")")
|
||||
|
||||
@staticmethod
|
||||
@@ -737,7 +737,7 @@ class ValueExpression(BaseExpression):
|
||||
self._Token = "'" + UStr + "'"
|
||||
return self._Token
|
||||
elif Expr.startswith('UINT'):
|
||||
Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
|
||||
Re = re.compile(r'(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
|
||||
try:
|
||||
RetValue = Re.search(Expr).group(1)
|
||||
except:
|
||||
@@ -975,7 +975,7 @@ class ValueExpressionEx(ValueExpression):
|
||||
TokenSpaceGuidName = ''
|
||||
if Item.startswith(TAB_GUID) and Item.endswith(')'):
|
||||
try:
|
||||
TokenSpaceGuidName = re.search('GUID\((\w+)\)', Item).group(1)
|
||||
TokenSpaceGuidName = re.search(r'GUID\((\w+)\)', Item).group(1)
|
||||
except:
|
||||
pass
|
||||
if TokenSpaceGuidName and TokenSpaceGuidName in self._Symb:
|
||||
|
@@ -33,10 +33,10 @@ gDefaultStores = []
|
||||
gGuidDict = {}
|
||||
|
||||
# definition for a MACRO name. used to create regular expressions below.
|
||||
_MacroNamePattern = "[A-Z][A-Z0-9_]*"
|
||||
_MacroNamePattern = r"[A-Z][A-Z0-9_]*"
|
||||
|
||||
## Regular expression for matching macro used in DSC/DEC/INF file inclusion
|
||||
gMacroRefPattern = re.compile("\$\(({})\)".format(_MacroNamePattern), re.UNICODE)
|
||||
gMacroRefPattern = re.compile(r"\$\(({})\)".format(_MacroNamePattern), re.UNICODE)
|
||||
gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+")
|
||||
gMacroNamePattern = re.compile("^{}$".format(_MacroNamePattern))
|
||||
|
||||
|
@@ -41,16 +41,16 @@ from CommonDataClass.Exceptions import BadExpression
|
||||
from Common.caching import cached_property
|
||||
import struct
|
||||
|
||||
ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")
|
||||
ArrayIndex = re.compile(r"\[\s*[0-9a-fA-FxX]*\s*\]")
|
||||
## Regular expression used to find out place holders in string template
|
||||
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
||||
gPlaceholderPattern = re.compile(r"\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
||||
|
||||
## regular expressions for map file processing
|
||||
startPatternGeneral = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
|
||||
addressPatternGeneral = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
|
||||
valuePatternGcc = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
|
||||
pcdPatternGcc = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
|
||||
secReGeneral = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
|
||||
startPatternGeneral = re.compile(r"^Start[' ']+Length[' ']+Name[' ']+Class")
|
||||
addressPatternGeneral = re.compile(r"^Address[' ']+Publics by Value[' ']+Rva\+Base")
|
||||
valuePatternGcc = re.compile(r'^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
|
||||
pcdPatternGcc = re.compile(r'^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
|
||||
secReGeneral = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
|
||||
|
||||
StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$')
|
||||
|
||||
@@ -82,7 +82,7 @@ def GetVariableOffset(mapfilepath, efifilepath, varnames):
|
||||
|
||||
if len(lines) == 0: return None
|
||||
firstline = lines[0].strip()
|
||||
if re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
|
||||
if re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
|
||||
return _parseForXcodeAndClang9(lines, efifilepath, varnames)
|
||||
if (firstline.startswith("Archive member included ") and
|
||||
firstline.endswith(" file (symbol)")):
|
||||
@@ -96,7 +96,7 @@ def _parseForXcodeAndClang9(lines, efifilepath, varnames):
|
||||
ret = []
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if status == 0 and (re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
|
||||
if status == 0 and (re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
|
||||
or line == "# Symbols:"):
|
||||
status = 1
|
||||
continue
|
||||
@@ -104,7 +104,7 @@ def _parseForXcodeAndClang9(lines, efifilepath, varnames):
|
||||
for varname in varnames:
|
||||
if varname in line:
|
||||
# cannot pregenerate this RegEx since it uses varname from varnames.
|
||||
m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
|
||||
m = re.match(r'^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
|
||||
if m is not None:
|
||||
ret.append((varname, m.group(1)))
|
||||
return ret
|
||||
@@ -170,7 +170,7 @@ def _parseGeneral(lines, efifilepath, varnames):
|
||||
status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table
|
||||
secs = [] # key = section name
|
||||
varoffset = []
|
||||
symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$-]+) +([\da-fA-F]+)', re.UNICODE)
|
||||
symRe = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$-]+) +([\da-fA-F]+)', re.UNICODE)
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
@@ -1926,4 +1926,4 @@ def CopyDict(ori_dict):
|
||||
# Remove the c/c++ comments: // and /* */
|
||||
#
|
||||
def RemoveCComments(ctext):
|
||||
return re.sub('//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S)
|
||||
return re.sub(r'//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S)
|
||||
|
@@ -30,9 +30,9 @@ from .DataType import TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG,\
|
||||
##
|
||||
# Static variables used for pattern
|
||||
#
|
||||
gMacroRefPattern = re.compile('(DEF\([^\(\)]+\))')
|
||||
gEnvRefPattern = re.compile('(ENV\([^\(\)]+\))')
|
||||
gMacroDefPattern = re.compile("DEFINE\s+([^\s]+)")
|
||||
gMacroRefPattern = re.compile(r'(DEF\([^\(\)]+\))')
|
||||
gEnvRefPattern = re.compile(r'(ENV\([^\(\)]+\))')
|
||||
gMacroDefPattern = re.compile(r"DEFINE\s+([^\s]+)")
|
||||
gDefaultToolsDefFile = "tools_def.txt"
|
||||
|
||||
## ToolDefClassObject
|
||||
|
Reference in New Issue
Block a user