[Python-checkins] r53547 - in sandbox/trunk/setuptools: launcher.c setuptools/cli.exe setuptools/gui.exe setuptools/tests/win_script_wrapper.txt

phillip.eby python-checkins at python.org
Wed Jan 24 21:57:26 CET 2007


Author: phillip.eby
Date: Wed Jan 24 21:57:26 2007
New Revision: 53547

Modified:
   sandbox/trunk/setuptools/launcher.c
   sandbox/trunk/setuptools/setuptools/cli.exe
   sandbox/trunk/setuptools/setuptools/gui.exe
   sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt
Log:
Fix #! parsing problems w/whitespace in quoted strings or at the end
of the #! line.


Modified: sandbox/trunk/setuptools/launcher.c
==============================================================================
--- sandbox/trunk/setuptools/launcher.c	(original)
+++ sandbox/trunk/setuptools/launcher.c	Wed Jan 24 21:57:26 2007
@@ -129,6 +129,7 @@
     char *output = cmdline;
     char c;
     int nb = 0;
+    int iq = 0;
     *argc = 0;
 
     result[0] = output;
@@ -136,19 +137,20 @@
 
     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 @@
 
 
 
-
-
 int run(int argc, char **argv, int is_gui) {
 
     char python[256];   /* python executable's filename*/

Modified: sandbox/trunk/setuptools/setuptools/cli.exe
==============================================================================
Binary files. No diff available.

Modified: sandbox/trunk/setuptools/setuptools/gui.exe
==============================================================================
Binary files. No diff available.

Modified: sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt
==============================================================================
--- sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt	(original)
+++ sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt	Wed Jan 24 21:57:26 2007
@@ -15,6 +15,7 @@
 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 @@
     ... 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 @@
 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 @@
     ... 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


More information about the Python-checkins mailing list