Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: subprocess.py
# subprocess - Subprocesses with accessible I/O streams
[0] Fix | Delete
#
[1] Fix | Delete
# For more information about this module, see PEP 324.
[2] Fix | Delete
#
[3] Fix | Delete
# Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se>
[4] Fix | Delete
#
[5] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[6] Fix | Delete
# See http://www.python.org/2.4/license for licensing details.
[7] Fix | Delete
[8] Fix | Delete
r"""Subprocesses with accessible I/O streams
[9] Fix | Delete
[10] Fix | Delete
This module allows you to spawn processes, connect to their
[11] Fix | Delete
input/output/error pipes, and obtain their return codes.
[12] Fix | Delete
[13] Fix | Delete
For a complete description of this module see the Python documentation.
[14] Fix | Delete
[15] Fix | Delete
Main API
[16] Fix | Delete
========
[17] Fix | Delete
run(...): Runs a command, waits for it to complete, then returns a
[18] Fix | Delete
CompletedProcess instance.
[19] Fix | Delete
Popen(...): A class for flexibly executing a command in a new process
[20] Fix | Delete
[21] Fix | Delete
Constants
[22] Fix | Delete
---------
[23] Fix | Delete
DEVNULL: Special value that indicates that os.devnull should be used
[24] Fix | Delete
PIPE: Special value that indicates a pipe should be created
[25] Fix | Delete
STDOUT: Special value that indicates that stderr should go to stdout
[26] Fix | Delete
[27] Fix | Delete
[28] Fix | Delete
Older API
[29] Fix | Delete
=========
[30] Fix | Delete
call(...): Runs a command, waits for it to complete, then returns
[31] Fix | Delete
the return code.
[32] Fix | Delete
check_call(...): Same as call() but raises CalledProcessError()
[33] Fix | Delete
if return code is not 0
[34] Fix | Delete
check_output(...): Same as check_call() but returns the contents of
[35] Fix | Delete
stdout instead of a return code
[36] Fix | Delete
getoutput(...): Runs a command in the shell, waits for it to complete,
[37] Fix | Delete
then returns the output
[38] Fix | Delete
getstatusoutput(...): Runs a command in the shell, waits for it to complete,
[39] Fix | Delete
then returns a (exitcode, output) tuple
[40] Fix | Delete
"""
[41] Fix | Delete
[42] Fix | Delete
import sys
[43] Fix | Delete
_mswindows = (sys.platform == "win32")
[44] Fix | Delete
[45] Fix | Delete
import io
[46] Fix | Delete
import os
[47] Fix | Delete
import time
[48] Fix | Delete
import signal
[49] Fix | Delete
import builtins
[50] Fix | Delete
import warnings
[51] Fix | Delete
import errno
[52] Fix | Delete
from time import monotonic as _time
[53] Fix | Delete
[54] Fix | Delete
# Exception classes used by this module.
[55] Fix | Delete
class SubprocessError(Exception): pass
[56] Fix | Delete
[57] Fix | Delete
[58] Fix | Delete
class CalledProcessError(SubprocessError):
[59] Fix | Delete
"""Raised when run() is called with check=True and the process
[60] Fix | Delete
returns a non-zero exit status.
[61] Fix | Delete
[62] Fix | Delete
Attributes:
[63] Fix | Delete
cmd, returncode, stdout, stderr, output
[64] Fix | Delete
"""
[65] Fix | Delete
def __init__(self, returncode, cmd, output=None, stderr=None):
[66] Fix | Delete
self.returncode = returncode
[67] Fix | Delete
self.cmd = cmd
[68] Fix | Delete
self.output = output
[69] Fix | Delete
self.stderr = stderr
[70] Fix | Delete
[71] Fix | Delete
def __str__(self):
[72] Fix | Delete
if self.returncode and self.returncode < 0:
[73] Fix | Delete
try:
[74] Fix | Delete
return "Command '%s' died with %r." % (
[75] Fix | Delete
self.cmd, signal.Signals(-self.returncode))
[76] Fix | Delete
except ValueError:
[77] Fix | Delete
return "Command '%s' died with unknown signal %d." % (
[78] Fix | Delete
self.cmd, -self.returncode)
[79] Fix | Delete
else:
[80] Fix | Delete
return "Command '%s' returned non-zero exit status %d." % (
[81] Fix | Delete
self.cmd, self.returncode)
[82] Fix | Delete
[83] Fix | Delete
@property
[84] Fix | Delete
def stdout(self):
[85] Fix | Delete
"""Alias for output attribute, to match stderr"""
[86] Fix | Delete
return self.output
[87] Fix | Delete
[88] Fix | Delete
@stdout.setter
[89] Fix | Delete
def stdout(self, value):
[90] Fix | Delete
# There's no obvious reason to set this, but allow it anyway so
[91] Fix | Delete
# .stdout is a transparent alias for .output
[92] Fix | Delete
self.output = value
[93] Fix | Delete
[94] Fix | Delete
[95] Fix | Delete
class TimeoutExpired(SubprocessError):
[96] Fix | Delete
"""This exception is raised when the timeout expires while waiting for a
[97] Fix | Delete
child process.
[98] Fix | Delete
[99] Fix | Delete
Attributes:
[100] Fix | Delete
cmd, output, stdout, stderr, timeout
[101] Fix | Delete
"""
[102] Fix | Delete
def __init__(self, cmd, timeout, output=None, stderr=None):
[103] Fix | Delete
self.cmd = cmd
[104] Fix | Delete
self.timeout = timeout
[105] Fix | Delete
self.output = output
[106] Fix | Delete
self.stderr = stderr
[107] Fix | Delete
[108] Fix | Delete
def __str__(self):
[109] Fix | Delete
return ("Command '%s' timed out after %s seconds" %
[110] Fix | Delete
(self.cmd, self.timeout))
[111] Fix | Delete
[112] Fix | Delete
@property
[113] Fix | Delete
def stdout(self):
[114] Fix | Delete
return self.output
[115] Fix | Delete
[116] Fix | Delete
@stdout.setter
[117] Fix | Delete
def stdout(self, value):
[118] Fix | Delete
# There's no obvious reason to set this, but allow it anyway so
[119] Fix | Delete
# .stdout is a transparent alias for .output
[120] Fix | Delete
self.output = value
[121] Fix | Delete
[122] Fix | Delete
[123] Fix | Delete
if _mswindows:
[124] Fix | Delete
import threading
[125] Fix | Delete
import msvcrt
[126] Fix | Delete
import _winapi
[127] Fix | Delete
class STARTUPINFO:
[128] Fix | Delete
dwFlags = 0
[129] Fix | Delete
hStdInput = None
[130] Fix | Delete
hStdOutput = None
[131] Fix | Delete
hStdError = None
[132] Fix | Delete
wShowWindow = 0
[133] Fix | Delete
else:
[134] Fix | Delete
import _posixsubprocess
[135] Fix | Delete
import select
[136] Fix | Delete
import selectors
[137] Fix | Delete
try:
[138] Fix | Delete
import threading
[139] Fix | Delete
except ImportError:
[140] Fix | Delete
import dummy_threading as threading
[141] Fix | Delete
[142] Fix | Delete
# When select or poll has indicated that the file is writable,
[143] Fix | Delete
# we can write up to _PIPE_BUF bytes without risk of blocking.
[144] Fix | Delete
# POSIX defines PIPE_BUF as >= 512.
[145] Fix | Delete
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
[146] Fix | Delete
[147] Fix | Delete
# poll/select have the advantage of not requiring any extra file
[148] Fix | Delete
# descriptor, contrarily to epoll/kqueue (also, they require a single
[149] Fix | Delete
# syscall).
[150] Fix | Delete
if hasattr(selectors, 'PollSelector'):
[151] Fix | Delete
_PopenSelector = selectors.PollSelector
[152] Fix | Delete
else:
[153] Fix | Delete
_PopenSelector = selectors.SelectSelector
[154] Fix | Delete
[155] Fix | Delete
[156] Fix | Delete
__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "getstatusoutput",
[157] Fix | Delete
"getoutput", "check_output", "run", "CalledProcessError", "DEVNULL",
[158] Fix | Delete
"SubprocessError", "TimeoutExpired", "CompletedProcess"]
[159] Fix | Delete
# NOTE: We intentionally exclude list2cmdline as it is
[160] Fix | Delete
# considered an internal implementation detail. issue10838.
[161] Fix | Delete
[162] Fix | Delete
if _mswindows:
[163] Fix | Delete
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
[164] Fix | Delete
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
[165] Fix | Delete
STD_ERROR_HANDLE, SW_HIDE,
[166] Fix | Delete
STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW)
[167] Fix | Delete
[168] Fix | Delete
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP",
[169] Fix | Delete
"STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE",
[170] Fix | Delete
"STD_ERROR_HANDLE", "SW_HIDE",
[171] Fix | Delete
"STARTF_USESTDHANDLES", "STARTF_USESHOWWINDOW",
[172] Fix | Delete
"STARTUPINFO"])
[173] Fix | Delete
[174] Fix | Delete
class Handle(int):
[175] Fix | Delete
closed = False
[176] Fix | Delete
[177] Fix | Delete
def Close(self, CloseHandle=_winapi.CloseHandle):
[178] Fix | Delete
if not self.closed:
[179] Fix | Delete
self.closed = True
[180] Fix | Delete
CloseHandle(self)
[181] Fix | Delete
[182] Fix | Delete
def Detach(self):
[183] Fix | Delete
if not self.closed:
[184] Fix | Delete
self.closed = True
[185] Fix | Delete
return int(self)
[186] Fix | Delete
raise ValueError("already closed")
[187] Fix | Delete
[188] Fix | Delete
def __repr__(self):
[189] Fix | Delete
return "%s(%d)" % (self.__class__.__name__, int(self))
[190] Fix | Delete
[191] Fix | Delete
__del__ = Close
[192] Fix | Delete
__str__ = __repr__
[193] Fix | Delete
[194] Fix | Delete
[195] Fix | Delete
# This lists holds Popen instances for which the underlying process had not
[196] Fix | Delete
# exited at the time its __del__ method got called: those processes are wait()ed
[197] Fix | Delete
# for synchronously from _cleanup() when a new Popen object is created, to avoid
[198] Fix | Delete
# zombie processes.
[199] Fix | Delete
_active = []
[200] Fix | Delete
[201] Fix | Delete
def _cleanup():
[202] Fix | Delete
for inst in _active[:]:
[203] Fix | Delete
res = inst._internal_poll(_deadstate=sys.maxsize)
[204] Fix | Delete
if res is not None:
[205] Fix | Delete
try:
[206] Fix | Delete
_active.remove(inst)
[207] Fix | Delete
except ValueError:
[208] Fix | Delete
# This can happen if two threads create a new Popen instance.
[209] Fix | Delete
# It's harmless that it was already removed, so ignore.
[210] Fix | Delete
pass
[211] Fix | Delete
[212] Fix | Delete
PIPE = -1
[213] Fix | Delete
STDOUT = -2
[214] Fix | Delete
DEVNULL = -3
[215] Fix | Delete
[216] Fix | Delete
[217] Fix | Delete
# XXX This function is only used by multiprocessing and the test suite,
[218] Fix | Delete
# but it's here so that it can be imported when Python is compiled without
[219] Fix | Delete
# threads.
[220] Fix | Delete
[221] Fix | Delete
def _optim_args_from_interpreter_flags():
[222] Fix | Delete
"""Return a list of command-line arguments reproducing the current
[223] Fix | Delete
optimization settings in sys.flags."""
[224] Fix | Delete
args = []
[225] Fix | Delete
value = sys.flags.optimize
[226] Fix | Delete
if value > 0:
[227] Fix | Delete
args.append('-' + 'O' * value)
[228] Fix | Delete
return args
[229] Fix | Delete
[230] Fix | Delete
[231] Fix | Delete
def _args_from_interpreter_flags():
[232] Fix | Delete
"""Return a list of command-line arguments reproducing the current
[233] Fix | Delete
settings in sys.flags, sys.warnoptions and sys._xoptions."""
[234] Fix | Delete
flag_opt_map = {
[235] Fix | Delete
'debug': 'd',
[236] Fix | Delete
# 'inspect': 'i',
[237] Fix | Delete
# 'interactive': 'i',
[238] Fix | Delete
'dont_write_bytecode': 'B',
[239] Fix | Delete
'no_site': 'S',
[240] Fix | Delete
'verbose': 'v',
[241] Fix | Delete
'bytes_warning': 'b',
[242] Fix | Delete
'quiet': 'q',
[243] Fix | Delete
# -O is handled in _optim_args_from_interpreter_flags()
[244] Fix | Delete
}
[245] Fix | Delete
args = _optim_args_from_interpreter_flags()
[246] Fix | Delete
for flag, opt in flag_opt_map.items():
[247] Fix | Delete
v = getattr(sys.flags, flag)
[248] Fix | Delete
if v > 0:
[249] Fix | Delete
args.append('-' + opt * v)
[250] Fix | Delete
[251] Fix | Delete
if sys.flags.isolated:
[252] Fix | Delete
args.append('-I')
[253] Fix | Delete
else:
[254] Fix | Delete
if sys.flags.ignore_environment:
[255] Fix | Delete
args.append('-E')
[256] Fix | Delete
if sys.flags.no_user_site:
[257] Fix | Delete
args.append('-s')
[258] Fix | Delete
[259] Fix | Delete
for opt in sys.warnoptions:
[260] Fix | Delete
args.append('-W' + opt)
[261] Fix | Delete
[262] Fix | Delete
# -X options
[263] Fix | Delete
xoptions = getattr(sys, '_xoptions', {})
[264] Fix | Delete
for opt in ('faulthandler', 'tracemalloc',
[265] Fix | Delete
'showalloccount', 'showrefcount', 'utf8'):
[266] Fix | Delete
if opt in xoptions:
[267] Fix | Delete
value = xoptions[opt]
[268] Fix | Delete
if value is True:
[269] Fix | Delete
arg = opt
[270] Fix | Delete
else:
[271] Fix | Delete
arg = '%s=%s' % (opt, value)
[272] Fix | Delete
args.extend(('-X', arg))
[273] Fix | Delete
[274] Fix | Delete
return args
[275] Fix | Delete
[276] Fix | Delete
[277] Fix | Delete
def call(*popenargs, timeout=None, **kwargs):
[278] Fix | Delete
"""Run command with arguments. Wait for command to complete or
[279] Fix | Delete
timeout, then return the returncode attribute.
[280] Fix | Delete
[281] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[282] Fix | Delete
[283] Fix | Delete
retcode = call(["ls", "-l"])
[284] Fix | Delete
"""
[285] Fix | Delete
with Popen(*popenargs, **kwargs) as p:
[286] Fix | Delete
try:
[287] Fix | Delete
return p.wait(timeout=timeout)
[288] Fix | Delete
except:
[289] Fix | Delete
p.kill()
[290] Fix | Delete
p.wait()
[291] Fix | Delete
raise
[292] Fix | Delete
[293] Fix | Delete
[294] Fix | Delete
def check_call(*popenargs, **kwargs):
[295] Fix | Delete
"""Run command with arguments. Wait for command to complete. If
[296] Fix | Delete
the exit code was zero then return, otherwise raise
[297] Fix | Delete
CalledProcessError. The CalledProcessError object will have the
[298] Fix | Delete
return code in the returncode attribute.
[299] Fix | Delete
[300] Fix | Delete
The arguments are the same as for the call function. Example:
[301] Fix | Delete
[302] Fix | Delete
check_call(["ls", "-l"])
[303] Fix | Delete
"""
[304] Fix | Delete
retcode = call(*popenargs, **kwargs)
[305] Fix | Delete
if retcode:
[306] Fix | Delete
cmd = kwargs.get("args")
[307] Fix | Delete
if cmd is None:
[308] Fix | Delete
cmd = popenargs[0]
[309] Fix | Delete
raise CalledProcessError(retcode, cmd)
[310] Fix | Delete
return 0
[311] Fix | Delete
[312] Fix | Delete
[313] Fix | Delete
def check_output(*popenargs, timeout=None, **kwargs):
[314] Fix | Delete
r"""Run command with arguments and return its output.
[315] Fix | Delete
[316] Fix | Delete
If the exit code was non-zero it raises a CalledProcessError. The
[317] Fix | Delete
CalledProcessError object will have the return code in the returncode
[318] Fix | Delete
attribute and output in the output attribute.
[319] Fix | Delete
[320] Fix | Delete
The arguments are the same as for the Popen constructor. Example:
[321] Fix | Delete
[322] Fix | Delete
>>> check_output(["ls", "-l", "/dev/null"])
[323] Fix | Delete
b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
[324] Fix | Delete
[325] Fix | Delete
The stdout argument is not allowed as it is used internally.
[326] Fix | Delete
To capture standard error in the result, use stderr=STDOUT.
[327] Fix | Delete
[328] Fix | Delete
>>> check_output(["/bin/sh", "-c",
[329] Fix | Delete
... "ls -l non_existent_file ; exit 0"],
[330] Fix | Delete
... stderr=STDOUT)
[331] Fix | Delete
b'ls: non_existent_file: No such file or directory\n'
[332] Fix | Delete
[333] Fix | Delete
There is an additional optional argument, "input", allowing you to
[334] Fix | Delete
pass a string to the subprocess's stdin. If you use this argument
[335] Fix | Delete
you may not also use the Popen constructor's "stdin" argument, as
[336] Fix | Delete
it too will be used internally. Example:
[337] Fix | Delete
[338] Fix | Delete
>>> check_output(["sed", "-e", "s/foo/bar/"],
[339] Fix | Delete
... input=b"when in the course of fooman events\n")
[340] Fix | Delete
b'when in the course of barman events\n'
[341] Fix | Delete
[342] Fix | Delete
If universal_newlines=True is passed, the "input" argument must be a
[343] Fix | Delete
string and the return value will be a string rather than bytes.
[344] Fix | Delete
"""
[345] Fix | Delete
if 'stdout' in kwargs:
[346] Fix | Delete
raise ValueError('stdout argument not allowed, it will be overridden.')
[347] Fix | Delete
[348] Fix | Delete
if 'input' in kwargs and kwargs['input'] is None:
[349] Fix | Delete
# Explicitly passing input=None was previously equivalent to passing an
[350] Fix | Delete
# empty string. That is maintained here for backwards compatibility.
[351] Fix | Delete
kwargs['input'] = '' if kwargs.get('universal_newlines', False) else b''
[352] Fix | Delete
[353] Fix | Delete
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
[354] Fix | Delete
**kwargs).stdout
[355] Fix | Delete
[356] Fix | Delete
[357] Fix | Delete
class CompletedProcess(object):
[358] Fix | Delete
"""A process that has finished running.
[359] Fix | Delete
[360] Fix | Delete
This is returned by run().
[361] Fix | Delete
[362] Fix | Delete
Attributes:
[363] Fix | Delete
args: The list or str args passed to run().
[364] Fix | Delete
returncode: The exit code of the process, negative for signals.
[365] Fix | Delete
stdout: The standard output (None if not captured).
[366] Fix | Delete
stderr: The standard error (None if not captured).
[367] Fix | Delete
"""
[368] Fix | Delete
def __init__(self, args, returncode, stdout=None, stderr=None):
[369] Fix | Delete
self.args = args
[370] Fix | Delete
self.returncode = returncode
[371] Fix | Delete
self.stdout = stdout
[372] Fix | Delete
self.stderr = stderr
[373] Fix | Delete
[374] Fix | Delete
def __repr__(self):
[375] Fix | Delete
args = ['args={!r}'.format(self.args),
[376] Fix | Delete
'returncode={!r}'.format(self.returncode)]
[377] Fix | Delete
if self.stdout is not None:
[378] Fix | Delete
args.append('stdout={!r}'.format(self.stdout))
[379] Fix | Delete
if self.stderr is not None:
[380] Fix | Delete
args.append('stderr={!r}'.format(self.stderr))
[381] Fix | Delete
return "{}({})".format(type(self).__name__, ', '.join(args))
[382] Fix | Delete
[383] Fix | Delete
def check_returncode(self):
[384] Fix | Delete
"""Raise CalledProcessError if the exit code is non-zero."""
[385] Fix | Delete
if self.returncode:
[386] Fix | Delete
raise CalledProcessError(self.returncode, self.args, self.stdout,
[387] Fix | Delete
self.stderr)
[388] Fix | Delete
[389] Fix | Delete
[390] Fix | Delete
def run(*popenargs, input=None, timeout=None, check=False, **kwargs):
[391] Fix | Delete
"""Run command with arguments and return a CompletedProcess instance.
[392] Fix | Delete
[393] Fix | Delete
The returned instance will have attributes args, returncode, stdout and
[394] Fix | Delete
stderr. By default, stdout and stderr are not captured, and those attributes
[395] Fix | Delete
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
[396] Fix | Delete
[397] Fix | Delete
If check is True and the exit code was non-zero, it raises a
[398] Fix | Delete
CalledProcessError. The CalledProcessError object will have the return code
[399] Fix | Delete
in the returncode attribute, and output & stderr attributes if those streams
[400] Fix | Delete
were captured.
[401] Fix | Delete
[402] Fix | Delete
If timeout is given, and the process takes too long, a TimeoutExpired
[403] Fix | Delete
exception will be raised.
[404] Fix | Delete
[405] Fix | Delete
There is an optional argument "input", allowing you to
[406] Fix | Delete
pass a string to the subprocess's stdin. If you use this argument
[407] Fix | Delete
you may not also use the Popen constructor's "stdin" argument, as
[408] Fix | Delete
it will be used internally.
[409] Fix | Delete
[410] Fix | Delete
The other arguments are the same as for the Popen constructor.
[411] Fix | Delete
[412] Fix | Delete
If universal_newlines=True is passed, the "input" argument must be a
[413] Fix | Delete
string and stdout/stderr in the returned object will be strings rather than
[414] Fix | Delete
bytes.
[415] Fix | Delete
"""
[416] Fix | Delete
if input is not None:
[417] Fix | Delete
if 'stdin' in kwargs:
[418] Fix | Delete
raise ValueError('stdin and input arguments may not both be used.')
[419] Fix | Delete
kwargs['stdin'] = PIPE
[420] Fix | Delete
[421] Fix | Delete
with Popen(*popenargs, **kwargs) as process:
[422] Fix | Delete
try:
[423] Fix | Delete
stdout, stderr = process.communicate(input, timeout=timeout)
[424] Fix | Delete
except TimeoutExpired:
[425] Fix | Delete
process.kill()
[426] Fix | Delete
stdout, stderr = process.communicate()
[427] Fix | Delete
raise TimeoutExpired(process.args, timeout, output=stdout,
[428] Fix | Delete
stderr=stderr)
[429] Fix | Delete
except:
[430] Fix | Delete
process.kill()
[431] Fix | Delete
process.wait()
[432] Fix | Delete
raise
[433] Fix | Delete
retcode = process.poll()
[434] Fix | Delete
if check and retcode:
[435] Fix | Delete
raise CalledProcessError(retcode, process.args,
[436] Fix | Delete
output=stdout, stderr=stderr)
[437] Fix | Delete
return CompletedProcess(process.args, retcode, stdout, stderr)
[438] Fix | Delete
[439] Fix | Delete
[440] Fix | Delete
def list2cmdline(seq):
[441] Fix | Delete
"""
[442] Fix | Delete
Translate a sequence of arguments into a command line
[443] Fix | Delete
string, using the same rules as the MS C runtime:
[444] Fix | Delete
[445] Fix | Delete
1) Arguments are delimited by white space, which is either a
[446] Fix | Delete
space or a tab.
[447] Fix | Delete
[448] Fix | Delete
2) A string surrounded by double quotation marks is
[449] Fix | Delete
interpreted as a single argument, regardless of white space
[450] Fix | Delete
contained within. A quoted string can be embedded in an
[451] Fix | Delete
argument.
[452] Fix | Delete
[453] Fix | Delete
3) A double quotation mark preceded by a backslash is
[454] Fix | Delete
interpreted as a literal double quotation mark.
[455] Fix | Delete
[456] Fix | Delete
4) Backslashes are interpreted literally, unless they
[457] Fix | Delete
immediately precede a double quotation mark.
[458] Fix | Delete
[459] Fix | Delete
5) If backslashes immediately precede a double quotation mark,
[460] Fix | Delete
every pair of backslashes is interpreted as a literal
[461] Fix | Delete
backslash. If the number of backslashes is odd, the last
[462] Fix | Delete
backslash escapes the next double quotation mark as
[463] Fix | Delete
described in rule 3.
[464] Fix | Delete
"""
[465] Fix | Delete
[466] Fix | Delete
# See
[467] Fix | Delete
# http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
[468] Fix | Delete
# or search http://msdn.microsoft.com for
[469] Fix | Delete
# "Parsing C++ Command-Line Arguments"
[470] Fix | Delete
result = []
[471] Fix | Delete
needquote = False
[472] Fix | Delete
for arg in seq:
[473] Fix | Delete
bs_buf = []
[474] Fix | Delete
[475] Fix | Delete
# Add a space to separate this argument from the others
[476] Fix | Delete
if result:
[477] Fix | Delete
result.append(' ')
[478] Fix | Delete
[479] Fix | Delete
needquote = (" " in arg) or ("\t" in arg) or not arg
[480] Fix | Delete
if needquote:
[481] Fix | Delete
result.append('"')
[482] Fix | Delete
[483] Fix | Delete
for c in arg:
[484] Fix | Delete
if c == '\\':
[485] Fix | Delete
# Don't know if we need to double yet.
[486] Fix | Delete
bs_buf.append(c)
[487] Fix | Delete
elif c == '"':
[488] Fix | Delete
# Double backslashes.
[489] Fix | Delete
result.append('\\' * len(bs_buf)*2)
[490] Fix | Delete
bs_buf = []
[491] Fix | Delete
result.append('\\"')
[492] Fix | Delete
else:
[493] Fix | Delete
# Normal char
[494] Fix | Delete
if bs_buf:
[495] Fix | Delete
result.extend(bs_buf)
[496] Fix | Delete
bs_buf = []
[497] Fix | Delete
result.append(c)
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function