Fix ``#!`` parsing problems in Windows ``.exe`` script wrappers, when there
was whitespace inside a quoted argument or at the end of the ``#!`` line (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4053548
This commit is contained in:
parent
2dd7ed9ccf
commit
6dbe235a60
|
@ -129,6 +129,7 @@ char **parse_argv(char *cmdline, int *argc)
|
|||
char *output = cmdline;
|
||||
char c;
|
||||
int nb = 0;
|
||||
int iq = 0;
|
||||
*argc = 0;
|
||||
|
||||
result[0] = output;
|
||||
|
@ -136,19 +137,20 @@ char **parse_argv(char *cmdline, int *argc)
|
|||
|
||||
do {
|
||||
c = *cmdline++;
|
||||
if (!c || isspace(c)) {
|
||||
if (!c || (isspace(c) && !iq)) {
|
||||
while (nb) {*output++ = '\\'; nb--; }
|
||||
*output++ = 0;
|
||||
result[++*argc] = output;
|
||||
if (!c) return result;
|
||||
while (isspace(*cmdline)) cmdline++; /* skip leading spaces */
|
||||
if (!*cmdline) return result; /* avoid empty arg if trailing ws */
|
||||
continue;
|
||||
}
|
||||
if (c == '\\')
|
||||
++nb; /* count \'s */
|
||||
else {
|
||||
if (c == '"') {
|
||||
if (!(nb & 1)) c = 0; /* skip " unless odd # of \ */
|
||||
if (!(nb & 1)) { iq = !iq; c = 0; } /* skip " unless odd # of \ */
|
||||
nb = nb >> 1; /* cut \'s in half */
|
||||
}
|
||||
while (nb) {*output++ = '\\'; nb--; }
|
||||
|
@ -160,8 +162,6 @@ char **parse_argv(char *cmdline, int *argc)
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
int run(int argc, char **argv, int is_gui) {
|
||||
|
||||
char python[256]; /* python executable's filename*/
|
||||
|
|
|
@ -2606,6 +2606,10 @@ Release Notes/Change History
|
|||
* Fix "eggsecutables" (such as setuptools' own egg) only being runnable with
|
||||
bash-compatible shells.
|
||||
|
||||
* Fix ``#!`` parsing problems in Windows ``.exe`` script wrappers, when there
|
||||
was whitespace inside a quoted argument or at the end of the ``#!`` line
|
||||
(a regression introduced in 0.6c4).
|
||||
|
||||
0.6c5
|
||||
* Fix uploaded ``bdist_rpm`` packages being described as ``bdist_egg``
|
||||
packages under Python versions less than 2.5.
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -15,6 +15,7 @@ will illustrate this.
|
|||
Let's create a simple script, foo-script.py:
|
||||
|
||||
>>> import os, sys, tempfile
|
||||
>>> from setuptools.command.easy_install import nt_quote_arg
|
||||
>>> sample_directory = tempfile.mkdtemp()
|
||||
>>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
|
||||
... """#!%(python_exe)s
|
||||
|
@ -25,7 +26,7 @@ Let's create a simple script, foo-script.py:
|
|||
... print input
|
||||
... if __debug__:
|
||||
... print 'non-optimized'
|
||||
... """ % dict(python_exe=sys.executable))
|
||||
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
|
||||
|
||||
Note that the script starts with a Unix-style '#!' line saying which
|
||||
Python executable to run. The wrapper will use this to find the
|
||||
|
@ -46,8 +47,8 @@ named out script the way we did. Now we can run out script by running
|
|||
the wrapper:
|
||||
|
||||
>>> import os
|
||||
>>> input, output = os.popen4(os.path.join(sample_directory, 'foo.exe')
|
||||
... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b')
|
||||
>>> input, output = os.popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))
|
||||
... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"')
|
||||
>>> input.write('hello\nworld\n')
|
||||
>>> input.close()
|
||||
>>> print output.read(),
|
||||
|
@ -86,9 +87,9 @@ enter the interpreter after running the script, you could use -Oi:
|
|||
... if __debug__:
|
||||
... print 'non-optimized'
|
||||
... sys.ps1 = '---'
|
||||
... """ % dict(python_exe=sys.executable))
|
||||
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
|
||||
|
||||
>>> input, output = os.popen4(os.path.join(sample_directory, 'foo.exe'))
|
||||
>>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
|
||||
>>> input.close()
|
||||
>>> print output.read(),
|
||||
\foo-script.py
|
||||
|
|
Loading…
Reference in New Issue