diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-07-19 01:59:05 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-07-19 01:59:05 (GMT) |
commit | 07fc01f9efa00e04d38d19bb722f65be0a1f39ad (patch) | |
tree | 4c3b6f1c5aa87abab7795ade47c97330427f0e38 | |
parent | 8d15643a4bbb118a2fc91541d3b02d7aca7953d9 (diff) | |
download | cpython-07fc01f9efa00e04d38d19bb722f65be0a1f39ad.zip cpython-07fc01f9efa00e04d38d19bb722f65be0a1f39ad.tar.gz cpython-07fc01f9efa00e04d38d19bb722f65be0a1f39ad.tar.bz2 |
Merged revisions 74058 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r74058 | alexandre.vassalotti | 2009-07-17 06:55:50 -0400 (Fri, 17 Jul 2009) | 36 lines
Merged revisions 73870,73879,73899-73900,73905-73906 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73870 | r.david.murray | 2009-07-06 21:06:13 -0400 (Mon, 06 Jul 2009) | 5 lines
Issue 6070: when creating a compiled file, after copying the mode bits, on
posix zap the execute bit in case it was set on the .py file, since the
compiled files are not directly executable on posix. Patch by Marco N.
........
r73879 | r.david.murray | 2009-07-07 05:54:16 -0400 (Tue, 07 Jul 2009) | 3 lines
Update issue 6070 patch to match the patch that was actually tested
on Windows.
........
r73899 | r.david.murray | 2009-07-08 21:43:41 -0400 (Wed, 08 Jul 2009) | 3 lines
Conditionalize test cleanup code to eliminate traceback, which will
hopefully reveal the real problem.
........
r73900 | r.david.murray | 2009-07-08 22:06:17 -0400 (Wed, 08 Jul 2009) | 2 lines
Make test work with -O.
........
r73905 | r.david.murray | 2009-07-09 09:55:44 -0400 (Thu, 09 Jul 2009) | 3 lines
Specify umask in execute bit test to get consistent results
and make sure we test resetting all three execute bits.
........
r73906 | r.david.murray | 2009-07-09 11:35:33 -0400 (Thu, 09 Jul 2009) | 5 lines
Curdir needs to be in the path for the test to work on all buildbots.
(I copied this from another import test, but currently this will fail if
TESTFN ends up in /tmp...see issue 2609).
........
................
-rw-r--r-- | Lib/test/test_import.py | 30 | ||||
-rw-r--r-- | Python/import.c | 6 |
2 files changed, 34 insertions, 2 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index dbfadfb7..8196865 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -1,5 +1,6 @@ import unittest import os +import stat import random import shutil import sys @@ -7,7 +8,7 @@ import py_compile import warnings import imp import marshal -from test.support import unlink, TESTFN, unload, run_unittest +from test.support import unlink, TESTFN, unload, run_unittest, TestFailed def remove_files(name): @@ -80,6 +81,32 @@ class ImportTest(unittest.TestCase): finally: del sys.path[0] + @unittest.skipUnless(os.name == 'posix', "test meaningful only on posix systems") + def test_execute_bit_not_copied(self): + # Issue 6070: under posix .pyc files got their execute bit set if + # the .py file had the execute bit set, but they aren't executable. + oldmask = os.umask(0o022) + sys.path.insert(0, os.curdir) + try: + fname = TESTFN + os.extsep + "py" + f = open(fname, 'w').close() + os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | + stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) + __import__(TESTFN) + fn = fname + 'c' + if not os.path.exists(fn): + fn = fname + 'o' + if not os.path.exists(fn): raise TestFailed("__import__ did " + "not result in creation of either a .pyc or .pyo file") + s = os.stat(fn) + self.assertEquals(stat.S_IMODE(s.st_mode), + stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) + finally: + os.umask(oldmask) + remove_files(TESTFN) + if TESTFN in sys.modules: del sys.modules[TESTFN] + del sys.path[0] + def testImpModule(self): # Verify that the imp module can correctly load and find .py files import imp @@ -230,6 +257,7 @@ class ImportTest(unittest.TestCase): else: self.fail("import by path didn't raise an exception") + class TestPycRewriting(unittest.TestCase): # Test that the `co_filename` attribute on code objects always points # to the right file, even when various things happen (e.g. both the .py diff --git a/Python/import.c b/Python/import.c index bccb971..2b82587 100644 --- a/Python/import.c +++ b/Python/import.c @@ -930,7 +930,11 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat) { FILE *fp; time_t mtime = srcstat->st_mtime; - mode_t mode = srcstat->st_mode; +#ifdef MS_WINDOWS /* since Windows uses different permissions */ + mode_t mode = srcstat->st_mode & ~S_IEXEC; +#else + mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH; +#endif fp = open_exclusive(cpathname, mode); if (fp == NULL) { |