Commits

Vinay Sajip committed 9a88a30 Merge

Merged alt_shebang branch.

Comments (0)

Files changed (6)

CLILauncher/CLILauncher.rc

 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,0,3
- PRODUCTVERSION 1,0,0,3
+ FILEVERSION 1,0,0,9
+ PRODUCTVERSION 1,0,0,9
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
             VALUE "Comments", "Python Launcher for Windows"
             VALUE "CompanyName", "Python Software Foundation"
             VALUE "FileDescription", "Python Launcher for Windows (Console)"
-            VALUE "FileVersion", "1, 0, 0, 3"
+            VALUE "FileVersion", "1, 0, 0, 9"
             VALUE "InternalName", "py"
-            VALUE "LegalCopyright", "Copyright (C) 2011 Python Software Foundation"
+            VALUE "LegalCopyright", "Copyright (C) 2011-2012 Python Software Foundation"
             VALUE "OriginalFilename", "py"
             VALUE "ProductName", "Python Launcher for Windows"
-            VALUE "ProductVersion", "1, 0, 0, 3"
+            VALUE "ProductVersion", "1, 0, 0, 9"
         END
     END
     BLOCK "VarFileInfo"

CLILauncher/launcher.c

                 if (status != ERROR_NO_MORE_ITEMS) {
                     /* unexpected error */
                     winerror(status, message, MSGSIZE);
-                    debug(L"can't enumerate registry key for version %s: %s\n",
+                    debug(L"Can't enumerate registry key for version %s: %s\n",
                           ip->version, message);
                 }
                 break;
 static COMMAND commands[MAX_COMMANDS];
 static int num_commands = 0;
 
+static wchar_t * builtin_prefixes [] = {
+    /* These must be in an order that the longest matches should be found,
+     * i.e. if the prefix is "/usr/bin/env ", it should match that entry
+     * *before* matching "/usr/bin/".
+     */
+    L"/usr/bin/env ",
+    L"/usr/bin/",
+    L"/usr/local/bin/",
+    NULL
+};
+
+static wchar_t * skip_prefix(wchar_t * name)
+{
+    wchar_t ** pp = builtin_prefixes;
+    wchar_t * result = name;
+    wchar_t * p;
+    size_t n;
+
+    for (; p = *pp; pp++) {
+        n = wcslen(p);
+        if (_wcsnicmp(p, name, n) == 0) {
+            result += n;   /* skip the prefix */
+            if (p[n - 1] == L' ') /* No empty strings in table, so n > 1 */
+                result = skip_whitespace(result);
+            break;
+        }
+    }
+    return result;
+}
+
 static COMMAND * find_command(wchar_t * name)
 {
     COMMAND * result = NULL;
     wchar_t zapped;
     wchar_t * endp = shebang_line + nchars - 1;
     COMMAND * cp;
+    wchar_t * skipped;
 
     *command = NULL;    /* failure return */
     *suffix = NULL;
                  * stick a NUL after the command while searching for it,
                  * then put back the char we zapped.
                  */
-                p = wcspbrk(shebang_line, L" \t\r\n");
+                skipped = skip_prefix(shebang_line);
+                p = wcspbrk(skipped, L" \t\r\n");
                 if (p != NULL) {
                     zapped = *p;
                     *p = L'\0';
                 }
-                cp = find_command(shebang_line);
+                cp = find_command(skipped);
                 if (p != NULL)
                     *p = zapped;
                 if (cp != NULL) {
                             suffix = skip_whitespace(suffix);
                         }
                         if (wcsncmp(command, L"python", 6))
-                            error(RC_BAD_VIRTUAL_PATH, L"unknown virtual \
+                            error(RC_BAD_VIRTUAL_PATH, L"Unknown virtual \
 path '%s'", command);
                         command += 6;   /* skip past "python" */
                         if (*command && !validate_version(command))
-                            error(RC_BAD_VIRTUAL_PATH, L"invalid version \
-specification: '%s'", command);
+                            error(RC_BAD_VIRTUAL_PATH, L"Invalid version \
+specification: '%s'.\nIn the first line of the script, 'python' needs to be \
+followed by a valid version specifier.\nPlease check the documentation.",
+                                  command);
                         /* TODO could call validate_version(command) */
                         ip = locate_python(command);
                         if (ip == NULL) {

Doc/launcher.rst

File contents unchanged.

GUILauncher/GUILauncher.rc

 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,0,3
- PRODUCTVERSION 1,0,0,3
+ FILEVERSION 1,0,0,9
+ PRODUCTVERSION 1,0,0,9
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
             VALUE "Comments", "Python Launcher for Windows"
             VALUE "CompanyName", "Python Software Foundation"
             VALUE "FileDescription", "Python Launcher for Windows (GUI)"
-            VALUE "FileVersion", "1, 0, 0, 3"
+            VALUE "FileVersion", "1, 0, 0, 9"
             VALUE "InternalName", "GUILaunpyw"
-            VALUE "LegalCopyright", "Copyright (C) 2011 Python Software Foundation"
+            VALUE "LegalCopyright", "Copyright (C) 2011-2012 Python Software Foundation"
             VALUE "OriginalFilename", "pyw"
             VALUE "ProductName", "Python Launcher for Windows"
-            VALUE "ProductVersion", "1, 0, 0, 3"
+            VALUE "ProductVersion", "1, 0, 0, 9"
         END
     END
     BLOCK "VarFileInfo"
 import os
 import sys
 
-VERSION = 'Version=1.0.0.5'
+VERSION = 'Version=1.0.0.9'
 MANUFACTURER = 'Manufacturer=Vinay Sajip'
 X86 = 'Platform=x86'
 X64 = 'Platform=x64'
 
 VIRT_PATHS = [
     '/usr/bin/env ',
+    '/usr/bin/env  ', # test extra whitespace before command
     '/usr/bin/',
+    '/usr/local/bin/',
+    '',
 ]
 
 class VirtualPath: # think a C struct...
         self.assertIn(DEFAULT_PYTHON2.bdir, stdout)
 
         # Python 3 version
-        shebang = '#!v3\n'
-        path = self.make_script(shebang_line=shebang)
-        stdout, stderr = self.run_child(path)
-        self.assertTrue(stderr.startswith(DEFAULT_PYTHON3.output_version))
+        for prefix in VIRT_PATHS:
+            shebang = '#!%sv3\n' % prefix
+            path = self.make_script(shebang_line=shebang)
+            stdout, stderr = self.run_child(path)
+            self.assertTrue(stderr.startswith(DEFAULT_PYTHON3.output_version))
 
         # Python 2 version
-        shebang = '#!v2\n'
-        path = self.make_script(shebang_line=shebang)
-        stdout, stderr = self.run_child(path)
-        self.assertTrue(stderr.startswith(DEFAULT_PYTHON2.output_version))
+        for prefix in VIRT_PATHS:
+            shebang = '#!%sv2\n' % prefix
+            path = self.make_script(shebang_line=shebang)
+            stdout, stderr = self.run_child(path)
+            self.assertTrue(stderr.startswith(DEFAULT_PYTHON2.output_version))
 
         VERBOSE_START = b'# installing zipimport hook'