Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d58e3e

Browse files
committed
Merged revisions 73870,73879,73899-73900,73905-73906 via svnmerge from
svn+ssh://[email protected]/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). ........
1 parent 711ed4a commit 9d58e3e

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

Lib/test/test_import.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import unittest
22
import os
3+
import stat
34
import random
45
import shutil
56
import sys
67
import py_compile
78
import warnings
89
import imp
910
import marshal
10-
from test.support import unlink, TESTFN, unload, run_unittest
11+
from test.support import unlink, TESTFN, unload, run_unittest, TestFailed
1112

1213

1314
def remove_files(name):
@@ -80,6 +81,32 @@ def test_with_extension(ext):
8081
finally:
8182
del sys.path[0]
8283

84+
@unittest.skipUnless(os.name == 'posix', "test meaningful only on posix systems")
85+
def test_execute_bit_not_copied(self):
86+
# Issue 6070: under posix .pyc files got their execute bit set if
87+
# the .py file had the execute bit set, but they aren't executable.
88+
oldmask = os.umask(0o022)
89+
sys.path.insert(0, os.curdir)
90+
try:
91+
fname = TESTFN + os.extsep + "py"
92+
f = open(fname, 'w').close()
93+
os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
94+
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
95+
__import__(TESTFN)
96+
fn = fname + 'c'
97+
if not os.path.exists(fn):
98+
fn = fname + 'o'
99+
if not os.path.exists(fn): raise TestFailed("__import__ did "
100+
"not result in creation of either a .pyc or .pyo file")
101+
s = os.stat(fn)
102+
self.assertEquals(stat.S_IMODE(s.st_mode),
103+
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
104+
finally:
105+
os.umask(oldmask)
106+
remove_files(TESTFN)
107+
if TESTFN in sys.modules: del sys.modules[TESTFN]
108+
del sys.path[0]
109+
83110
def testImpModule(self):
84111
# Verify that the imp module can correctly load and find .py files
85112
import imp
@@ -230,6 +257,7 @@ def test_importbyfilename(self):
230257
else:
231258
self.fail("import by path didn't raise an exception")
232259

260+
233261
class TestPycRewriting(unittest.TestCase):
234262
# Test that the `co_filename` attribute on code objects always points
235263
# to the right file, even when various things happen (e.g. both the .py

Python/import.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,11 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
931931
{
932932
FILE *fp;
933933
time_t mtime = srcstat->st_mtime;
934-
mode_t mode = srcstat->st_mode;
934+
#ifdef MS_WINDOWS /* since Windows uses different permissions */
935+
mode_t mode = srcstat->st_mode & ~S_IEXEC;
936+
#else
937+
mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH;
938+
#endif
935939

936940
fp = open_exclusive(cpathname, mode);
937941
if (fp == NULL) {

0 commit comments

Comments
 (0)