##// END OF EJS Templates
Create fallback with old arg_split, incase CommandLineToArgvW is missing.
Jörgen Stenarson -
Show More
@@ -151,7 +151,7 b' def getoutput(cmd):'
151 out = ''
151 out = ''
152 return out
152 return out
153
153
154
154 try:
155 CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
155 CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
156 CommandLineToArgvW.arg_types = [LPCWSTR, POINTER(c_int)]
156 CommandLineToArgvW.arg_types = [LPCWSTR, POINTER(c_int)]
157 CommandLineToArgvW.res_types = [POINTER(LPCWSTR)]
157 CommandLineToArgvW.res_types = [POINTER(LPCWSTR)]
@@ -174,3 +174,28 b' def arg_split(commandline, posix=False):'
174 result = [arg for arg in result_array_type.from_address(result_pointer)]
174 result = [arg for arg in result_array_type.from_address(result_pointer)]
175 retval = LocalFree(result_pointer)
175 retval = LocalFree(result_pointer)
176 return result
176 return result
177 except AttributeError:
178 import shlex
179 #alternative if CommandLineToArgvW is not available
180 def arg_split(s, posix=False):
181 """Split a command line's arguments in a shell-like manner.
182
183 This is a modified version of the standard library's shlex.split()
184 function, but with a default of posix=False for splitting, so that quotes
185 in inputs are respected."""
186
187 # Unfortunately, python's shlex module is buggy with unicode input:
188 # http://bugs.python.org/issue1170
189 # At least encoding the input when it's unicode seems to help, but there
190 # may be more problems lurking. Apparently this is fixed in python3.
191 is_unicode = False
192 if (not py3compat.PY3) and isinstance(s, unicode):
193 is_unicode = True
194 s = s.encode('utf-8')
195 lex = shlex.shlex(s, posix=posix)
196 lex.whitespace_split = True
197 tokens = list(lex)
198 if is_unicode:
199 # Convert the tokens back to unicode.
200 tokens = [x.decode('utf-8') for x in tokens]
201 return tokens
General Comments 0
You need to be logged in to leave comments. Login now