]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Expression.py
BaseTools: Fix old python2 idioms
[mirror_edk2.git] / BaseTools / Source / Python / Common / Expression.py
index 9ff4f104256e7d84e5ae955a371eb3cd3e62850d..e1a2c155b7f3d94afa62997413d8a1f6f6b43480 100644 (file)
@@ -245,12 +245,12 @@ class ValueExpression(BaseExpression):
         WrnExp = None\r
 \r
         if Operator not in {"==", "!=", ">=", "<=", ">", "<", "in", "not in"} and \\r
-            (type(Oprand1) == type('') or type(Oprand2) == type('')):\r
+            (isinstance(Oprand1, type('')) or isinstance(Oprand2, type(''))):\r
             raise BadExpression(ERR_STRING_EXPR % Operator)\r
         if Operator in {'in', 'not in'}:\r
-            if type(Oprand1) != type(''):\r
+            if not isinstance(Oprand1, type('')):\r
                 Oprand1 = IntToStr(Oprand1)\r
-            if type(Oprand2) != type(''):\r
+            if not isinstance(Oprand2, type('')):\r
                 Oprand2 = IntToStr(Oprand2)\r
         TypeDict = {\r
             type(0)  : 0,\r
@@ -261,18 +261,18 @@ class ValueExpression(BaseExpression):
 \r
         EvalStr = ''\r
         if Operator in {"!", "NOT", "not"}:\r
-            if type(Oprand1) == type(''):\r
+            if isinstance(Oprand1, type('')):\r
                 raise BadExpression(ERR_STRING_EXPR % Operator)\r
             EvalStr = 'not Oprand1'\r
         elif Operator in {"~"}:\r
-            if type(Oprand1) == type(''):\r
+            if isinstance(Oprand1, type('')):\r
                 raise BadExpression(ERR_STRING_EXPR % Operator)\r
             EvalStr = '~ Oprand1'\r
         else:\r
             if Operator in {"+", "-"} and (type(True) in {type(Oprand1), type(Oprand2)}):\r
                 # Boolean in '+'/'-' will be evaluated but raise warning\r
                 WrnExp = WrnExpression(WRN_BOOL_EXPR)\r
-            elif type('') in {type(Oprand1), type(Oprand2)} and type(Oprand1)!= type(Oprand2):\r
+            elif type('') in {type(Oprand1), type(Oprand2)} and not isinstance(Oprand1, type(Oprand2)):\r
                 # == between string and number/boolean will always return False, != return True\r
                 if Operator == "==":\r
                     WrnExp = WrnExpression(WRN_EQCMP_STR_OTHERS)\r
@@ -293,11 +293,11 @@ class ValueExpression(BaseExpression):
                     pass\r
                 else:\r
                     raise BadExpression(ERR_EXPR_TYPE)\r
-            if type(Oprand1) == type('') and type(Oprand2) == type(''):\r
+            if isinstance(Oprand1, type('')) and isinstance(Oprand2, type('')):\r
                 if (Oprand1.startswith('L"') and not Oprand2.startswith('L"')) or \\r
                     (not Oprand1.startswith('L"') and Oprand2.startswith('L"')):\r
                     raise BadExpression(ERR_STRING_CMP % (Oprand1, Operator, Oprand2))\r
-            if 'in' in Operator and type(Oprand2) == type(''):\r
+            if 'in' in Operator and isinstance(Oprand2, type('')):\r
                 Oprand2 = Oprand2.split()\r
             EvalStr = 'Oprand1 ' + Operator + ' Oprand2'\r
 \r
@@ -325,7 +325,7 @@ class ValueExpression(BaseExpression):
     def __init__(self, Expression, SymbolTable={}):\r
         super(ValueExpression, self).__init__(self, Expression, SymbolTable)\r
         self._NoProcess = False\r
-        if type(Expression) != type(''):\r
+        if not isinstance(Expression, type('')):\r
             self._Expr = Expression\r
             self._NoProcess = True\r
             return\r
@@ -373,7 +373,7 @@ class ValueExpression(BaseExpression):
                 Token = self._GetToken()\r
             except BadExpression:\r
                 pass\r
-            if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len:\r
+            if isinstance(Token, type('')) and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len:\r
                 return self._Expr\r
 \r
             self._Idx = 0\r
@@ -381,7 +381,7 @@ class ValueExpression(BaseExpression):
 \r
         Val = self._ConExpr()\r
         RealVal = Val\r
-        if type(Val) == type(''):\r
+        if isinstance(Val, type('')):\r
             if Val == 'L""':\r
                 Val = False\r
             elif not Val:\r
@@ -640,7 +640,7 @@ class ValueExpression(BaseExpression):
                 Ex.Pcd = self._Token\r
                 raise Ex\r
             self._Token = ValueExpression(self._Symb[self._Token], self._Symb)(True, self._Depth+1)\r
-            if type(self._Token) != type(''):\r
+            if not isinstance(self._Token, type('')):\r
                 self._LiteralToken = hex(self._Token)\r
                 return\r
 \r
@@ -735,7 +735,7 @@ class ValueExpression(BaseExpression):
                 if Ch == ')':\r
                     TmpValue = self._Expr[Idx :self._Idx - 1]\r
                     TmpValue = ValueExpression(TmpValue)(True)\r
-                    TmpValue = '0x%x' % int(TmpValue) if type(TmpValue) != type('') else TmpValue\r
+                    TmpValue = '0x%x' % int(TmpValue) if not isinstance(TmpValue, type('')) else TmpValue\r
                     break\r
             self._Token, Size = ParseFieldValue(Prefix + '(' + TmpValue + ')')\r
             return  self._Token\r
@@ -824,7 +824,7 @@ class ValueExpressionEx(ValueExpression):
                 PcdValue = PcdValue.strip()\r
                 if PcdValue.startswith('{') and PcdValue.endswith('}'):\r
                     PcdValue = SplitPcdValueString(PcdValue[1:-1])\r
-                if type(PcdValue) == type([]):\r
+                if isinstance(PcdValue, type([])):\r
                     TmpValue = 0\r
                     Size = 0\r
                     ValueType = ''\r
@@ -863,7 +863,7 @@ class ValueExpressionEx(ValueExpression):
                         else:\r
                             ItemValue = ParseFieldValue(Item)[0]\r
 \r
-                        if type(ItemValue) == type(''):\r
+                        if isinstance(ItemValue, type('')):\r
                             ItemValue = int(ItemValue, 0)\r
 \r
                         TmpValue = (ItemValue << (Size * 8)) | TmpValue\r
@@ -873,7 +873,7 @@ class ValueExpressionEx(ValueExpression):
                         TmpValue, Size = ParseFieldValue(PcdValue)\r
                     except BadExpression as Value:\r
                         raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value))\r
-                if type(TmpValue) == type(''):\r
+                if isinstance(TmpValue, type('')):\r
                     try:\r
                         TmpValue = int(TmpValue)\r
                     except:\r
@@ -996,7 +996,7 @@ class ValueExpressionEx(ValueExpression):
                                     TmpValue = ValueExpressionEx(Item, ValueType, self._Symb)(True)\r
                                 else:\r
                                     TmpValue = ValueExpressionEx(Item, self.PcdType, self._Symb)(True)\r
-                                Item = '0x%x' % TmpValue if type(TmpValue) != type('') else TmpValue\r
+                                Item = '0x%x' % TmpValue if not isinstance(TmpValue, type('')) else TmpValue\r
                                 if ItemSize == 0:\r
                                     ItemValue, ItemSize = ParseFieldValue(Item)\r
                                     if Item[0] not in {'"', 'L', '{'} and ItemSize > 1:\r