diff options
author | Brett Cannon <brett@python.org> | 2013-04-14 16:48:15 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-04-14 16:48:15 (GMT) |
commit | edfd6ae79c76ebf766ffc1da1e8003ab72df6475 (patch) | |
tree | 7c7387f82f4e909e0a96b3e6a82d7f7e3e475156 /Lib/importlib | |
parent | 672559fc4f6d3811440965a12d900209f364b5f0 (diff) | |
download | cpython-edfd6ae79c76ebf766ffc1da1e8003ab72df6475.zip cpython-edfd6ae79c76ebf766ffc1da1e8003ab72df6475.tar.gz cpython-edfd6ae79c76ebf766ffc1da1e8003ab72df6475.tar.bz2 |
Issue #17244: Don't mask exceptions raised during the creation of
bytecode files in py_compile.
Thanks to Arfrever Frehtes Taifersar Arahesis for the bug report.
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 03ca79f..77c14bc 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -474,6 +474,18 @@ def _get_sourcefile(bytecode_path): return source_path if _path_isfile(source_stats) else bytecode_path +def _calc_mode(path): + """Calculate the mode permissions for a bytecode file.""" + try: + mode = _os.stat(path).st_mode + except OSError: + mode = 0o666 + # We always ensure write access so we can update cached files + # later even when the source files are read-only on Windows (#6074) + mode |= 0o200 + return mode + + def _verbose_message(message, *args, verbosity=1): """Print the message to stderr if -v/PYTHONVERBOSE is turned on.""" if sys.flags.verbose >= verbosity: @@ -1060,13 +1072,7 @@ class SourceFileLoader(FileLoader, SourceLoader): def _cache_bytecode(self, source_path, bytecode_path, data): # Adapt between the two APIs - try: - mode = _os.stat(source_path).st_mode - except OSError: - mode = 0o666 - # We always ensure write access so we can update cached files - # later even when the source files are read-only on Windows (#6074) - mode |= 0o200 + mode = _calc_mode(source_path) return self.set_data(bytecode_path, data, _mode=mode) def set_data(self, path, data, *, _mode=0o666): |