]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
BaseTools: Replace StringIO.StringIO with io.BytesIO
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / ValidCheckingInfoObject.py
index 2f8f4fac23f8c59ac9b2392ac172e1d0f80ef4d9..49fbdf3246a584fd895ce26f335230e71aad786b 100644 (file)
@@ -17,7 +17,7 @@
 import os\r
 from Common.RangeExpression import RangeExpression\r
 from Common.Misc import *\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from struct import pack\r
 from Common.DataType import *\r
 \r
@@ -35,12 +35,6 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
     \r
     def dump(self, dest, Phase):\r
         \r
-        FormatMap = {}\r
-        FormatMap[1] = "=B"\r
-        FormatMap[2] = "=H"\r
-        FormatMap[4] = "=L"\r
-        FormatMap[8] = "=Q"\r
-        \r
         if not os.path.isabs(dest):\r
             return\r
         if not os.path.exists(dest):\r
@@ -106,19 +100,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
             realLength += 4\r
 \r
             Guid = var_check_tab.Guid\r
-            b = pack('=LHHBBBBBBBB',\r
-                Guid[0],\r
-                Guid[1],\r
-                Guid[2],\r
-                Guid[3],\r
-                Guid[4],\r
-                Guid[5],\r
-                Guid[6],\r
-                Guid[7],\r
-                Guid[8],\r
-                Guid[9],\r
-                Guid[10],\r
-                )\r
+            b = PackByteFormatGUID(Guid)\r
             Buffer += b\r
             realLength += 16\r
 \r
@@ -156,14 +138,14 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
                 realLength += 1\r
                 for v_data in item.data:\r
                     if type(v_data) in (int, long):\r
-                        b = pack(FormatMap[item.StorageWidth], v_data)\r
+                        b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data)\r
                         Buffer += b\r
                         realLength += item.StorageWidth\r
                     else:\r
-                        b = pack(FormatMap[item.StorageWidth], v_data[0])\r
+                        b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data[0])\r
                         Buffer += b\r
                         realLength += item.StorageWidth\r
-                        b = pack(FormatMap[item.StorageWidth], v_data[1])\r
+                        b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data[1])\r
                         Buffer += b\r
                         realLength += item.StorageWidth\r
 \r
@@ -180,7 +162,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
                             Buffer += b\r
                             realLength += 1\r
         \r
-        DbFile = StringIO()\r
+        DbFile = BytesIO()\r
         if Phase == 'DXE' and os.path.exists(BinFilePath):\r
             BinFile = open(BinFilePath, "rb")\r
             BinBuffer = BinFile.read()\r
@@ -244,16 +226,12 @@ class VAR_CHECK_PCD_VALID_OBJ(object):
         self.Type = 1\r
         self.Length = 0  # Length include this header\r
         self.VarOffset = VarOffset\r
-        self.StorageWidth = 0\r
         self.PcdDataType = PcdDataType.strip()\r
         self.rawdata = data\r
         self.data = set()\r
-        self.ValidData = True\r
-        self.updateStorageWidth()\r
-\r
-    def updateStorageWidth(self):\r
         try:\r
             self.StorageWidth = MAX_SIZE_TYPE[self.PcdDataType]\r
+            self.ValidData = True\r
         except:\r
             self.StorageWidth = 0\r
             self.ValidData = False\r
@@ -265,11 +243,7 @@ class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ):
     def __init__(self, VarOffset, validlist, PcdDataType):\r
         super(VAR_CHECK_PCD_VALID_LIST, self).__init__(VarOffset, validlist, PcdDataType)\r
         self.Type = 1\r
-        self.update_data()\r
-        self.update_size()\r
-    def update_data(self):\r
         valid_num_list = []\r
-        data_list = []\r
         for item in self.rawdata:\r
             valid_num_list.extend(item.split(','))\r
         \r
@@ -277,14 +251,11 @@ class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ):
             valid_num = valid_num.strip()\r
 \r
             if valid_num.startswith('0x') or valid_num.startswith('0X'):\r
-                data_list.append(int(valid_num, 16))\r
+                self.data.add(int(valid_num, 16))\r
             else:\r
-                data_list.append(int(valid_num))\r
+                self.data.add(int(valid_num))\r
 \r
                 \r
-        self.data = set(data_list)\r
-        \r
-    def update_size(self):\r
         self.Length = 5 + len(self.data) * self.StorageWidth\r
         \r
            \r
@@ -292,11 +263,7 @@ class VAR_CHECK_PCD_VALID_RANGE(VAR_CHECK_PCD_VALID_OBJ):
     def __init__(self, VarOffset, validrange, PcdDataType):\r
         super(VAR_CHECK_PCD_VALID_RANGE, self).__init__(VarOffset, validrange, PcdDataType)\r
         self.Type = 2\r
-        self.update_data()\r
-        self.update_size()\r
-    def update_data(self):\r
         RangeExpr = ""\r
-        data_list = []\r
         i = 0\r
         for item in self.rawdata:\r
             if i == 0:\r
@@ -306,21 +273,14 @@ class VAR_CHECK_PCD_VALID_RANGE(VAR_CHECK_PCD_VALID_OBJ):
         range_result = RangeExpression(RangeExpr, self.PcdDataType)(True)\r
         for rangelist in range_result:\r
             for obj in rangelist.pop():\r
-                data_list.append((obj.start, obj.end))\r
-        self.data = set(data_list)\r
-    \r
-    def update_size(self):\r
+                self.data.add((obj.start, obj.end))\r
         self.Length = 5 + len(self.data) * 2 * self.StorageWidth\r
         \r
 \r
-class VAR_VALID_OBJECT_FACTORY(object):\r
-    def __init__(self):\r
-        pass\r
-    @staticmethod\r
-    def Get_valid_object(PcdClass, VarOffset):\r
-        if PcdClass.validateranges:\r
-            return VAR_CHECK_PCD_VALID_RANGE(VarOffset, PcdClass.validateranges, PcdClass.DatumType)\r
-        if PcdClass.validlists:\r
-            return VAR_CHECK_PCD_VALID_LIST(VarOffset, PcdClass.validlists, PcdClass.DatumType)\r
-        else:\r
-            return None\r
+def GetValidationObject(PcdClass, VarOffset):\r
+    if PcdClass.validateranges:\r
+        return VAR_CHECK_PCD_VALID_RANGE(VarOffset, PcdClass.validateranges, PcdClass.DatumType)\r
+    if PcdClass.validlists:\r
+        return VAR_CHECK_PCD_VALID_LIST(VarOffset, PcdClass.validlists, PcdClass.DatumType)\r
+    else:\r
+        return None\r