Fd = open(File, "wb")\r
Fd.write(Content)\r
Fd.close()\r
- except IOError, X:\r
+ except IOError as X:\r
EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s' % X)\r
\r
return True\r
try:\r
Fd = open(File, 'rb')\r
Data = cPickle.load(Fd)\r
- except Exception, e:\r
+ except Exception as e:\r
EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e)))\r
Data = None\r
finally:\r
def Append(self, AppendString, Dictionary=None):\r
if Dictionary:\r
SectionList = self._Parse(AppendString)\r
- self.String += "".join([S.Instantiate(Dictionary) for S in SectionList])\r
+ self.String += "".join(S.Instantiate(Dictionary) for S in SectionList)\r
else:\r
self.String += AppendString\r
\r
# @retval str The string replaced with placeholder values\r
#\r
def Replace(self, Dictionary=None):\r
- return "".join([S.Instantiate(Dictionary) for S in self._TemplateSectionList])\r
+ return "".join(S.Instantiate(Dictionary) for S in self._TemplateSectionList)\r
\r
## Progress indicator class\r
#\r
\r
def IsFieldValueAnArray (Value):\r
Value = Value.strip()\r
- if Value.startswith('GUID') and Value.endswith(')'):\r
+ if Value.startswith(TAB_GUID) and Value.endswith(')'):\r
return True\r
if Value.startswith('L"') and Value.endswith('"') and len(list(Value[2:-1])) > 1:\r
return True\r
try:\r
p = subprocess.Popen(Cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\r
out, err = p.communicate()\r
- except Exception, X:\r
+ except Exception as X:\r
raise BadExpression("DevicePath: %s" % (str(X)) )\r
finally:\r
subprocess._cleanup()\r
def ParseFieldValue (Value):\r
if type(Value) == type(0):\r
return Value, (Value.bit_length() + 7) / 8\r
- if type(Value) <> type(''):\r
+ if type(Value) != type(''):\r
raise BadExpression('Type %s is %s' %(Value, type(Value)))\r
Value = Value.strip()\r
if Value.startswith(TAB_UINT8) and Value.endswith(')'):\r
if Size > 8:\r
raise BadExpression('Value (%s) Size larger than %d' % (Value, Size))\r
return Value, 8\r
- if Value.startswith('GUID') and Value.endswith(')'):\r
+ if Value.startswith(TAB_GUID) and Value.endswith(')'):\r
Value = Value.split('(', 1)[1][:-1].strip()\r
if Value[0] == '{' and Value[-1] == '}':\r
TmpValue = GuidStructureStringToGuidString(Value)\r
Value = Value[1:-1]\r
try:\r
Value = "'" + uuid.UUID(Value).get_bytes_le() + "'"\r
- except ValueError, Message:\r
- raise BadExpression('%s' % Message)\r
+ except ValueError as Message:\r
+ raise BadExpression(Message)\r
Value, Size = ParseFieldValue(Value)\r
return Value, 16\r
if Value.startswith('L"') and Value.endswith('"'):\r
if not self.DefaultStores or "0" in self.DefaultStores:\r
return "0",TAB_DEFAULT_STORES_DEFAULT\r
else:\r
- minvalue = min([int(value_str) for value_str in self.DefaultStores])\r
+ minvalue = min(int(value_str) for value_str in self.DefaultStores)\r
return (str(minvalue), self.DefaultStores[str(minvalue)])\r
def GetMin(self,DefaultSIdList):\r
if not DefaultSIdList:\r
skuorderset.append(self.GetSkuChain(skuname))\r
\r
skuorder = []\r
- for index in range(max([len(item) for item in skuorderset])):\r
+ for index in range(max(len(item) for item in skuorderset)):\r
for subset in skuorderset:\r
if index > len(subset)-1:\r
continue\r
# Pack a registry format GUID\r
#\r
def PackRegistryFormatGuid(Guid):\r
- Guid = Guid.split('-')\r
- return pack('=LHHBBBBBBBB',\r
- int(Guid[0], 16),\r
- int(Guid[1], 16),\r
- int(Guid[2], 16),\r
- int(Guid[3][-4:-2], 16),\r
- int(Guid[3][-2:], 16),\r
- int(Guid[4][-12:-10], 16),\r
- int(Guid[4][-10:-8], 16),\r
- int(Guid[4][-8:-6], 16),\r
- int(Guid[4][-6:-4], 16),\r
- int(Guid[4][-4:-2], 16),\r
- int(Guid[4][-2:], 16)\r
- )\r
+ return PackGUID(Guid.split('-'))\r
\r
## Get the integer value from string like "14U" or integer like 2\r
#\r
else:\r
return int(String)\r
\r
+#\r
+# Pack a GUID (registry format) list into a buffer and return it\r
+#\r
+def PackGUID(Guid):\r
+ return pack(PACK_PATTERN_GUID,\r
+ int(Guid[0], 16),\r
+ int(Guid[1], 16),\r
+ int(Guid[2], 16),\r
+ int(Guid[3][-4:-2], 16),\r
+ int(Guid[3][-2:], 16),\r
+ int(Guid[4][-12:-10], 16),\r
+ int(Guid[4][-10:-8], 16),\r
+ int(Guid[4][-8:-6], 16),\r
+ int(Guid[4][-6:-4], 16),\r
+ int(Guid[4][-4:-2], 16),\r
+ int(Guid[4][-2:], 16)\r
+ )\r
+\r
+#\r
+# Pack a GUID (byte) list into a buffer and return it\r
+#\r
+def PackByteFormatGUID(Guid):\r
+ return pack(PACK_PATTERN_GUID,\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
+\r
##\r
#\r
# This acts like the main() function for the script, unless it is 'import'ed into another\r