--- /dev/null
+## @file\r
+# Override built in function file.open to provide support for long file path\r
+#\r
+# Copyright (c) 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
+#\r
+\r
+import os\r
+import platform\r
+import shutil\r
+\r
+##\r
+# OpenLongPath\r
+# Convert a file path to a long file path\r
+#\r
+def LongFilePath(FileName):\r
+ FileName = os.path.normpath(FileName)\r
+ if platform.system() == 'Windows':\r
+ if FileName.startswith('\\\\?\\'):\r
+ return FileName\r
+ if FileName.startswith('\\\\'):\r
+ return '\\\\?\\UNC\\' + FileName[2:]\r
+ if os.path.isabs(FileName):\r
+ return '\\\\?\\' + FileName\r
+ return FileName\r
+\r
+##\r
+# OpenLongFilePath\r
+# wrap open to support opening a long file path\r
+#\r
+def OpenLongFilePath(FileName, Mode='r', Buffer= -1):\r
+ return open(LongFilePath(FileName), Mode, Buffer)\r
+\r
+##\r
+# CopyLongFilePath\r
+# wrap copyfile to support copy a long file path\r
+#\r
+def CopyLongFilePath(src, dst):\r
+ with open(LongFilePath(src), 'rb') as fsrc:\r
+ with open(LongFilePath(dst), 'wb') as fdst:\r
+ shutil.copyfileobj(fsrc, fdst)\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