77import shlex
88import subprocess
99import os
10- from os .path import abspath , normcase , realpath
1110import io
1211import platform
1312
@@ -27,7 +26,7 @@ def ensure_stripped_str(str_or_bytes):
2726 if isinstance (str_or_bytes , str ):
2827 return str_or_bytes .strip ()
2928 else :
30- return str_or_bytes .decode ('utf-8' , 'surogate_escape ' ).strip ()
29+ return str_or_bytes .decode ('utf-8' , 'surrogateescape ' ).strip ()
3130
3231
3332def _always_strings (env_dict ):
@@ -108,59 +107,3 @@ def has_command(name):
108107 if not res :
109108 warnings .warn ("%r was not found" % name )
110109 return res
111-
112-
113- def _normalized (path ):
114- if IS_WINDOWS :
115- path = get_windows_long_path_name (path )
116- return normcase (abspath (realpath (path )))
117-
118-
119- if IS_WINDOWS :
120- from ctypes import create_unicode_buffer , windll , WinError
121- from ctypes .wintypes import MAX_PATH , LPCWSTR , LPWSTR , DWORD
122-
123- GetLongPathNameW = windll .kernel32 .GetLongPathNameW
124- GetLongPathNameW .argtypes = [LPCWSTR , LPWSTR , DWORD ]
125- GetLongPathNameW .restype = DWORD
126-
127- def get_windows_long_path_name (path ):
128- """
129- Converts the specified path from short (MS-DOS style) to long form
130- using the 'GetLongPathNameW' function from Windows API.
131-
132- https://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx
133- """
134- if PY2 :
135- # decode path using filesystem encoding on python2; on python3
136- # it is already a unicode string
137- path = unicode (path , sys .getfilesystemencoding ()) # noqa
138-
139- pathlen = MAX_PATH + 1
140- if DEBUG :
141- # test reallocation logic
142- pathlen = 1
143-
144- for _ in range (2 ):
145- buf = create_unicode_buffer (pathlen )
146- retval = GetLongPathNameW (path , buf , pathlen )
147-
148- if retval == 0 :
149- # if the function fails for any reason (e.g. file does not
150- # exist), the return value is zero
151- raise WinError ()
152-
153- if retval <= pathlen :
154- # the function succeeded: the return value is the length of
155- # the string copied to the buffer
156- if PY2 :
157- # re-encode to native 'str' type (i.e. bytes) on python2
158- return buf .value .encode (sys .getfilesystemencoding ())
159- return buf .value
160-
161- # if the buffer is too small to contain the result, the return
162- # value is the size of the buffer required to hold the path and
163- # the terminating NULL char; we retry using a large enough buffer
164- pathlen = retval
165-
166- raise RuntimeError ("Failed to get long path name: {!r}" .format (path ))
0 commit comments