BaseTools: Remove equality operator with None
replace "== None" with "is None" and "!= None" with "is not None" Cc: Yonghong Zhu <yonghong.zhu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
05a32984ab
commit
4231a8193e
@@ -555,15 +555,15 @@ def ParseComment (Comment, UsageTokens, TypeTokens, RemoveTokens, ParseVariable)
|
||||
# from HelpText
|
||||
#
|
||||
for Token in List[0:NumTokens]:
|
||||
if Usage == None and Token in UsageTokens:
|
||||
if Usage is None and Token in UsageTokens:
|
||||
Usage = UsageTokens[Token]
|
||||
HelpText = HelpText.replace(Token, '')
|
||||
if Usage != None or not ParseVariable:
|
||||
if Usage is not None or not ParseVariable:
|
||||
for Token in List[0:NumTokens]:
|
||||
if Type == None and Token in TypeTokens:
|
||||
if Type is None and Token in TypeTokens:
|
||||
Type = TypeTokens[Token]
|
||||
HelpText = HelpText.replace(Token, '')
|
||||
if Usage != None:
|
||||
if Usage is not None:
|
||||
for Token in List[0:NumTokens]:
|
||||
if Token in RemoveTokens:
|
||||
HelpText = HelpText.replace(Token, '')
|
||||
@@ -571,13 +571,13 @@ def ParseComment (Comment, UsageTokens, TypeTokens, RemoveTokens, ParseVariable)
|
||||
#
|
||||
# If no Usage token is present and set Usage to UNDEFINED
|
||||
#
|
||||
if Usage == None:
|
||||
if Usage is None:
|
||||
Usage = 'UNDEFINED'
|
||||
|
||||
#
|
||||
# If no Type token is present and set Type to UNDEFINED
|
||||
#
|
||||
if Type == None:
|
||||
if Type is None:
|
||||
Type = 'UNDEFINED'
|
||||
|
||||
#
|
||||
|
@@ -120,7 +120,7 @@ def GuidStructureStringToGuidString(GuidValue):
|
||||
# @param Directory: The directory name
|
||||
#
|
||||
def CreateDirectory(Directory):
|
||||
if Directory == None or Directory.strip() == "":
|
||||
if Directory is None or Directory.strip() == "":
|
||||
return True
|
||||
try:
|
||||
if not access(Directory, F_OK):
|
||||
@@ -134,7 +134,7 @@ def CreateDirectory(Directory):
|
||||
# @param Directory: The directory name
|
||||
#
|
||||
def RemoveDirectory(Directory, Recursively=False):
|
||||
if Directory == None or Directory.strip() == "" or not \
|
||||
if Directory is None or Directory.strip() == "" or not \
|
||||
os.path.exists(Directory):
|
||||
return
|
||||
if Recursively:
|
||||
@@ -237,7 +237,7 @@ def GetNonMetaDataFiles(Root, SkipList, FullPath, PrefixPath):
|
||||
#
|
||||
def ValidFile(File, Ext=None):
|
||||
File = File.replace('\\', '/')
|
||||
if Ext != None:
|
||||
if Ext is not None:
|
||||
FileExt = os.path.splitext(File)[1]
|
||||
if FileExt.lower() != Ext.lower():
|
||||
return False
|
||||
@@ -423,7 +423,7 @@ class Sdict(IterableUserDict):
|
||||
## update method
|
||||
#
|
||||
def update(self, Dict=None, **Kwargs):
|
||||
if Dict != None:
|
||||
if Dict is not None:
|
||||
for Key1, Val1 in Dict.items():
|
||||
self[Key1] = Val1
|
||||
if len(Kwargs):
|
||||
@@ -529,7 +529,7 @@ class PathClass(object):
|
||||
## _GetFileKey
|
||||
#
|
||||
def _GetFileKey(self):
|
||||
if self._Key == None:
|
||||
if self._Key is None:
|
||||
self._Key = self.Path.upper()
|
||||
return self._Key
|
||||
## Validate
|
||||
|
@@ -128,7 +128,7 @@ def IsValidInfComponentType(ComponentType):
|
||||
#
|
||||
def IsValidToolFamily(ToolFamily):
|
||||
ReIsValieFamily = re.compile(r"^[A-Z]+[A-Za-z0-9]{0,}$", re.DOTALL)
|
||||
if ReIsValieFamily.match(ToolFamily) == None:
|
||||
if ReIsValieFamily.match(ToolFamily) is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -159,7 +159,7 @@ def IsValidArch(Arch):
|
||||
if Arch == 'common':
|
||||
return True
|
||||
ReIsValieArch = re.compile(r"^[a-zA-Z]+[a-zA-Z0-9]{0,}$", re.DOTALL)
|
||||
if ReIsValieArch.match(Arch) == None:
|
||||
if ReIsValieArch.match(Arch) is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -179,7 +179,7 @@ def IsValidFamily(Family):
|
||||
return True
|
||||
|
||||
ReIsValidFamily = re.compile(r"^[A-Z]+[A-Za-z0-9]{0,}$", re.DOTALL)
|
||||
if ReIsValidFamily.match(Family) == None:
|
||||
if ReIsValidFamily.match(Family) is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -199,13 +199,13 @@ def IsValidBuildOptionName(BuildOptionName):
|
||||
ReIsValidBuildOption1 = re.compile(r"^\s*(\*)|([A-Z][a-zA-Z0-9]*)$")
|
||||
ReIsValidBuildOption2 = re.compile(r"^\s*(\*)|([a-zA-Z][a-zA-Z0-9]*)$")
|
||||
|
||||
if ReIsValidBuildOption1.match(ToolOptionList[0]) == None:
|
||||
if ReIsValidBuildOption1.match(ToolOptionList[0]) is None:
|
||||
return False
|
||||
|
||||
if ReIsValidBuildOption1.match(ToolOptionList[1]) == None:
|
||||
if ReIsValidBuildOption1.match(ToolOptionList[1]) is None:
|
||||
return False
|
||||
|
||||
if ReIsValidBuildOption2.match(ToolOptionList[2]) == None:
|
||||
if ReIsValidBuildOption2.match(ToolOptionList[2]) is None:
|
||||
return False
|
||||
|
||||
if ToolOptionList[3] == "*" and ToolOptionList[4] not in ['FAMILY', 'DLL', 'DPATH']:
|
||||
@@ -442,7 +442,7 @@ def IsValidDecVersion(Word):
|
||||
ReIsValidDecVersion = re.compile(r"[0-9]+\.?[0-9]+$")
|
||||
else:
|
||||
ReIsValidDecVersion = re.compile(r"[0-9]+$")
|
||||
if ReIsValidDecVersion.match(Word) == None:
|
||||
if ReIsValidDecVersion.match(Word) is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -457,7 +457,7 @@ def IsValidDecVersion(Word):
|
||||
#
|
||||
def IsValidHexVersion(Word):
|
||||
ReIsValidHexVersion = re.compile(r"[0][xX][0-9A-Fa-f]{8}$", re.DOTALL)
|
||||
if ReIsValidHexVersion.match(Word) == None:
|
||||
if ReIsValidHexVersion.match(Word) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -471,7 +471,7 @@ def IsValidHexVersion(Word):
|
||||
#
|
||||
def IsValidBuildNumber(Word):
|
||||
ReIsValieBuildNumber = re.compile(r"[0-9]{1,4}$", re.DOTALL)
|
||||
if ReIsValieBuildNumber.match(Word) == None:
|
||||
if ReIsValieBuildNumber.match(Word) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -488,7 +488,7 @@ def IsValidDepex(Word):
|
||||
return IsValidCFormatGuid(Word[Index+4:].strip())
|
||||
|
||||
ReIsValidCName = re.compile(r"^[A-Za-z_][0-9A-Za-z_\s\.]*$", re.DOTALL)
|
||||
if ReIsValidCName.match(Word) == None:
|
||||
if ReIsValidCName.match(Word) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -585,11 +585,11 @@ def IsValidPcdValue(PcdValue):
|
||||
return True
|
||||
|
||||
ReIsValidIntegerSingle = re.compile(r"^\s*[0-9]\s*$", re.DOTALL)
|
||||
if ReIsValidIntegerSingle.match(PcdValue) != None:
|
||||
if ReIsValidIntegerSingle.match(PcdValue) is not None:
|
||||
return True
|
||||
|
||||
ReIsValidIntegerMulti = re.compile(r"^\s*[1-9][0-9]+\s*$", re.DOTALL)
|
||||
if ReIsValidIntegerMulti.match(PcdValue) != None:
|
||||
if ReIsValidIntegerMulti.match(PcdValue) is not None:
|
||||
return True
|
||||
|
||||
#
|
||||
@@ -654,7 +654,7 @@ def IsValidPcdValue(PcdValue):
|
||||
#
|
||||
def IsValidCVariableName(CName):
|
||||
ReIsValidCName = re.compile(r"^[A-Za-z_][0-9A-Za-z_]*$", re.DOTALL)
|
||||
if ReIsValidCName.match(CName) == None:
|
||||
if ReIsValidCName.match(CName) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -669,7 +669,7 @@ def IsValidCVariableName(CName):
|
||||
#
|
||||
def IsValidIdentifier(Ident):
|
||||
ReIdent = re.compile(r"^[A-Za-z_][0-9A-Za-z_]*$", re.DOTALL)
|
||||
if ReIdent.match(Ident) == None:
|
||||
if ReIdent.match(Ident) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -683,7 +683,7 @@ def IsValidIdentifier(Ident):
|
||||
def IsValidDecVersionVal(Ver):
|
||||
ReVersion = re.compile(r"[0-9]+(\.[0-9]{1,2})$")
|
||||
|
||||
if ReVersion.match(Ver) == None:
|
||||
if ReVersion.match(Ver) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@@ -134,7 +134,7 @@ def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo= -1):
|
||||
#
|
||||
def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo= -1):
|
||||
Format = '<TokenSpaceGuidCName>.<PcdCName>'
|
||||
if TokenInfoString != '' and TokenInfoString != None:
|
||||
if TokenInfoString != '' and TokenInfoString is not None:
|
||||
TokenInfoList = GetSplitValueList(TokenInfoString, DataType.TAB_SPLIT)
|
||||
if len(TokenInfoList) == 2:
|
||||
return True
|
||||
@@ -433,7 +433,7 @@ def GetComponents(Lines, KeyValues, CommentCharacter):
|
||||
LineList = Lines.split('\n')
|
||||
for Line in LineList:
|
||||
Line = CleanString(Line, CommentCharacter)
|
||||
if Line == None or Line == '':
|
||||
if Line is None or Line == '':
|
||||
continue
|
||||
|
||||
if FindBlock == False:
|
||||
@@ -921,7 +921,7 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
|
||||
FileLocalMacros[Name] = Value
|
||||
|
||||
ReIsValidMacroName = re.compile(r"^[A-Z][A-Z0-9_]*$", re.DOTALL)
|
||||
if ReIsValidMacroName.match(Name) == None:
|
||||
if ReIsValidMacroName.match(Name) is None:
|
||||
Logger.Error('Parser',
|
||||
FORMAT_INVALID,
|
||||
ST.ERR_MACRONAME_INVALID % (Name),
|
||||
@@ -940,7 +940,7 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
|
||||
# <UnicodeString>, <CArray> are subset of <AsciiString>.
|
||||
#
|
||||
ReIsValidMacroValue = re.compile(r"^[\x20-\x7e]*$", re.DOTALL)
|
||||
if ReIsValidMacroValue.match(Value) == None:
|
||||
if ReIsValidMacroValue.match(Value) is None:
|
||||
Logger.Error('Parser',
|
||||
FORMAT_INVALID,
|
||||
ST.ERR_MACROVALUE_INVALID % (Value),
|
||||
@@ -979,7 +979,7 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
|
||||
else:
|
||||
Section = '[' + SectionName + ']'
|
||||
Content += '\n' + Section + '\n'
|
||||
if StatementList != None:
|
||||
if StatementList is not None:
|
||||
for Statement in StatementList:
|
||||
LineList = Statement.split('\n')
|
||||
NewStatement = ""
|
||||
|
@@ -166,7 +166,7 @@ def SplitModuleType(Key):
|
||||
#
|
||||
def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, Line=None, FileName=None, Flag=False):
|
||||
LastString = String
|
||||
if MacroDefinitions == None:
|
||||
if MacroDefinitions is None:
|
||||
MacroDefinitions = {}
|
||||
while MacroDefinitions:
|
||||
QuotedStringList = []
|
||||
@@ -244,7 +244,7 @@ def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, Line=None
|
||||
#
|
||||
def NormPath(Path, Defines=None):
|
||||
IsRelativePath = False
|
||||
if Defines == None:
|
||||
if Defines is None:
|
||||
Defines = {}
|
||||
if Path:
|
||||
if Path[0] == '.':
|
||||
@@ -524,7 +524,7 @@ def PreCheck(FileName, FileContent, SupSectionTag):
|
||||
# to be checked
|
||||
#
|
||||
def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line, LineNo= -1):
|
||||
if CheckFilename != '' and CheckFilename != None:
|
||||
if CheckFilename != '' and CheckFilename is not None:
|
||||
(Root, Ext) = os.path.splitext(CheckFilename)
|
||||
if Ext.upper() != ExtName.upper() and Root:
|
||||
ContainerFile = open(ContainerFilename, 'r').read()
|
||||
@@ -552,7 +552,7 @@ def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line,
|
||||
#
|
||||
def CheckFileExist(WorkspaceDir, CheckFilename, ContainerFilename, SectionName, Line, LineNo= -1):
|
||||
CheckFile = ''
|
||||
if CheckFilename != '' and CheckFilename != None:
|
||||
if CheckFilename != '' and CheckFilename is not None:
|
||||
CheckFile = WorkspaceFile(WorkspaceDir, CheckFilename)
|
||||
if not os.path.isfile(CheckFile):
|
||||
ContainerFile = open(ContainerFilename, 'r').read()
|
||||
|
@@ -161,7 +161,7 @@ def GetLanguageCode1766(LangName, File=None):
|
||||
for Key in gLANG_CONV_TABLE.keys():
|
||||
if gLANG_CONV_TABLE.get(Key) == LangName[0:2].lower():
|
||||
return Key
|
||||
if LangName[0:3].isalpha() and gLANG_CONV_TABLE.get(LangName.lower()) == None and LangName[3] == '-':
|
||||
if LangName[0:3].isalpha() and gLANG_CONV_TABLE.get(LangName.lower()) is None and LangName[3] == '-':
|
||||
for Key in gLANG_CONV_TABLE.keys():
|
||||
if Key == LangName[0:3].lower():
|
||||
return Key
|
||||
@@ -186,7 +186,7 @@ def GetLanguageCode(LangName, IsCompatibleMode, File):
|
||||
if IsCompatibleMode:
|
||||
if length == 3 and LangName.isalpha():
|
||||
TempLangName = gLANG_CONV_TABLE.get(LangName.lower())
|
||||
if TempLangName != None:
|
||||
if TempLangName is not None:
|
||||
return TempLangName
|
||||
return LangName
|
||||
else:
|
||||
@@ -200,7 +200,7 @@ def GetLanguageCode(LangName, IsCompatibleMode, File):
|
||||
if LangName.isalpha():
|
||||
return LangName
|
||||
elif length == 3:
|
||||
if LangName.isalpha() and gLANG_CONV_TABLE.get(LangName.lower()) == None:
|
||||
if LangName.isalpha() and gLANG_CONV_TABLE.get(LangName.lower()) is None:
|
||||
return LangName
|
||||
elif length == 5:
|
||||
if LangName[0:2].isalpha() and LangName[2] == '-':
|
||||
@@ -208,7 +208,7 @@ def GetLanguageCode(LangName, IsCompatibleMode, File):
|
||||
elif length >= 6:
|
||||
if LangName[0:2].isalpha() and LangName[2] == '-':
|
||||
return LangName
|
||||
if LangName[0:3].isalpha() and gLANG_CONV_TABLE.get(LangName.lower()) == None and LangName[3] == '-':
|
||||
if LangName[0:3].isalpha() and gLANG_CONV_TABLE.get(LangName.lower()) is None and LangName[3] == '-':
|
||||
return LangName
|
||||
|
||||
EdkLogger.Error("Unicode File Parser",
|
||||
@@ -270,14 +270,14 @@ class StringDefClassObject(object):
|
||||
self.UseOtherLangDef = UseOtherLangDef
|
||||
self.Length = 0
|
||||
|
||||
if Name != None:
|
||||
if Name is not None:
|
||||
self.StringName = Name
|
||||
self.StringNameByteList = UniToHexList(Name)
|
||||
if Value != None:
|
||||
if Value is not None:
|
||||
self.StringValue = Value
|
||||
self.StringValueByteList = UniToHexList(self.StringValue)
|
||||
self.Length = len(self.StringValueByteList)
|
||||
if Token != None:
|
||||
if Token is not None:
|
||||
self.Token = Token
|
||||
|
||||
def __str__(self):
|
||||
@@ -288,7 +288,7 @@ class StringDefClassObject(object):
|
||||
repr(self.UseOtherLangDef)
|
||||
|
||||
def UpdateValue(self, Value = None):
|
||||
if Value != None:
|
||||
if Value is not None:
|
||||
if self.StringValue:
|
||||
self.StringValue = self.StringValue + '\r\n' + Value
|
||||
else:
|
||||
@@ -393,7 +393,7 @@ class UniFileClassObject(object):
|
||||
# Check the string name is the upper character
|
||||
if Name != '':
|
||||
MatchString = re.match('[A-Z0-9_]+', Name, re.UNICODE)
|
||||
if MatchString == None or MatchString.end(0) != len(Name):
|
||||
if MatchString is None or MatchString.end(0) != len(Name):
|
||||
EdkLogger.Error("Unicode File Parser",
|
||||
ToolError.FORMAT_INVALID,
|
||||
'The string token name %s in UNI file %s must be upper case character.' %(Name, self.File))
|
||||
@@ -798,7 +798,7 @@ class UniFileClassObject(object):
|
||||
# Load a .uni file
|
||||
#
|
||||
def LoadUniFile(self, File = None):
|
||||
if File == None:
|
||||
if File is None:
|
||||
EdkLogger.Error("Unicode File Parser",
|
||||
ToolError.PARSER_ERROR,
|
||||
Message='No unicode file is given',
|
||||
@@ -901,7 +901,7 @@ class UniFileClassObject(object):
|
||||
IsAdded = True
|
||||
if Name in self.OrderedStringDict[Language]:
|
||||
IsAdded = False
|
||||
if Value != None:
|
||||
if Value is not None:
|
||||
ItemIndexInList = self.OrderedStringDict[Language][Name]
|
||||
Item = self.OrderedStringList[Language][ItemIndexInList]
|
||||
Item.UpdateValue(Value)
|
||||
|
@@ -36,14 +36,14 @@ import Logger.Log as Logger
|
||||
def CreateXmlElement(Name, String, NodeList, AttributeList):
|
||||
Doc = xml.dom.minidom.Document()
|
||||
Element = Doc.createElement(Name)
|
||||
if String != '' and String != None:
|
||||
if String != '' and String is not None:
|
||||
Element.appendChild(Doc.createTextNode(String))
|
||||
|
||||
for Item in NodeList:
|
||||
if type(Item) == type([]):
|
||||
Key = Item[0]
|
||||
Value = Item[1]
|
||||
if Key != '' and Key != None and Value != '' and Value != None:
|
||||
if Key != '' and Key is not None and Value != '' and Value is not None:
|
||||
Node = Doc.createElement(Key)
|
||||
Node.appendChild(Doc.createTextNode(Value))
|
||||
Element.appendChild(Node)
|
||||
@@ -52,7 +52,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList):
|
||||
for Item in AttributeList:
|
||||
Key = Item[0]
|
||||
Value = Item[1]
|
||||
if Key != '' and Key != None and Value != '' and Value != None:
|
||||
if Key != '' and Key is not None and Value != '' and Value is not None:
|
||||
Element.setAttribute(Key, Value)
|
||||
|
||||
return Element
|
||||
@@ -66,7 +66,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList):
|
||||
# @param String A XPath style path.
|
||||
#
|
||||
def XmlList(Dom, String):
|
||||
if String == None or String == "" or Dom == None or Dom == "":
|
||||
if String is None or String == "" or Dom is None or Dom == "":
|
||||
return []
|
||||
if Dom.nodeType == Dom.DOCUMENT_NODE:
|
||||
Dom = Dom.documentElement
|
||||
@@ -101,7 +101,7 @@ def XmlList(Dom, String):
|
||||
# @param String A XPath style path.
|
||||
#
|
||||
def XmlNode(Dom, String):
|
||||
if String == None or String == "" or Dom == None or Dom == "":
|
||||
if String is None or String == "" or Dom is None or Dom == "":
|
||||
return None
|
||||
if Dom.nodeType == Dom.DOCUMENT_NODE:
|
||||
Dom = Dom.documentElement
|
||||
|
Reference in New Issue
Block a user