From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 04/11] BaseTools: remove repeated calls to startswith/endswith
Date: Wed, 20 Jun 2018 14:08:10 -0700 [thread overview]
Message-ID: <5271b48db2aa208f6862bffcbbe347b7cbaf0546.1529528784.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1529528783.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1529528783.git.jaben.carsey@intel.com>
As both can take a tuple, use that instead of calling repeatedly.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
BaseTools/Source/Python/AutoGen/GenMake.py | 2 +-
BaseTools/Source/Python/AutoGen/StrGather.py | 2 +-
BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py | 2 +-
BaseTools/Source/Python/BPDG/GenVpd.py | 2 +-
BaseTools/Source/Python/Common/Expression.py | 13 ++++++-------
BaseTools/Source/Python/Common/Misc.py | 6 +++---
BaseTools/Source/Python/Ecc/Check.py | 6 +++---
BaseTools/Source/Python/Ecc/CodeFragmentCollector.py | 4 ++--
BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py | 2 +-
BaseTools/Source/Python/Ecc/c.py | 14 +++++++-------
BaseTools/Source/Python/Eot/CodeFragmentCollector.py | 9 +++------
BaseTools/Source/Python/GenFds/FdfParser.py | 10 ++++------
BaseTools/Source/Python/Trim/Trim.py | 2 +-
BaseTools/Source/Python/Workspace/BuildClassObject.py | 2 +-
BaseTools/Source/Python/Workspace/DscBuildData.py | 2 +-
BaseTools/Source/Python/Workspace/InfBuildData.py | 2 +-
BaseTools/Source/Python/build/BuildReport.py | 2 +-
17 files changed, 38 insertions(+), 44 deletions(-)
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 1227447741f9..f19c1bfdaff1 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -741,7 +741,7 @@ cleanlib:
index = index + 1
if CmdName == 'Trim':
SecDepsFileList.append(os.path.join('$(DEBUG_DIR)', os.path.basename(OutputFile).replace('offset', 'efi')))
- if OutputFile.endswith('.ui') or OutputFile.endswith('.ver'):
+ if OutputFile.endswith(('.ui','.ver')):
SecDepsFileList.append(os.path.join('$(MODULE_DIR)','$(MODULE_FILE)'))
self.FfsOutputFileList.append((OutputFile, ' '.join(SecDepsFileList), SecCmdStr))
if len(SecDepsFileList) > 0:
diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py
index ce8866f480d5..d41bcb3f7137 100644
--- a/BaseTools/Source/Python/AutoGen/StrGather.py
+++ b/BaseTools/Source/Python/AutoGen/StrGather.py
@@ -290,7 +290,7 @@ def GetFilteredLanguage(UniLanguageList, LanguageFilterList):
if DefaultTag not in UniLanguageListFiltered:
# check whether language code with primary code equivalent with DefaultTag already in the list, if so, use that
for UniLanguage in UniLanguageList:
- if UniLanguage.startswith('en-') or UniLanguage.startswith('eng-'):
+ if UniLanguage.startswith(('eng-','en-')):
if UniLanguage not in UniLanguageListFiltered:
UniLanguageListFiltered.append(UniLanguage)
break
diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
index e2b4795129ef..3b54865000bf 100644
--- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
+++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
@@ -254,7 +254,7 @@ class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ):
for valid_num in valid_num_list:
valid_num = valid_num.strip()
- if valid_num.startswith('0x') or valid_num.startswith('0X'):
+ if valid_num.startswith(('0x','0X')):
self.data.add(int(valid_num, 16))
else:
self.data.add(int(valid_num))
diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
index 69a9665f5a76..4fa12b7d59de 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -172,7 +172,7 @@ class PcdEntry:
# @param ValueString The Integer type string for pack.
#
def _PackPtrValue(self, ValueString, Size):
- if ValueString.startswith('L"') or ValueString.startswith("L'"):
+ if ValueString.startswith(("L'",'L"')):
self._PackUnicode(ValueString, Size)
elif ValueString.startswith('{') and ValueString.endswith('}'):
self._PackByteArray(ValueString, Size)
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 9fa07c6add16..e5d17e6b4de0 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -130,7 +130,7 @@ def IsValidCName(Str):
def BuildOptionValue(PcdValue, GuidDict):
if PcdValue.startswith('H'):
InputValue = PcdValue[1:]
- elif PcdValue.startswith("L'") or PcdValue.startswith("'"):
+ elif PcdValue.startswith(("L'", "'")):
InputValue = PcdValue
elif PcdValue.startswith('L'):
InputValue = 'L"' + PcdValue[1:] + '"'
@@ -390,7 +390,7 @@ class ValueExpression(BaseExpression):
elif not Val:
Val = False
RealVal = '""'
- elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'"):
+ elif not Val.startswith(('L"',"L'",'{')):
Val = True
RealVal = '"' + RealVal + '"'
@@ -532,7 +532,7 @@ class ValueExpression(BaseExpression):
Radix = 10
if self._Token.lower()[0:2] == '0x' and len(self._Token) > 2:
Radix = 16
- if self._Token.startswith('"') or self._Token.startswith('L"'):
+ if self._Token.startswith(('"','L"')):
Flag = 0
for Index in range(len(self._Token)):
if self._Token[Index] in {'"'}:
@@ -541,7 +541,7 @@ class ValueExpression(BaseExpression):
Flag += 1
if Flag == 2 and self._Token.endswith('"'):
return True
- if self._Token.startswith("'") or self._Token.startswith("L'"):
+ if self._Token.startswith(("'","L'")):
Flag = 0
for Index in range(len(self._Token)):
if self._Token[Index] in {"'"}:
@@ -810,15 +810,14 @@ class ValueExpressionEx(ValueExpression):
PcdValue = self.PcdValue
try:
PcdValue = ValueExpression.__call__(self, RealValue, Depth)
- if self.PcdType == TAB_VOID and (PcdValue.startswith("'") or PcdValue.startswith("L'")):
+ if self.PcdType == TAB_VOID and PcdValue.startswith(("'","L'")):
PcdValue, Size = ParseFieldValue(PcdValue)
PcdValueList = []
for I in range(Size):
PcdValueList.append('0x%02X'%(PcdValue & 0xff))
PcdValue = PcdValue >> 8
PcdValue = '{' + ','.join(PcdValueList) + '}'
- elif self.PcdType in TAB_PCD_NUMERIC_TYPES and (PcdValue.startswith("'") or \
- PcdValue.startswith('"') or PcdValue.startswith("L'") or PcdValue.startswith('L"') or PcdValue.startswith('{')):
+ elif self.PcdType in TAB_PCD_NUMERIC_TYPES and PcdValue.startswith(("'",'"',"L'",'L"','{')):
raise BadExpression
except WrnExpression, Value:
PcdValue = Value.result
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 24706ebe500f..8fba734568bd 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1568,8 +1568,8 @@ def AnalyzePcdData(Setting):
def CheckPcdDatum(Type, Value):
if Type == TAB_VOID:
ValueRe = re.compile(r'\s*L?\".*\"\s*$')
- if not (((Value.startswith('L"') or Value.startswith('"')) and Value.endswith('"'))
- or (Value.startswith('{') and Value.endswith('}')) or (Value.startswith("L'") or Value.startswith("'") and Value.endswith("'"))
+ if not ((Value.startswith(('L"','"')) and Value.endswith('"'))
+ or (Value.startswith('{') and Value.endswith('}')) or (Value.startswith(("L'","'")) and Value.endswith("'"))
):
return False, "Invalid value [%s] of type [%s]; must be in the form of {...} for array"\
", \"...\" or \'...\' for string, L\"...\" or L\'...\' for unicode string" % (Value, Type)
@@ -2106,7 +2106,7 @@ def GetIntegerValue(Input):
if String.endswith("LL"):
String = String[:-2]
- if String.startswith("0x") or String.startswith("0X"):
+ if String.startswith(("0x","0X")):
return int(String, 16)
elif String == '':
return 0
diff --git a/BaseTools/Source/Python/Ecc/Check.py b/BaseTools/Source/Python/Ecc/Check.py
index dde7d7841082..e7bd97297538 100644
--- a/BaseTools/Source/Python/Ecc/Check.py
+++ b/BaseTools/Source/Python/Ecc/Check.py
@@ -777,7 +777,7 @@ class Check(object):
SqlCommand = """select ID, Value1, Value2 from Dsc where Model = %s""" % MODEL_EFI_LIBRARY_CLASS
LibraryClasses = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)
for LibraryClass in LibraryClasses:
- if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryClass[1].endswith('!endif'):
+ if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith(('!ifdef','!ifndef')) or LibraryClass[1].endswith('!endif'):
continue
else:
LibraryIns = os.path.normpath(mws.join(EccGlobalData.gWorkspace, LibraryClass[2]))
@@ -1029,9 +1029,9 @@ class Check(object):
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, FunName):
if Model in [MODEL_PCD_FIXED_AT_BUILD] and not FunName.startswith('FixedPcdGet'):
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, OtherMsg="The pcd '%s' is defined as a FixPcd but now it is called by c function [%s]" % (PcdName, FunName), BelongsToTable=TblName, BelongsToItem=Record[1])
- if Model in [MODEL_PCD_FEATURE_FLAG] and (not FunName.startswith('FeaturePcdGet') and not FunName.startswith('FeaturePcdSet')):
+ if Model in [MODEL_PCD_FEATURE_FLAG] and not FunName.startswith(('FeaturePcdGet','FeaturePcdSet')):
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, OtherMsg="The pcd '%s' is defined as a FeaturePcd but now it is called by c function [%s]" % (PcdName, FunName), BelongsToTable=TblName, BelongsToItem=Record[1])
- if Model in [MODEL_PCD_PATCHABLE_IN_MODULE] and (not FunName.startswith('PatchablePcdGet') and not FunName.startswith('PatchablePcdSet')):
+ if Model in [MODEL_PCD_PATCHABLE_IN_MODULE] and not FunName.startswith(('PatchablePcdGet','PatchablePcdSet')):
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, OtherMsg="The pcd '%s' is defined as a PatchablePcd but now it is called by c function [%s]" % (PcdName, FunName), BelongsToTable=TblName, BelongsToItem=Record[1])
#ERROR_META_DATA_FILE_CHECK_PCD_TYPE
diff --git a/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py b/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py
index ffa51de7c1bf..a2d2817b73f4 100644
--- a/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py
+++ b/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py
@@ -221,7 +221,7 @@ class CodeFragmentCollector:
if self.Profile.FileLinesList[Line - 1][0] != T_CHAR_HASH:
BeforeHashPart = str(self.Profile.FileLinesList[Line - 1]).split(T_CHAR_HASH)[0]
- if BeforeHashPart.rstrip().endswith(T_CHAR_COMMA) or BeforeHashPart.rstrip().endswith(';'):
+ if BeforeHashPart.rstrip().endswith((T_CHAR_COMMA,';')):
return
if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith(','):
@@ -230,7 +230,7 @@ class CodeFragmentCollector:
if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith(';'):
return
- if str(self.Profile.FileLinesList[Line]).lstrip().startswith(',') or str(self.Profile.FileLinesList[Line]).lstrip().startswith(';'):
+ if str(self.Profile.FileLinesList[Line]).lstrip().startswith((',',';')):
return
self.Profile.FileLinesList[Line - 1].insert(self.CurrentOffsetWithinLine, ',')
diff --git a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py b/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py
index c2e60016926d..3756c34e2215 100644
--- a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py
@@ -1712,7 +1712,7 @@ class DecParser(MetaFileParser):
if len(GuidValueList) == 11:
for GuidValue in GuidValueList:
GuidValue = GuidValue.strip()
- if GuidValue.startswith('0x') or GuidValue.startswith('0X'):
+ if GuidValue.startswith(('0x','0X')):
HexList.append('0x' + str(GuidValue[2:]))
Index += 1
continue
diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/Ecc/c.py
index bc72abdce477..4c49d1ca570f 100644
--- a/BaseTools/Source/Python/Ecc/c.py
+++ b/BaseTools/Source/Python/Ecc/c.py
@@ -1372,7 +1372,7 @@ def CheckFuncLayoutName(FullFileName):
PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, 'Parameter [%s] NOT follow naming convention.' % Param.Name, FileTable, Result[1])
StartLine = Param.StartLine
- if not Result[0].endswith('\n )') and not Result[0].endswith('\r )'):
+ if not Result[0].endswith(('\n )','\r )')):
PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', FileTable, Result[1])
SqlStatement = """ select Modifier, ID, FunNameStartColumn, Name
@@ -1398,7 +1398,7 @@ def CheckFuncLayoutName(FullFileName):
if not Pattern.match(Param.Name) and not Param.Name in ParamIgnoreList and not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Param.Name):
PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, 'Parameter [%s] NOT follow naming convention.' % Param.Name, FileTable, Result[1])
StartLine = Param.StartLine
- if not Result[0].endswith('\n )') and not Result[0].endswith('\r )'):
+ if not Result[0].endswith(('\n )','\r )')):
PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', 'Function', Result[1])
def CheckFuncLayoutPrototype(FullFileName):
@@ -2193,7 +2193,7 @@ def CheckHeaderFileIfndef(FullFileName):
""" % (FileTable, Result[1])
ResultSet = Db.TblFile.Exec(SqlStatement)
for Result in ResultSet:
- if not Result[0].startswith('/*') and not Result[0].startswith('//'):
+ if not Result[0].startswith(('/*','//')):
PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2, '', 'File', FileID)
break
@@ -2203,7 +2203,7 @@ def CheckHeaderFileIfndef(FullFileName):
""" % (FileTable, FileTable, DataClass.MODEL_IDENTIFIER_MACRO_ENDIF)
ResultSet = Db.TblFile.Exec(SqlStatement)
for Result in ResultSet:
- if not Result[0].startswith('/*') and not Result[0].startswith('//'):
+ if not Result[0].startswith(('/*','//')):
PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3, '', 'File', FileID)
return ErrorMsgList
@@ -2374,7 +2374,7 @@ def CheckFileHeaderDoxygenComments(FullFileName):
break
# Check whether C File header Comment content start with two spaces.
if EccGlobalData.gConfig.HeaderCheckCFileCommentStartSpacesNum == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
- if CommentLine.startswith('/** @file') == False and CommentLine.startswith('**/') == False and CommentLine.strip() and CommentLine.startswith(' ') == False:
+ if not CommentLine.startswith(('/** @file','**/',' ')) and CommentLine.strip():
PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment content should start with two spaces at each line', FileTable, ID)
CommentLine = CommentLine.strip()
@@ -2401,7 +2401,7 @@ def CheckFileHeaderDoxygenComments(FullFileName):
# Check whether C File header Comment's each reference at list should begin with a bullet character.
if EccGlobalData.gConfig.HeaderCheckCFileCommentReferenceFormat == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
if RefListFlag == True:
- if RefLine.strip() and RefLine.strip().startswith('**/') == False and RefLine.startswith(' -') == False:
+ if RefLine.strip() and not RefLine.strip().startswith(('**/',' -')):
PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'Each reference on a separate line should begin with a bullet character ""-"" ', FileTable, ID)
if NoHeaderCommentStartFlag:
@@ -2614,7 +2614,7 @@ def CheckFunctionHeaderConsistentWithDoxygenComment(FuncModifier, FuncHeader, Fu
ErrorMsgList.append('Line %d : VOID return type need NO doxygen tags in comment' % CommentStartLine)
PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'VOID return type need no doxygen tags in comment ', TableName, CommentId)
else:
- if Index < DoxygenTagNumber and not DoxygenStrList[Index].startswith('@retval') and not DoxygenStrList[Index].startswith('@return'):
+ if Index < DoxygenTagNumber and not DoxygenStrList[Index].startswith(('@retval','@return')):
ErrorMsgList.append('Line %d : Number of @param doxygen tags in comment does NOT match number of function parameters' % CommentStartLine)
PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'Number of @param doxygen tags in comment does NOT match number of function parameters ', TableName, CommentId)
else:
diff --git a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py b/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
index 87f179206d84..b962ad019161 100644
--- a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
+++ b/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
@@ -215,16 +215,13 @@ class CodeFragmentCollector:
if self.Profile.FileLinesList[Line - 1][0] != T_CHAR_HASH:
BeforeHashPart = str(self.Profile.FileLinesList[Line - 1]).split(T_CHAR_HASH)[0]
- if BeforeHashPart.rstrip().endswith(T_CHAR_COMMA) or BeforeHashPart.rstrip().endswith(';'):
+ if BeforeHashPart.rstrip().endswith((T_CHAR_COMMA,';')):
return
- if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith(','):
+ if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith((',',';')):
return
- if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith(';'):
- return
-
- if str(self.Profile.FileLinesList[Line]).lstrip().startswith(',') or str(self.Profile.FileLinesList[Line]).lstrip().startswith(';'):
+ if str(self.Profile.FileLinesList[Line]).lstrip().startswith((',',';')):
return
self.Profile.FileLinesList[Line - 1].insert(self.CurrentOffsetWithinLine, ',')
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 78cb049c6187..ba076c8c1ecd 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -1249,7 +1249,7 @@ class FdfParser:
# @retval False Not able to find a string data, file buffer pointer not changed
#
def __GetStringData(self):
- if self.__Token.startswith("\"") or self.__Token.startswith("L\""):
+ if self.__Token.startswith(("\"","L\"")):
self.__UndoToken()
self.__SkipToToken("\"")
currentLineNumber = self.CurrentLineNumber
@@ -1261,7 +1261,7 @@ class FdfParser:
self.__Token = self.__SkippedChars.rstrip('\"')
return True
- elif self.__Token.startswith("\'") or self.__Token.startswith("L\'"):
+ elif self.__Token.startswith(("\'","L\'")):
self.__UndoToken()
self.__SkipToToken("\'")
currentLineNumber = self.CurrentLineNumber
@@ -1391,8 +1391,7 @@ class FdfParser:
def SectionParser(self, section):
S = section.upper()
- if not S.startswith("[DEFINES") and not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \
- and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM.") and not S.startswith('[FMPPAYLOAD.'):
+ if not S.startswith(("[DEFINES","[FD.","[FV.","[CAPSULE.","[VTF.","[RULE.","[OPTIONROM.",'[FMPPAYLOAD.')):
raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.], [FMPPAYLOAD.])", self.FileName, self.CurrentLineNumber)
## __GetDefines() method
@@ -1456,8 +1455,7 @@ class FdfParser:
S = self.__Token.upper()
if S.startswith("[") and not S.startswith("[FD."):
- if not S.startswith("[FV.") and not S.startswith('[FMPPAYLOAD.') and not S.startswith("[CAPSULE.") \
- and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):
+ if not S.startswith(("[FV.",'[FMPPAYLOAD.',"[CAPSULE.","[VTF.","[RULE.","[OPTIONROM.")):
raise Warning("Unknown section", self.FileName, self.CurrentLineNumber)
self.__UndoToken()
return False
diff --git a/BaseTools/Source/Python/Trim/Trim.py b/BaseTools/Source/Python/Trim/Trim.py
index a74075859148..d2e6d317676c 100644
--- a/BaseTools/Source/Python/Trim/Trim.py
+++ b/BaseTools/Source/Python/Trim/Trim.py
@@ -409,7 +409,7 @@ def TrimAslFile(Source, Target, IncludePathFile):
LineNum = 0
for Line in open(IncludePathFile,'r'):
LineNum += 1
- if Line.startswith("/I") or Line.startswith ("-I"):
+ if Line.startswith(("/I","-I")):
IncludePathList.append(Line[2:].strip())
else:
EdkLogger.warn("Trim", "Invalid include line in include list file.", IncludePathFile, LineNum)
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index db9518cdff17..3e68be3ce34e 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -82,7 +82,7 @@ class PcdClassObject(object):
if self.PcdValueFromComm:
if self.PcdValueFromComm.startswith("{") and self.PcdValueFromComm.endswith("}"):
return max([len(self.PcdValueFromComm.split(",")),MaxSize])
- elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFromComm.startswith("\'"):
+ elif self.PcdValueFromComm.startswith(("\"","\'")):
return max([len(self.PcdValueFromComm)-2+1,MaxSize])
elif self.PcdValueFromComm.startswith("L\""):
return max([2*(len(self.PcdValueFromComm)-3+1),MaxSize])
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 1ed7eb1c2cf7..edae4e5e7fcf 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1062,7 +1062,7 @@ class DscBuildData(PlatformBuildClassObject):
except BadExpression, Value:
EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %
(TokenSpaceGuidCName, TokenCName, PcdValue, Value))
- elif PcdValue.startswith("L'") or PcdValue.startswith("'"):
+ elif PcdValue.startswith(("L'","'")):
if FieldName and IsFieldValueAnArray(PcdValue):
PcdDatumType = TAB_VOID
IsArray = True
diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/Source/Python/Workspace/InfBuildData.py
index 836140759f21..d7e474770521 100644
--- a/BaseTools/Source/Python/Workspace/InfBuildData.py
+++ b/BaseTools/Source/Python/Workspace/InfBuildData.py
@@ -1080,7 +1080,7 @@ class InfBuildData(ModuleBuildClassObject):
# Check hexadecimal token value length and format.
#
ReIsValidPcdTokenValue = re.compile(r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)
- if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.startswith("0X"):
+ if Pcd.TokenValue.startswith(("0x","0X")):
if ReIsValidPcdTokenValue.match(Pcd.TokenValue) is None:
EdkLogger.error(
'build',
diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py
index 324b6ff6aa76..4e1d0cc18c16 100644
--- a/BaseTools/Source/Python/build/BuildReport.py
+++ b/BaseTools/Source/Python/build/BuildReport.py
@@ -1362,7 +1362,7 @@ class PcdReport(object):
return value[1:-1]
for ch in value[1:-1].split(','):
ch = ch.strip()
- if ch.startswith('0x') or ch.startswith('0X'):
+ if ch.startswith(('0x','0X')):
valuelist.append(ch)
continue
try:
--
2.16.2.windows.1
next prev parent reply other threads:[~2018-06-20 21:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-20 21:08 [PATCH v2 00/11] BaseTools Refactoring Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 01/11] BaseTools: decorate base classes to prevent instantiation Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 02/11] BaseTools: Workspace - create a base class Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 03/11] BaseTools: remove unused code Jaben Carsey
2018-06-20 21:08 ` Jaben Carsey [this message]
2018-06-20 21:08 ` [PATCH v1 05/11] BaseTools: use set presence instead of series of equality Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 06/11] BaseTools: refactor section generation Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 07/11] BaseTools: refactor file opening/writing Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 08/11] BaseTools: refactor to change object types Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 09/11] BaseTools: refactor to stop re-allocating strings Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 10/11] BaseTools: change to set for membership testing Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 11/11] BaseTools: remove extra assignment Jaben Carsey
-- strict thread matches above, loose matches on Subject: below --
2018-05-14 18:09 [PATCH v1 00/11] BaseTools refactoring Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 04/11] BaseTools: remove repeated calls to startswith/endswith Jaben Carsey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5271b48db2aa208f6862bffcbbe347b7cbaf0546.1529528784.git.jaben.carsey@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox