From nobody Fri Sep 5 06:18:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 152632137742163.6005145667076; Mon, 14 May 2018 11:09:37 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B892121DF8098; Mon, 14 May 2018 11:09:26 -0700 (PDT) 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) 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 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 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="55814264" From: Jaben Carsey To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D index + 1 if CmdName =3D=3D 'Trim': SecDepsFileList.append(os.path.join('$(DEBUG_D= IR)', os.path.basename(OutputFile).replace('offset', 'efi'))) - if OutputFile.endswith('.ui') or OutputFile.endswi= th('.ver'): + if OutputFile.endswith(('.ui','.ver')): SecDepsFileList.append(os.path.join('$(MODULE_= DIR)','$(MODULE_FILE)')) self.FfsOutputFileList.append((OutputFile, ' '.joi= n(SecDepsFileList), SecCmdStr)) if len(SecDepsFileList) > 0: diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Sourc= e/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, LanguageFilter= List): if DefaultTag not in UniLanguageListFiltered: # check whether language code with primary code equiva= lent with DefaultTag already in the list, if so, use that for UniLanguage in UniLanguageList: - if UniLanguage.startswith('en-') or UniLanguage.st= artswith('eng-'): + if UniLanguage.startswith(('eng-','en-')): if UniLanguage not in UniLanguageListFiltered: UniLanguageListFiltered +=3D [UniLanguage] break diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/B= aseTools/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 =3D valid_num.strip() =20 - 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/Pyth= on/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. # =20 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/Sourc= e/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 =3D PcdValue[1:] - elif PcdValue.startswith("L'") or PcdValue.startswith("'"): + elif PcdValue.startswith(("L'", "'")): InputValue =3D PcdValue elif PcdValue.startswith('L'): InputValue =3D 'L"' + PcdValue[1:] + '"' @@ -390,7 +390,7 @@ class ValueExpression(BaseExpression): elif not Val: Val =3D False RealVal =3D '""' - elif not Val.startswith('L"') and not Val.startswith('{') and = not Val.startswith("L'"): + elif not Val.startswith(('L"',"L'",'{')): Val =3D True RealVal =3D '"' + RealVal + '"' =20 @@ -532,7 +532,7 @@ class ValueExpression(BaseExpression): Radix =3D 10 if self._Token.lower()[0:2] =3D=3D '0x' and len(self._Token) > 2: Radix =3D 16 - if self._Token.startswith('"') or self._Token.startswith('L"'): + if self._Token.startswith(('"','L"')): Flag =3D 0 for Index in range(len(self._Token)): if self._Token[Index] in {'"'}: @@ -541,7 +541,7 @@ class ValueExpression(BaseExpression): Flag +=3D 1 if Flag =3D=3D 2 and self._Token.endswith('"'): return True - if self._Token.startswith("'") or self._Token.startswith("L'"): + if self._Token.startswith(("'","L'")): Flag =3D 0 for Index in range(len(self._Token)): if self._Token[Index] in {"'"}: @@ -810,15 +810,14 @@ class ValueExpressionEx(ValueExpression): PcdValue =3D self.PcdValue try: PcdValue =3D ValueExpression.__call__(self, RealValue, Depth) - if self.PcdType =3D=3D TAB_VOID and (PcdValue.startswith("'") = or PcdValue.startswith("L'")): + if self.PcdType =3D=3D TAB_VOID and PcdValue.startswith(("'","= L'")): PcdValue, Size =3D ParseFieldValue(PcdValue) PcdValueList =3D [] for I in range(Size): PcdValueList.append('0x%02X'%(PcdValue & 0xff)) PcdValue =3D PcdValue >> 8 PcdValue =3D '{' + ','.join(PcdValueList) + '}' - elif self.PcdType in TAB_PCD_NUMERIC_TYPES and (PcdValue.start= swith("'") or \ - PcdValue.startswith('"') or PcdValue.startswith("L'"= ) or PcdValue.startswith('L"') or PcdValue.startswith('{')): + elif self.PcdType in TAB_PCD_NUMERIC_TYPES and PcdValue.starts= with(("'",'"',"L'",'L"','{')): raise BadExpression except WrnExpression, Value: PcdValue =3D Value.result diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/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 =3D=3D TAB_VOID: ValueRe =3D re.compile(r'\s*L?\".*\"\s*$') - if not (((Value.startswith('L"') or Value.startswith('"')) and Val= ue.endswith('"')) - or (Value.startswith('{') and Value.endswith('}')) or (Val= ue.startswith("L'") or Value.startswith("'") and Value.endswith("'")) + if not ((Value.startswith(('L"','"')) and Value.endswith('"')) + or (Value.startswith('{') and Value.endswith('}')) or (Val= ue.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 =3D String[:-2] =20 - if String.startswith("0x") or String.startswith("0X"): + if String.startswith(("0x","0X")): return int(String, 16) elif String =3D=3D '': 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 =3D """select ID, Value1, Value2 from Dsc where Mod= el =3D %s""" % MODEL_EFI_LIBRARY_CLASS LibraryClasses =3D EccGlobalData.gDb.TblDsc.Exec(SqlCommand) for LibraryClass in LibraryClasses: - if LibraryClass[1].upper() =3D=3D 'NULL' or LibraryClass[1= ].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryC= lass[1].endswith('!endif'): + if LibraryClass[1].upper() =3D=3D 'NULL' or LibraryClass[1= ].startswith(('!ifdef','!ifndef')) or LibraryClass[1].endswith('!endif'): continue else: LibraryIns =3D 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_M= ETA_DATA_FILE_CHECK_PCD_TYPE, OtherMsg=3D"The pcd '%s' is defined as a FixP= cd but now it is called by c function [%s]" % (PcdName, FunName), BelongsTo= Table=3DTblName, BelongsToItem=3DRecord[1]) - if Model in [MODEL_PCD_FEATURE_FLAG] and (not = FunName.startswith('FeaturePcdGet') and not FunName.startswith('FeaturePcdS= et')): + if Model in [MODEL_PCD_FEATURE_FLAG] and not F= unName.startswith(('FeaturePcdGet','FeaturePcdSet')): EccGlobalData.gDb.TblReport.Insert(ERROR_M= ETA_DATA_FILE_CHECK_PCD_TYPE, OtherMsg=3D"The pcd '%s' is defined as a Feat= urePcd but now it is called by c function [%s]" % (PcdName, FunName), Belon= gsToTable=3DTblName, BelongsToItem=3DRecord[1]) - if Model in [MODEL_PCD_PATCHABLE_IN_MODULE] an= d (not FunName.startswith('PatchablePcdGet') and not FunName.startswith('Pa= tchablePcdSet')): + if Model in [MODEL_PCD_PATCHABLE_IN_MODULE] an= d not FunName.startswith(('PatchablePcdGet','PatchablePcdSet')): EccGlobalData.gDb.TblReport.Insert(ERROR_M= ETA_DATA_FILE_CHECK_PCD_TYPE, OtherMsg=3D"The pcd '%s' is defined as a Patc= hablePcd but now it is called by c function [%s]" % (PcdName, FunName), Bel= ongsToTable=3DTblName, BelongsToItem=3DRecord[1]) =20 #ERROR_META_DATA_FILE_CHECK_PCD_TYPE diff --git a/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py b/BaseToo= ls/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: =20 if self.Profile.FileLinesList[Line - 1][0] !=3D T_CHAR_HASH: BeforeHashPart =3D str(self.Profile.FileLinesList[Line - 1]).s= plit(T_CHAR_HASH)[0] - if BeforeHashPart.rstrip().endswith(T_CHAR_COMMA) or BeforeHas= hPart.rstrip().endswith(';'): + if BeforeHashPart.rstrip().endswith((T_CHAR_COMMA,';')): return =20 if Line - 2 >=3D 0 and str(self.Profile.FileLinesList[Line - 2]).r= strip().endswith(','): @@ -230,7 +230,7 @@ class CodeFragmentCollector: if Line - 2 >=3D 0 and str(self.Profile.FileLinesList[Line - 2]).r= strip().endswith(';'): return =20 - 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 =20 self.Profile.FileLinesList[Line - 1].insert(self.CurrentOffsetWith= inLine, ',') diff --git a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.p= y 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) =3D=3D 11: for GuidValue in GuidValueList: GuidValue =3D GuidValue.strip() - if GuidValue.startswith('0x') or GuidValue.startswith('0X'= ): + if GuidValue.startswith(('0x','0X')): HexList.append('0x' + str(GuidValue[2:])) Index +=3D 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, Re= sult[1]) StartLine =3D Param.StartLine =20 - 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]) =20 SqlStatement =3D """ select Modifier, ID, FunNameStartColumn, Name @@ -1398,7 +1398,7 @@ def CheckFuncLayoutName(FullFileName): if not Pattern.match(Param.Name) and not Param.Name in ParamIg= noreList and not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTI= ON_CHECK_VARIABLE_NAME, Param.Name): PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME,= 'Parameter [%s] NOT follow naming convention.' % Param.Name, FileTable, Re= sult[1]) StartLine =3D 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]) =20 def CheckFuncLayoutPrototype(FullFileName): @@ -2193,7 +2193,7 @@ def CheckHeaderFileIfndef(FullFileName): """ % (FileTable, Result[1]) ResultSet =3D 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 =20 @@ -2203,7 +2203,7 @@ def CheckHeaderFileIfndef(FullFileName): """ % (FileTable, FileTable, DataClass.MODEL_IDENTIFIER= _MACRO_ENDIF) ResultSet =3D 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 =20 @@ -2374,7 +2374,7 @@ def CheckFileHeaderDoxygenComments(FullFileName): break # Check whether C File header Comment content start with two s= paces. if EccGlobalData.gConfig.HeaderCheckCFileCommentStartSpacesNum= =3D=3D '1' or EccGlobalData.gConfig.HeaderCheckAll =3D=3D '1' or EccGlobal= Data.gConfig.CheckAll =3D=3D '1': - if CommentLine.startswith('/** @file') =3D=3D False and Co= mmentLine.startswith('**/') =3D=3D False and CommentLine.strip() and Commen= tLine.startswith(' ') =3D=3D False: + if not CommentLine.startswith(('/** @file','**/',' ')) an= d CommentLine.strip(): PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header co= mment content should start with two spaces at each line', FileTable, ID) =20 CommentLine =3D 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.HeaderCheckCFileCommentRefere= nceFormat =3D=3D '1' or EccGlobalData.gConfig.HeaderCheckAll =3D=3D '1' or = EccGlobalData.gConfig.CheckAll =3D=3D '1': if RefListFlag =3D=3D True: - if RefLine.strip() and RefLine.strip().startsw= ith('**/') =3D=3D False and RefLine.startswith(' -') =3D=3D False: = =20 + if RefLine.strip() and not RefLine.strip().sta= rtswith(('**/',' -')): =20 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'Ea= ch reference on a separate line should begin with a bullet character ""-"" = ', FileTable, ID) =20 =20 if NoHeaderCommentStartFlag: @@ -2614,7 +2614,7 @@ def CheckFunctionHeaderConsistentWithDoxygenComment(F= uncModifier, FuncHeader, Fu ErrorMsgList.append('Line %d : VOID return type need NO do= xygen tags in comment' % CommentStartLine) PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'VOID r= eturn type need no doxygen tags in comment ', TableName, CommentId) else: - if Index < DoxygenTagNumber and not DoxygenStrList[Index].star= tswith('@retval') and not DoxygenStrList[Index].startswith('@return'): + if Index < DoxygenTagNumber and not DoxygenStrList[Index].star= tswith(('@retval','@return')): ErrorMsgList.append('Line %d : Number of @param doxygen ta= gs in comment does NOT match number of function parameters' % CommentStartL= ine) PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'Number= of @param doxygen tags in comment does NOT match number of function parame= ters ', TableName, CommentId) else: diff --git a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py b/BaseToo= ls/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: =20 if self.Profile.FileLinesList[Line - 1][0] !=3D T_CHAR_HASH: BeforeHashPart =3D str(self.Profile.FileLinesList[Line - 1]).s= plit(T_CHAR_HASH)[0] - if BeforeHashPart.rstrip().endswith(T_CHAR_COMMA) or BeforeHas= hPart.rstrip().endswith(';'): + if BeforeHashPart.rstrip().endswith((T_CHAR_COMMA,';')): return =20 - if Line - 2 >=3D 0 and str(self.Profile.FileLinesList[Line - 2]).r= strip().endswith(','): + if Line - 2 >=3D 0 and str(self.Profile.FileLinesList[Line - 2]).r= strip().endswith((',',';')): return =20 - if Line - 2 >=3D 0 and str(self.Profile.FileLinesList[Line - 2]).r= strip().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 =20 self.Profile.FileLinesList[Line - 1].insert(self.CurrentOffsetWith= inLine, ',') 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 po= inter not changed # def __GetStringData(self): - if self.__Token.startswith("\"") or self.__Token.startswith("L\""): + if self.__Token.startswith(("\"","L\"")): self.__UndoToken() self.__SkipToToken("\"") currentLineNumber =3D self.CurrentLineNumber @@ -1262,7 +1262,7 @@ class FdfParser: self.__Token =3D self.__SkippedChars.rstrip('\"') return True =20 - elif self.__Token.startswith("\'") or self.__Token.startswith("L\'= "): + elif self.__Token.startswith(("\'","L\'")): self.__UndoToken() self.__SkipToToken("\'") currentLineNumber =3D self.CurrentLineNumber @@ -1392,8 +1392,7 @@ class FdfParser: =20 def SectionParser(self, section): S =3D section.upper() - if not S.startswith("[DEFINES") and not S.startswith("[FD.") and n= ot S.startswith("[FV.") and not S.startswith("[CAPSULE.") \ - and not S.startswith("[VTF.") and not S.startswith("[RULE.") a= nd 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 erro= r (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF= .], [Rule.], [OptionRom.], [FMPPAYLOAD.])", self.FileName, self.CurrentLine= Number) =20 ## __GetDefines() method @@ -1457,8 +1456,7 @@ class FdfParser: =20 S =3D 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.Curre= ntLineNumber) 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 =3D 0 for Line in open(IncludePathFile,'r'): LineNum +=3D 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 includ= e list file.", IncludePathFile, LineNum) diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTo= ols/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.PcdValueFrom= Comm.endswith("}"): return max([len(self.PcdValueFromComm.split(",")),MaxSize]) - elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFr= omComm.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: =20 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Val= ue "%s", %s' % (TokenSpaceGuidCName, TokenCName, PcdValue= , Value)) - elif PcdValue.startswith("L'") or PcdValue.startswith("'"): + elif PcdValue.startswith(("L'","'")): if FieldName and IsFieldValueAnArray(PcdValue): PcdDatumType =3D TAB_VOID IsArray =3D 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 =3D re.compile(r"^[0][x|X][0]*[= 0-9a-fA-F]{1,8}$", re.DOTALL) - if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.s= tartswith("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/Sourc= e/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 =3D ch.strip() - if ch.startswith('0x') or ch.startswith('0X'): + if ch.startswith(('0x','0X')): valuelist.append(ch) continue try: --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel