]> granicus.if.org Git - python/commitdiff
Try to be a bit more consistent on all platforms:
authorNeal Norwitz <nnorwitz@gmail.com>
Thu, 9 Mar 2006 05:58:11 +0000 (05:58 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Thu, 9 Mar 2006 05:58:11 +0000 (05:58 +0000)
  python .
  python < .

both print a message, return non-zero and do not core dump.

Lib/test/test_cmd_line.py
Modules/main.c
Python/sysmodule.c

index 2d293c90cb28ee9986248335634ef45f9187fb07..a4a656d451bd694ecec3ebd57de45f7d6ffde3c2 100644 (file)
@@ -16,19 +16,8 @@ class CmdLineTest(unittest.TestCase):
         return subprocess.call([sys.executable, cmd_line], stderr=subprocess.PIPE)
 
     def test_directories(self):
-        if sys.platform == 'win32':
-            # Exit code for "python .", Error 13: permission denied = 2
-            expected_exit_code = 2
-        elif sys.platform.startswith('freebsd'):
-            # On FreeBSD, it more likely raise SyntaxError for binary
-            # directory data.
-            expected_exit_code = 1
-        else:
-            # Linux has no problem with "python .", Exit code = 0
-            expected_exit_code = 0
-        self.assertEqual(self.exit_code('.'), expected_exit_code)
-
-        self.assertTrue(self.exit_code('< .') != 0)
+        self.assertNotEqual(self.exit_code('.'), 0)
+        self.assertNotEqual(self.exit_code('< .'), 0)
 
     def verify_valid_flag(self, cmd_line):
         data = self.start_python(cmd_line)
index f6fa48bdd6dee17c369d8e2ead3c39385adb4fc2..8e7c50b25f3204fb95c9d16e0ef689c9bc428f25 100644 (file)
@@ -364,7 +364,8 @@ Py_Main(int argc, char **argv)
                                struct stat sb;
                                if (fstat(fileno(fp), &sb) == 0 &&
                                    S_ISDIR(sb.st_mode)) {
-                                       fprintf(stderr, "%s: warning '%s' is a directory\n", argv[0], filename);
+                                       fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);
+                                       return 1;
                                }
                        }
                }
index 6eadd06d9c3d6f1ee692069ffec9885e66052958..dfa6ac84d91f2aaa7d37b4fb3174a51a1c82b22c 100644 (file)
@@ -1037,7 +1037,10 @@ _PySys_Init(void)
                struct stat sb;
                if (fstat(fileno(stdin), &sb) == 0 &&
                    S_ISDIR(sb.st_mode)) {
-                       Py_FatalError("<stdin> is a directory");
+                       /* There's nothing more we can do. */
+                       /* Py_FatalError() will core dump, so just exit. */
+                       PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
+                       exit(EXIT_FAILURE);
                }
        }