]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Xml / XmlRoutines.py
index b93588eea61a12c099ee2e57a7a1127bca5b8cd8..b02f663b15a5752aa135f3f6b4d1fc398db3921d 100644 (file)
@@ -2,20 +2,16 @@
 # 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) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
 # Import Modules\r
 #\r
+from __future__ import print_function\r
 import xml.dom.minidom\r
+import codecs\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 ## Create a element of XML\r
@@ -30,14 +26,14 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 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
+\r
     for Item in NodeList:\r
-        if type(Item) == type([]):\r
+        if isinstance(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
@@ -46,9 +42,9 @@ 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
+\r
     return Element\r
 \r
 ## Get a list of XML nodes using XPath style syntax.\r
@@ -62,7 +58,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList):
 # @revel  Nodes              A list of XML nodes matching XPath style Sting.\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
@@ -98,7 +94,7 @@ def XmlList(Dom, String):
 # @revel  Node               A single XML node matching XPath style Sting.\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 ""\r
     if Dom.nodeType == Dom.DOCUMENT_NODE:\r
         Dom = Dom.documentElement\r
@@ -210,12 +206,12 @@ def XmlNodeName(Dom):
 #\r
 def XmlParseFile(FileName):\r
     try:\r
-        XmlFile = open(FileName)\r
+        XmlFile = codecs.open(FileName,encoding='utf_8_sig')\r
         Dom = xml.dom.minidom.parse(XmlFile)\r
         XmlFile.close()\r
         return Dom\r
-    except Exception, X:\r
-        print X\r
+    except Exception as X:\r
+        print(X)\r
         return ""\r
 \r
 # This acts like the main() function for the script, unless it is 'import'ed\r
@@ -225,5 +221,5 @@ if __name__ == '__main__':
     A = CreateXmlElement('AAA', 'CCC',  [['AAA', '111'], ['BBB', '222']], [['A', '1'], ['B', '2']])\r
     B = CreateXmlElement('ZZZ', 'CCC',  [['XXX', '111'], ['YYY', '222']], [['A', '1'], ['B', '2']])\r
     C = CreateXmlList('DDD', 'EEE', [A, B], ['FFF', 'GGG'])\r
-    print C.toprettyxml(indent = " ")\r
+    print(C.toprettyxml(indent = " "))\r
     pass\r