public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Yonghong Zhu <yonghong.zhu@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH v1 1/4] BaseTools: change hex parsing to use built in
Date: Thu, 29 Mar 2018 17:19:30 -0700	[thread overview]
Message-ID: <4ef8852109dfd963d92ea4f55bbebd8f2275fe58.1522369072.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1522369072.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1522369072.git.jaben.carsey@intel.com>

use <char> in string.hexdigits instead of custom functions.

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>
---
 BaseTools/Source/Python/Common/FdfParserLite.py | 26 +++-----------------
 BaseTools/Source/Python/GenFds/FdfParser.py     | 26 +++-----------------
 2 files changed, 8 insertions(+), 44 deletions(-)

diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py
index b7b5e21a9e3f..4638916fab2c 100644
--- a/BaseTools/Source/Python/Common/FdfParserLite.py
+++ b/BaseTools/Source/Python/Common/FdfParserLite.py
@@ -23,6 +23,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.MultipleWorkspace import MultipleWorkspace as mws
 from Common.RangeExpression import RangeExpression
 from Common.GlobalData import *
+import string
 
 ##define T_CHAR_SPACE                ' '
 ##define T_CHAR_NULL                 '\0'
@@ -974,32 +975,13 @@ class FdfParser(object):
             
         self.__GetOneChar()
     
-    ## __HexDigit() method
-    #
-    #   Whether char input is a Hex data bit
-    #
-    #   @param  self        The object pointer
-    #   @param  TempChar    The char to test
-    #   @retval True        The char is a Hex data bit
-    #   @retval False       The char is NOT a Hex data bit
-    #
-    def __HexDigit(self, TempChar):
-        if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \
-                or (TempChar >= '0' and TempChar <= '9'):
-                    return True
-        else:
-            return False
-    
     def __IsHex(self, HexStr):
         if not HexStr.upper().startswith("0X"):
             return False
         if len(self.__Token) <= 2:
             return False
-        charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]
-        if len(charList) == 0:
-            return True
-        else:
-            return False    
+        return True if all(x in string.hexdigits for x in HexStr[2:]) else False
+
     ## __GetNextHexNumber() method
     #
     #   Get next HEX data before a seperator
@@ -3457,7 +3439,7 @@ class FdfParser(object):
             raise Warning("expected Component type At Line ", self.FileName, self.CurrentLineNumber)
         if self.__Token not in ("FIT", "PAL_B", "PAL_A", "OEM"):
             if not self.__Token.startswith("0x") or len(self.__Token) < 3 or len(self.__Token) > 4 or \
-                not self.__HexDigit(self.__Token[2]) or not self.__HexDigit(self.__Token[-1]):
+                not self.__Token[2] in string.hexdigits or not self.__Token[-1] in string.hexdigits:
                 raise Warning("Unknown location type At line ", self.FileName, self.CurrentLineNumber)
         CompStatementObj.CompType = self.__Token
         
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 9903e9570cf9..4dc686922b5a 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -42,6 +42,7 @@ import ComponentStatement
 import OptionRom
 import OptRomInfStatement
 import OptRomFileStatement
+import string
 
 from GenFdsGlobalVariable import GenFdsGlobalVariable
 from Common.BuildToolError import *
@@ -1195,32 +1196,13 @@ class FdfParser:
 
         self.__GetOneChar()
 
-    ## __HexDigit() method
-    #
-    #   Whether char input is a Hex data bit
-    #
-    #   @param  self        The object pointer
-    #   @param  TempChar    The char to test
-    #   @retval True        The char is a Hex data bit
-    #   @retval False       The char is NOT a Hex data bit
-    #
-    def __HexDigit(self, TempChar):
-        if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \
-                or (TempChar >= '0' and TempChar <= '9'):
-                    return True
-        else:
-            return False
-
     def __IsHex(self, HexStr):
         if not HexStr.upper().startswith("0X"):
             return False
         if len(self.__Token) <= 2:
             return False
-        charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]
-        if len(charList) == 0:
-            return True
-        else:
-            return False
+        return True if all(x in string.hexdigits for x in HexStr[2:]) else False
+
     ## __GetNextHexNumber() method
     #
     #   Get next HEX data before a seperator
@@ -4299,7 +4281,7 @@ class FdfParser:
             raise Warning("expected Component type", self.FileName, self.CurrentLineNumber)
         if self.__Token not in ("FIT", "PAL_B", "PAL_A", "OEM"):
             if not self.__Token.startswith("0x") or len(self.__Token) < 3 or len(self.__Token) > 4 or \
-                not self.__HexDigit(self.__Token[2]) or not self.__HexDigit(self.__Token[-1]):
+                not self.__Token[2] in string.hexdigits or not self.__Token[-1] in string.hexdigits:
                 raise Warning("Unknown location type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
         CompStatementObj.CompType = self.__Token
 
-- 
2.16.2.windows.1



  reply	other threads:[~2018-03-30  0:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30  0:19 [PATCH v1 0/4] BaseTools: remove un-needed code Jaben Carsey
2018-03-30  0:19 ` Jaben Carsey [this message]
2018-03-30  0:19 ` [PATCH v1 2/4] BaseTools: remove uncalled function Jaben Carsey
2018-03-30  0:19 ` [PATCH v1 3/4] BaseTools: make static functions when self is not needed Jaben Carsey
2018-03-30  0:19 ` [PATCH v1 4/4] BaseTools: remove uncalled functions Jaben Carsey
2018-04-03  9:26 ` [PATCH v1 0/4] BaseTools: remove un-needed code Zhu, Yonghong

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=4ef8852109dfd963d92ea4f55bbebd8f2275fe58.1522369072.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