]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/UniClassObject.py
python: Replace distutils.utils.split_quotes with shlex.split
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / UniClassObject.py
index 384f31b165de08222f36e8f5330549ec7182da7e..b16330e36825453ceaa9f3126cc95fd7a1be3cf1 100644 (file)
@@ -5,20 +5,14 @@
 # Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR>\r
 #\r
 # Copyright (c) 2007 - 2018, 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
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 ##\r
 # Import Modules\r
 #\r
 from __future__ import print_function\r
 import Common.LongFilePathOs as os, codecs, re\r
-import distutils.util\r
+import shlex\r
 import Common.EdkLogger as EdkLogger\r
 from io import BytesIO\r
 from Common.BuildToolError import *\r
@@ -46,18 +40,6 @@ BACK_SLASH_PLACEHOLDER = u'\u0006'
 \r
 gIncludePattern = re.compile("^#include +[\"<]+([^\"< >]+)[>\"]+$", re.MULTILINE | re.UNICODE)\r
 \r
-## Convert a python unicode string to a normal string\r
-#\r
-# Convert a python unicode string to a normal string\r
-# UniToStr(u'I am a string') is 'I am a string'\r
-#\r
-# @param Uni:  The python unicode string\r
-#\r
-# @retval:     The formatted normal string\r
-#\r
-def UniToStr(Uni):\r
-    return repr(Uni)[2:-1]\r
-\r
 ## Convert a unicode string to a Hex list\r
 #\r
 # Convert a unicode string to a Hex list\r
@@ -111,12 +93,12 @@ LangConvTable = {'eng':'en', 'fra':'fr', \
 ## GetLanguageCode\r
 #\r
 # Check the language code read from .UNI file and convert ISO 639-2 codes to RFC 4646 codes if appropriate\r
-# ISO 639-2 language codes supported in compatiblity mode\r
+# ISO 639-2 language codes supported in compatibility mode\r
 # RFC 4646 language codes supported in native mode\r
 #\r
 # @param LangName:   Language codes read from .UNI file\r
 #\r
-# @retval LangName:  Valid lanugage code in RFC 4646 format or None\r
+# @retval LangName:  Valid language code in RFC 4646 format or None\r
 #\r
 def GetLanguageCode(LangName, IsCompatibleMode, File):\r
     length = len(LangName)\r
@@ -170,7 +152,7 @@ class Ucs2Codec(codecs.Codec):
 \r
 TheUcs2Codec = Ucs2Codec()\r
 def Ucs2Search(name):\r
-    if name == 'ucs-2':\r
+    if name in ['ucs-2', 'ucs_2']:\r
         return codecs.CodecInfo(\r
             name=name,\r
             encode=TheUcs2Codec.encode,\r
@@ -251,7 +233,7 @@ class UniFileClassObject(object):
     # Get Language definition\r
     #\r
     def GetLangDef(self, File, Line):\r
-        Lang = distutils.util.split_quoted((Line.split(u"//")[0]))\r
+        Lang = shlex.split(Line.split(u"//")[0])\r
         if len(Lang) != 3:\r
             try:\r
                 FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path))\r
@@ -389,13 +371,12 @@ class UniFileClassObject(object):
     # Pre-process before parse .uni file\r
     #\r
     def PreProcess(self, File):\r
-        if not os.path.exists(File.Path) or not os.path.isfile(File.Path):\r
-            EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path)\r
-\r
         try:\r
             FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path))\r
         except UnicodeError as X:\r
             EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path);\r
+        except OSError:\r
+            EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path)\r
         except:\r
             EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File.Path);\r
 \r
@@ -439,7 +420,7 @@ class UniFileClassObject(object):
                 if EndPos != -1 and EndPos - StartPos == 6 :\r
                     if g4HexChar.match(Line[StartPos + 2 : EndPos], re.UNICODE):\r
                         EndStr = Line[EndPos: ]\r
-                        UniStr = ('\u' + (Line[StartPos + 2 : EndPos])).decode('unicode_escape')\r
+                        UniStr = Line[StartPos + 2: EndPos]\r
                         if EndStr.startswith(u'\\x') and len(EndStr) >= 7:\r
                             if EndStr[6] == u'\\' and g4HexChar.match(EndStr[2 : 6], re.UNICODE):\r
                                 Line = Line[0 : StartPos] + UniStr + EndStr\r