diff --git a/BaseTools/Plugin/CodeQL/analyze/globber.py b/BaseTools/Plugin/CodeQL/analyze/globber.py index 5d45abaa1f..db8cda595e 100644 --- a/BaseTools/Plugin/CodeQL/analyze/globber.py +++ b/BaseTools/Plugin/CodeQL/analyze/globber.py @@ -34,7 +34,7 @@ import re _double_star_after_invalid_regex = re.compile(r'[^/\\]\*\*') -_double_star_first_before_invalid_regex = re.compile('^\\*\\*[^/]') +_double_star_first_before_invalid_regex = re.compile(r'^\\*\\*[^/]') _double_star_middle_before_invalid_regex = re.compile(r'[^\\]\*\*[^/]') diff --git a/BaseTools/Scripts/ConvertFceToStructurePcd.py b/BaseTools/Scripts/ConvertFceToStructurePcd.py index 9e7fe58768..4c281e9173 100644 --- a/BaseTools/Scripts/ConvertFceToStructurePcd.py +++ b/BaseTools/Scripts/ConvertFceToStructurePcd.py @@ -89,12 +89,12 @@ class parser_lst(object): return structs_file def struct(self):#struct:{offset:name} - unit_num = re.compile('(\d+)') - offset1_re = re.compile('(\d+)\[') - pcdname_num_re = re.compile('\w+\[(\S+)\]') - pcdname_re = re.compile('\](.*)\<') - pcdname2_re = re.compile('(\w+)\[') - uint_re = re.compile('\<(\S+)\>') + unit_num = re.compile(r'(\d+)') + offset1_re = re.compile(r'(\d+)\[') + pcdname_num_re = re.compile(r'\w+\[(\S+)\]') + pcdname_re = re.compile(r'\](.*)\<') + pcdname2_re = re.compile(r'(\w+)\[') + uint_re = re.compile(r'\<(\S+)\>') name_format = re.compile(r'(?= 3: HaveQuotedMacroFlag = True diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py index fd8065fab5..b6e407406b 100644 --- a/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py @@ -611,10 +611,10 @@ def ValidatePcdValueOnDatumType(Value, Type): elif Type == 'UINT8' or Type == 'UINT16' or Type == 'UINT32' or Type == 'UINT64': - ReIsValidUint8z = re.compile('^0[x|X][a-fA-F0-9]{2}$') - ReIsValidUint16z = re.compile('^0[x|X][a-fA-F0-9]{4}$') - ReIsValidUint32z = re.compile('^0[x|X][a-fA-F0-9]{8}$') - ReIsValidUint64z = re.compile('^0[x|X][a-fA-F0-9]{16}$') + ReIsValidUint8z = re.compile(r'^0[x|X][a-fA-F0-9]{2}$') + ReIsValidUint16z = re.compile(r'^0[x|X][a-fA-F0-9]{4}$') + ReIsValidUint32z = re.compile(r'^0[x|X][a-fA-F0-9]{8}$') + ReIsValidUint64z = re.compile(r'^0[x|X][a-fA-F0-9]{16}$') if not ReIsValidUint8z.match(Value) and Type == 'UINT8': return False diff --git a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py index 27990467d1..98ccc8f7a4 100644 --- a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py +++ b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py @@ -25,10 +25,10 @@ from Library.ExpressionValidate import IsValidStringTest from Library.Misc import CheckGuidRegFormat TOOL_NAME = 'DecParser' -VERSION_PATTERN = '[0-9]+(\.[0-9]+)?' -CVAR_PATTERN = '[_a-zA-Z][a-zA-Z0-9_]*' -PCD_TOKEN_PATTERN = '(0[xX]0*[a-fA-F0-9]{1,8})|([0-9]+)' -MACRO_PATTERN = '[A-Z][_A-Z0-9]*' +VERSION_PATTERN = r'[0-9]+(\.[0-9]+)?' +CVAR_PATTERN = r'[_a-zA-Z][a-zA-Z0-9_]*' +PCD_TOKEN_PATTERN = r'(0[xX]0*[a-fA-F0-9]{1,8})|([0-9]+)' +MACRO_PATTERN = r'[A-Z][_A-Z0-9]*' ## FileContent # Class to hold DEC file information diff --git a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py index 992b609120..9480a5e168 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py +++ b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py @@ -53,12 +53,12 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo, CurrentInfFileName): # # To deal with library instance specified by GUID and version # - RegFormatGuidPattern = re.compile("\s*([0-9a-fA-F]){8}-" - "([0-9a-fA-F]){4}-" - "([0-9a-fA-F]){4}-" - "([0-9a-fA-F]){4}-" - "([0-9a-fA-F]){12}\s*") - VersionPattern = re.compile('[\t\s]*\d+(\.\d+)?[\t\s]*') + RegFormatGuidPattern = re.compile(r"\s*([0-9a-fA-F]){8}-" + r"([0-9a-fA-F]){4}-" + r"([0-9a-fA-F]){4}-" + r"([0-9a-fA-F]){4}-" + r"([0-9a-fA-F]){12}\s*") + VersionPattern = re.compile(r'[\t\s]*\d+(\.\d+)?[\t\s]*') GuidMatchedObj = RegFormatGuidPattern.search(String) if String.upper().startswith('GUID') and GuidMatchedObj and 'Version' in String: @@ -75,8 +75,8 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo, CurrentInfFileName): FileLinesList = GetFileLineContent(String, WorkSpace, LineNo, OriginalString) - ReFindFileGuidPattern = re.compile("^\s*FILE_GUID\s*=.*$") - ReFindVerStringPattern = re.compile("^\s*VERSION_STRING\s*=.*$") + ReFindFileGuidPattern = re.compile(r"^\s*FILE_GUID\s*=.*$") + ReFindVerStringPattern = re.compile(r"^\s*VERSION_STRING\s*=.*$") for Line in FileLinesList: if ReFindFileGuidPattern.match(Line): @@ -106,8 +106,8 @@ def GetPackageListInfo(FileNameString, WorkSpace, LineNo): FileLinesList = GetFileLineContent(FileNameString, WorkSpace, LineNo, '') - RePackageHeader = re.compile('^\s*\[Packages.*\].*$') - ReDefineHeader = re.compile('^\s*\[Defines].*$') + RePackageHeader = re.compile(r'^\s*\[Packages.*\].*$') + ReDefineHeader = re.compile(r'^\s*\[Defines].*$') PackageHederFlag = False DefineHeaderFlag = False @@ -255,8 +255,8 @@ def GetGuidVerFormLibInstance(Guid, Version, WorkSpace, CurrentInfFileName): FileLinesList = InfFileObj.readlines() FileLinesList = ProcessLineExtender(FileLinesList) - ReFindFileGuidPattern = re.compile("^\s*FILE_GUID\s*=.*$") - ReFindVerStringPattern = re.compile("^\s*VERSION_STRING\s*=.*$") + ReFindFileGuidPattern = re.compile(r"^\s*FILE_GUID\s*=.*$") + ReFindVerStringPattern = re.compile(r"^\s*VERSION_STRING\s*=.*$") for Line in FileLinesList: if ReFindFileGuidPattern.match(Line): diff --git a/BaseTools/Source/Python/UPT/Parser/InfDefineSectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfDefineSectionParser.py index a63e40e617..9edcc2cb3f 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfDefineSectionParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfDefineSectionParser.py @@ -40,7 +40,7 @@ def GetValidateArchList(LineContent): TempArch = GetSplitValueList(TempArch, '(', 1)[0] - ArchList = re.split('\s+', TempArch) + ArchList = re.split(r'\s+', TempArch) NewArchList = [] for Arch in ArchList: if IsValidArch(Arch): diff --git a/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py b/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py index d01ae9aa02..eb768b9a12 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py +++ b/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py @@ -109,7 +109,7 @@ def InfExpandMacro(Content, LineInfo, GlobalMacros=None, SectionMacros=None, Fla return Content else: for Macro in MacroUsed: - gQuotedMacro = re.compile(".*\".*\$\(%s\).*\".*"%(Macro)) + gQuotedMacro = re.compile(r".*\".*\$\(%s\).*\".*"%(Macro)) if not gQuotedMacro.match(Content): # # Still have MACROs can't be expanded. @@ -130,8 +130,8 @@ def IsBinaryInf(FileLineList): if not FileLineList: return False - ReIsSourcesSection = re.compile("^\s*\[Sources.*\]\s.*$", re.IGNORECASE) - ReIsBinarySection = re.compile("^\s*\[Binaries.*\]\s.*$", re.IGNORECASE) + ReIsSourcesSection = re.compile(r"^\s*\[Sources.*\]\s.*$", re.IGNORECASE) + ReIsBinarySection = re.compile(r"^\s*\[Binaries.*\]\s.*$", re.IGNORECASE) BinarySectionFoundFlag = False for Line in FileLineList: @@ -155,7 +155,7 @@ def IsBinaryInf(FileLineList): # @return Flag # def IsLibInstanceInfo(String): - ReIsLibInstance = re.compile("^\s*##\s*@LIB_INSTANCES\s*$") + ReIsLibInstance = re.compile(r"^\s*##\s*@LIB_INSTANCES\s*$") if ReIsLibInstance.match(String): return True else: @@ -171,7 +171,7 @@ def IsLibInstanceInfo(String): # @return Flag # def IsAsBuildOptionInfo(String): - ReIsAsBuildInstance = re.compile("^\s*##\s*@AsBuilt\s*$") + ReIsAsBuildInstance = re.compile(r"^\s*##\s*@AsBuilt\s*$") if ReIsAsBuildInstance.match(String): return True else: diff --git a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py index da92fe5d3e..b1f8135bc7 100644 --- a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py +++ b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py @@ -747,12 +747,12 @@ class DecPomAlignment(PackageObject): # # deal with "NOT EQ", "NOT LT", "NOT GT", "NOT LE", "NOT GE", "NOT NOT" # - NOTNOT_Pattern = '[\t\s]*NOT[\t\s]+NOT[\t\s]*' - NOTGE_Pattern = '[\t\s]*NOT[\t\s]+GE[\t\s]*' - NOTLE_Pattern = '[\t\s]*NOT[\t\s]+LE[\t\s]*' - NOTGT_Pattern = '[\t\s]*NOT[\t\s]+GT[\t\s]*' - NOTLT_Pattern = '[\t\s]*NOT[\t\s]+LT[\t\s]*' - NOTEQ_Pattern = '[\t\s]*NOT[\t\s]+EQ[\t\s]*' + NOTNOT_Pattern = r'[\t\s]*NOT[\t\s]+NOT[\t\s]*' + NOTGE_Pattern = r'[\t\s]*NOT[\t\s]+GE[\t\s]*' + NOTLE_Pattern = r'[\t\s]*NOT[\t\s]+LE[\t\s]*' + NOTGT_Pattern = r'[\t\s]*NOT[\t\s]+GT[\t\s]*' + NOTLT_Pattern = r'[\t\s]*NOT[\t\s]+LT[\t\s]*' + NOTEQ_Pattern = r'[\t\s]*NOT[\t\s]+EQ[\t\s]*' ReplaceValue = re.compile(NOTNOT_Pattern).sub('', ReplaceValue) ReplaceValue = re.compile(NOTLT_Pattern).sub('x >= ', ReplaceValue) ReplaceValue = re.compile(NOTGT_Pattern).sub('x <= ', ReplaceValue) @@ -785,7 +785,7 @@ class DecPomAlignment(PackageObject): if ReplaceValue.find('!') >= 0 and ReplaceValue[ReplaceValue.index('!') + 1] != '=': ReplaceValue = ReplaceValue.replace('!', ' not ') if '.' in ReplaceValue: - Pattern = '[a-zA-Z0-9]{1,}\.[a-zA-Z0-9]{1,}' + Pattern = r'[a-zA-Z0-9]{1,}\.[a-zA-Z0-9]{1,}' MatchedList = re.findall(Pattern, ReplaceValue) for MatchedItem in MatchedList: if MatchedItem not in self.PcdDefaultValueDict: @@ -814,7 +814,7 @@ class DecPomAlignment(PackageObject): # # Delete the 'L' prefix of a quoted string, this operation is for eval() # - QUOTED_PATTERN = '[\t\s]*L?"[^"]*"' + QUOTED_PATTERN = r'[\t\s]*L?"[^"]*"' QuotedMatchedObj = re.search(QUOTED_PATTERN, Expression) if QuotedMatchedObj: MatchedStr = QuotedMatchedObj.group().strip() @@ -847,7 +847,7 @@ class DecPomAlignment(PackageObject): # # Delete the 'L' prefix of a quoted string, this operation is for eval() # - QUOTED_PATTERN = '[\t\s]*L?"[^"]*"' + QUOTED_PATTERN = r'[\t\s]*L?"[^"]*"' QuotedMatchedObj = re.search(QUOTED_PATTERN, DefaultValue) if QuotedMatchedObj: MatchedStr = QuotedMatchedObj.group().strip() diff --git a/BaseTools/Source/Python/UPT/Xml/IniToXml.py b/BaseTools/Source/Python/UPT/Xml/IniToXml.py index 3dc4001313..2c01c97fa5 100644 --- a/BaseTools/Source/Python/UPT/Xml/IniToXml.py +++ b/BaseTools/Source/Python/UPT/Xml/IniToXml.py @@ -200,9 +200,9 @@ def ValidateRegValues(Key, Value): ('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}' '-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}', ST.ERR_GUID_VALUE % Value), - 'Version' : ('[0-9]+(\.[0-9]+)?', ST.ERR_VERSION_VALUE % \ + 'Version' : (r'[0-9]+(\.[0-9]+)?', ST.ERR_VERSION_VALUE % \ (Key, Value)), - 'XmlSpecification' : ('1\.1', ST.ERR_VERSION_XMLSPEC % Value) + 'XmlSpecification' : (r'1\.1', ST.ERR_VERSION_XMLSPEC % Value) } if Key not in ValidateMap: return True, '' diff --git a/BaseTools/Source/Python/UPT/Xml/PcdXml.py b/BaseTools/Source/Python/UPT/Xml/PcdXml.py index bbcee45a01..ca95c820c9 100644 --- a/BaseTools/Source/Python/UPT/Xml/PcdXml.py +++ b/BaseTools/Source/Python/UPT/Xml/PcdXml.py @@ -100,11 +100,11 @@ class PcdErrorXml(object): def TransferValidRange2Expr(self, TokenSpaceGuidCName, CName, ValidRange): if self.Expression: pass - INT_RANGE_PATTERN1 = '[\t\s]*[0-9]+[\t\s]*-[\t\s]*[0-9]+' - INT_RANGE_PATTERN2 = '[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*' + INT_RANGE_PATTERN1 = r'[\t\s]*[0-9]+[\t\s]*-[\t\s]*[0-9]+' + INT_RANGE_PATTERN2 = r'[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*' HEX_RANGE_PATTERN1 = \ - '[\t\s]*0[xX][a-fA-F0-9]+[\t\s]*-[\t\s]*0[xX][a-fA-F0-9]+' - HEX_RANGE_PATTERN2 = '[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][a-fA-F0-9]+[\t\s]*' + r'[\t\s]*0[xX][a-fA-F0-9]+[\t\s]*-[\t\s]*0[xX][a-fA-F0-9]+' + HEX_RANGE_PATTERN2 = r'[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][a-fA-F0-9]+[\t\s]*' IntMatch1 = re.compile(INT_RANGE_PATTERN1) IntMatch2 = re.compile(INT_RANGE_PATTERN2) HexMatch1 = re.compile(HEX_RANGE_PATTERN1) @@ -158,18 +158,18 @@ class PcdErrorXml(object): pass PCD_PATTERN = \ - '[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*\.[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*' + r'[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*\.[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*' IntPattern1 = \ - '[\t\s]*\([\t\s]*'+PCD_PATTERN+'[\t\s]+GE[\t\s]+\d+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\ - PCD_PATTERN+'[\t\s]+LE[\t\s]+\d+[\t\s]*\)' + r'[\t\s]*\([\t\s]*'+PCD_PATTERN+r'[\t\s]+GE[\t\s]+\d+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\ + PCD_PATTERN+r'[\t\s]+LE[\t\s]+\d+[\t\s]*\)' IntPattern1 = IntPattern1.replace(' ', '') - IntPattern2 = '[\t\s]*'+PCD_PATTERN+'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*' + IntPattern2 = r'[\t\s]*'+PCD_PATTERN+r'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*' HexPattern1 = \ - '[\t\s]*\([\t\s]*'+PCD_PATTERN+'[\t\s]+GE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\ - PCD_PATTERN+'[\t\s]+LE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)' + r'[\t\s]*\([\t\s]*'+PCD_PATTERN+r'[\t\s]+GE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\ + PCD_PATTERN+r'[\t\s]+LE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)' HexPattern1 = HexPattern1.replace(' ', '') - HexPattern2 = '[\t\s]*'+PCD_PATTERN+'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][0-9a-zA-Z]+[\t\s]*' + HexPattern2 = r'[\t\s]*'+PCD_PATTERN+r'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][0-9a-zA-Z]+[\t\s]*' # # Do the Hex1 conversion @@ -180,7 +180,7 @@ class PcdErrorXml(object): # # To match items on both sides of '-' # - RangeItemList = re.compile('[\t\s]*0[xX][0-9a-fA-F]+[\t\s]*').findall(HexMatchedItem) + RangeItemList = re.compile(r'[\t\s]*0[xX][0-9a-fA-F]+[\t\s]*').findall(HexMatchedItem) if RangeItemList and len(RangeItemList) == 2: HexRangeDict[HexMatchedItem] = RangeItemList @@ -204,7 +204,7 @@ class PcdErrorXml(object): # # To match items on both sides of '-' # - RangeItemList = re.compile('[\t\s]*\d+[\t\s]*').findall(MatchedItem) + RangeItemList = re.compile(r'[\t\s]*\d+[\t\s]*').findall(MatchedItem) if RangeItemList and len(RangeItemList) == 2: IntRangeDict[MatchedItem] = RangeItemList diff --git a/BaseTools/Source/Python/UPT/Xml/XmlParser.py b/BaseTools/Source/Python/UPT/Xml/XmlParser.py index 8e22a280f6..f239588831 100644 --- a/BaseTools/Source/Python/UPT/Xml/XmlParser.py +++ b/BaseTools/Source/Python/UPT/Xml/XmlParser.py @@ -281,33 +281,33 @@ class DistributionPackageXml(object): # XmlContent = \ re.sub(r'[\s\r\n]*SupArchList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*COMMON' - '[\s\r\n]*"', '', XmlContent) + r'[\s\r\n]*"', '', XmlContent) XmlContent = \ re.sub(r'[\s\r\n]*SupArchList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*common' - '[\s\r\n]*"', '', XmlContent) + r'[\s\r\n]*"', '', XmlContent) # # Remove COMMON # XmlContent = \ re.sub(r'[\s\r\n]*[\s\r\n]*COMMON[\s\r\n]*' - '[\s\r\n]*', '', XmlContent) + r'[\s\r\n]*', '', XmlContent) # # Remove common # XmlContent = \ re.sub(r'[\s\r\n]*[\s\r\n]*' - 'common[\s\r\n]*[\s\r\n]*', '', XmlContent) + r'common[\s\r\n]*[\s\r\n]*', '', XmlContent) # # Remove SupModList="COMMON" or "common" # XmlContent = \ re.sub(r'[\s\r\n]*SupModList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*COMMON' - '[\s\r\n]*"', '', XmlContent) + r'[\s\r\n]*"', '', XmlContent) XmlContent = \ re.sub(r'[\s\r\n]*SupModList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*common' - '[\s\r\n]*"', '', XmlContent) + r'[\s\r\n]*"', '', XmlContent) return XmlContent