]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Parsing.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / Common / Parsing.py
index 5bea6941fdf77e0a9047342cb20ed6927a0787df..d858501af6c10aa432d99f789963b271287d893a 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define common parsing related functions used in parsing INF/DEC/DSC process\r
 #\r
-# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
 ##\r
 # Import Modules\r
 #\r
-from String import *\r
+from __future__ import absolute_import\r
+from .StringUtils import *\r
 from CommonDataClass.DataClass import *\r
-from DataType import *\r
+from .DataType import *\r
 \r
 ## ParseDefineMacro\r
 #\r
@@ -35,18 +36,16 @@ def ParseDefineMacro2(Table, RecordSets, GlobalMacro):
         Macros[Record[0]] = Record[1]\r
 \r
     #\r
-    # Overrided by Global Macros\r
+    # Overridden by Global Macros\r
     #\r
-    for Key in GlobalMacro.keys():\r
-        Macros[Key] = GlobalMacro[Key]\r
+    Macros.update(GlobalMacro)\r
 \r
     #\r
     # Replace the Macros\r
     #\r
-    for Key in RecordSets.keys():\r
-        if RecordSets[Key] != []:\r
-            for Item in RecordSets[Key]:\r
-                Item[0] = ReplaceMacro(Item[0], Macros)\r
+    for Value in (v for v in RecordSets.values() if v):\r
+        for Item in Value:\r
+            Item[0] = ReplaceMacro(Item[0], Macros)\r
 \r
 ## ParseDefineMacro\r
 #\r
@@ -77,10 +76,9 @@ def ParseDefineMacro(Table, GlobalMacro):
         Macros[Record[0]] = Record[1]\r
 \r
     #\r
-    # Overrided by Global Macros\r
+    # Overridden by Global Macros\r
     #\r
-    for Key in GlobalMacro.keys():\r
-        Macros[Key] = GlobalMacro[Key]\r
+    Macros.update(GlobalMacro)\r
 \r
     #\r
     # Found all defined macro and replaced\r
@@ -299,7 +297,7 @@ def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo = -1):
 #\r
 def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo = -1):\r
     Format = '<TokenSpaceGuidCName>.<PcdCName>'\r
-    if TokenInfoString != '' and TokenInfoString != None:\r
+    if TokenInfoString != '' and TokenInfoString is not None:\r
         TokenInfoList = GetSplitValueList(TokenInfoString, TAB_SPLIT)\r
         if len(TokenInfoList) == 2:\r
             return True\r
@@ -550,7 +548,7 @@ def GetComponents(Lines, Key, KeyValues, CommentCharacter):
     LineList = Lines.split('\n')\r
     for Line in LineList:\r
         Line = CleanString(Line, CommentCharacter)\r
-        if Line == None or Line == '':\r
+        if Line is None or Line == '':\r
             continue\r
 \r
         if findBlock == False:\r
@@ -832,7 +830,7 @@ def InsertSectionItems(Model, CurrentSection, SectionItemList, ArchList, ThirdLi
 # @param Table:            The Table to be inserted\r
 # @param FileID:           The ID of belonging file\r
 # @param Filename:         The name of belonging file\r
-# @param CurrentSection:   The name of currect section\r
+# @param CurrentSection:   The name of current section\r
 # @param SectionItemList:  A list of items of the section\r
 # @param ArchList:         A list of arches\r
 # @param ThirdList:        A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds\r
@@ -877,3 +875,38 @@ def GenMetaDatSectionItem(Key, Value, List):
         List[Key] = [Value]\r
     else:\r
         List[Key].append(Value)\r
+\r
+## IsValidWord\r
+#\r
+# Check whether the word is valid.\r
+# <Word>   ::=  (a-zA-Z0-9_)(a-zA-Z0-9_-){0,} Alphanumeric characters with\r
+#               optional\r
+#               dash "-" and/or underscore "_" characters. No whitespace\r
+#               characters are permitted.\r
+#\r
+# @param Word:  The word string need to be checked.\r
+#\r
+def IsValidWord(Word):\r
+    if not Word:\r
+        return False\r
+    #\r
+    # The first char should be alpha, _ or Digit.\r
+    #\r
+    if not Word[0].isalnum() and \\r
+       not Word[0] == '_' and \\r
+       not Word[0].isdigit():\r
+        return False\r
+\r
+    LastChar = ''\r
+    for Char in Word[1:]:\r
+        if (not Char.isalpha()) and \\r
+           (not Char.isdigit()) and \\r
+           Char != '-' and \\r
+           Char != '_' and \\r
+           Char != '.':\r
+            return False\r
+        if Char == '.' and LastChar == '.':\r
+            return False\r
+        LastChar = Char\r
+\r
+    return True\r