Split a command line's arguments in a shell-like manner. This is a special version for windows that use a ctypes call to CommandLineToArgvW to do the argv splitting. The posix parameter is ignored. If strict=False, process_common.arg_split(...strict=False) is used instead.
(
commandline: str, posix: bool = False, strict: bool = True
)
| 174 | LocalFree.arg_types = [HLOCAL] |
| 175 | |
| 176 | def arg_split( |
| 177 | commandline: str, posix: bool = False, strict: bool = True |
| 178 | ) -> List[str]: |
| 179 | """Split a command line's arguments in a shell-like manner. |
| 180 | |
| 181 | This is a special version for windows that use a ctypes call to CommandLineToArgvW |
| 182 | to do the argv splitting. The posix parameter is ignored. |
| 183 | |
| 184 | If strict=False, process_common.arg_split(...strict=False) is used instead. |
| 185 | """ |
| 186 | # CommandLineToArgvW returns path to executable if called with empty string. |
| 187 | if commandline.strip() == "": |
| 188 | return [] |
| 189 | if not strict: |
| 190 | # not really a cl-arg, fallback on _process_common |
| 191 | return py_arg_split(commandline, posix=posix, strict=strict) |
| 192 | argvn = c_int() |
| 193 | result_pointer = CommandLineToArgvW(commandline.lstrip(), ctypes.byref(argvn)) |
| 194 | try: |
| 195 | result_array_type = LPCWSTR * argvn.value |
| 196 | result = [ |
| 197 | arg |
| 198 | for arg in result_array_type.from_address( |
| 199 | ctypes.addressof(result_pointer.contents) |
| 200 | ) |
| 201 | if arg is not None |
| 202 | ] |
| 203 | finally: |
| 204 | # for side effects |
| 205 | _ = LocalFree(result_pointer) |
| 206 | return result |
| 207 | except AttributeError: |
| 208 | arg_split = py_arg_split |
| 209 |
no outgoing calls
searching dependent graphs…