From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2E1C320969676 for ; Mon, 14 May 2018 11:09:25 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2018 11:09:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="55814264" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga001.jf.intel.com with ESMTP; 14 May 2018 11:09:23 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Mon, 14 May 2018 11:09:13 -0700 Message-Id: X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v1 04/11] BaseTools: remove repeated calls to startswith/endswith X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 May 2018 18:09:25 -0000 As both can take a tuple, use that instead of calling repeatedly. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- 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 1c8ab7fe1ec8..d70c5c26ffc8 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 73af1214eb0a..e5e4f25efd5d 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 += [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 90350f863826..17907a318944 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 e5c43b629151..0f9711ba109e 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 8a9296c49d1d..2439d8ab9455 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -1250,7 +1250,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 @@ -1262,7 +1262,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 @@ -1392,8 +1392,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 @@ -1457,8 +1456,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 8476543c5352..2de8a84b9bd7 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 bd1c84154123..12d848b5fc41 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 cf45ef173498..72a557dfea50 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -1318,7 +1318,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