]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py
BaseTools: Refactor python except statements
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / Xml / XmlRoutines.py
index 7029e59889726f88fd6a91e1c70b806f6348d345..1096bc5b18498c99ce37f24a22242932d8843df1 100644 (file)
@@ -2,7 +2,7 @@
 # This is an XML API that uses a syntax similar to XPath, but it is written in\r
 # standard python so that no extra python packages are required to use it.\r
 #\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
@@ -22,6 +22,7 @@ XmlRoutines
 #\r
 import xml.dom.minidom\r
 import re\r
+import codecs\r
 from Logger.ToolError import PARSER_ERROR\r
 import Logger.Log as Logger\r
 \r
@@ -35,14 +36,14 @@ import Logger.Log as Logger
 def CreateXmlElement(Name, String, NodeList, AttributeList):\r
     Doc = xml.dom.minidom.Document()\r
     Element = Doc.createElement(Name)\r
-    if String != '' and String != None:\r
+    if String != '' and String is not None:\r
         Element.appendChild(Doc.createTextNode(String))\r
 \r
     for Item in NodeList:\r
         if type(Item) == type([]):\r
             Key = Item[0]\r
             Value = Item[1]\r
-            if Key != '' and Key != None and Value != '' and Value != None:\r
+            if Key != '' and Key is not None and Value != '' and Value is not None:\r
                 Node = Doc.createElement(Key)\r
                 Node.appendChild(Doc.createTextNode(Value))\r
                 Element.appendChild(Node)\r
@@ -51,7 +52,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList):
     for Item in AttributeList:\r
         Key = Item[0]\r
         Value = Item[1]\r
-        if Key != '' and Key != None and Value != '' and Value != None:\r
+        if Key != '' and Key is not None and Value != '' and Value is not None:\r
             Element.setAttribute(Key, Value)\r
 \r
     return Element\r
@@ -65,7 +66,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList):
 # @param  String             A XPath style path.\r
 #\r
 def XmlList(Dom, String):\r
-    if String == None or String == "" or Dom == None or Dom == "":\r
+    if String is None or String == "" or Dom is None or Dom == "":\r
         return []\r
     if Dom.nodeType == Dom.DOCUMENT_NODE:\r
         Dom = Dom.documentElement\r
@@ -100,7 +101,7 @@ def XmlList(Dom, String):
 # @param  String             A XPath style path.\r
 #\r
 def XmlNode(Dom, String):\r
-    if String == None or String == ""  or Dom == None or Dom == "":\r
+    if String is None or String == ""  or Dom is None or Dom == "":\r
         return None\r
     if Dom.nodeType == Dom.DOCUMENT_NODE:\r
         Dom = Dom.documentElement\r
@@ -219,10 +220,10 @@ def XmlNodeName(Dom):
 #\r
 def XmlParseFile(FileName):\r
     try:\r
-        XmlFile = open(FileName)\r
+        XmlFile = codecs.open(FileName, 'rb')\r
         Dom = xml.dom.minidom.parse(XmlFile)\r
         XmlFile.close()\r
         return Dom\r
-    except BaseException, XExcept:\r
+    except BaseException as XExcept:\r
         XmlFile.close()\r
         Logger.Error('\nUPT', PARSER_ERROR, XExcept, File=FileName, RaiseError=True)\r