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

Skip to content

Commit ba0a3ed

Browse files
committed
Issue #2051: Tweak last commit for this issue to pass in mode instead
of source path to set_data() and make the new argument private until possible API changes can be discussed more thoroughly in Python 3.4.
1 parent 07c6e71 commit ba0a3ed

2 files changed

Lines changed: 1875 additions & 1880 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,13 @@ def path_stats(self, path):
10421042

10431043
def _cache_bytecode(self, source_path, bytecode_path, data):
10441044
# Adapt between the two APIs
1045-
return self.set_data(bytecode_path, data, source_path=source_path)
1045+
try:
1046+
mode = _os.stat(source_path).st_mode
1047+
except OSError:
1048+
mode = 0o666
1049+
return self.set_data(bytecode_path, data, _mode=mode)
10461050

1047-
def set_data(self, path, data, *, source_path=None):
1051+
def set_data(self, path, data, *, _mode=0o666):
10481052
"""Write bytes data to a file."""
10491053
parent, filename = _path_split(path)
10501054
path_parts = []
@@ -1064,14 +1068,8 @@ def set_data(self, path, data, *, source_path=None):
10641068
# If can't get proper access, then just forget about writing
10651069
# the data.
10661070
return
1067-
mode = 0o666
1068-
if source_path is not None:
1069-
try:
1070-
mode = _os.stat(source_path).st_mode
1071-
except OSError:
1072-
pass
10731071
try:
1074-
_write_atomic(path, data, mode)
1072+
_write_atomic(path, data, _mode)
10751073
_verbose_message('created {!r}', path)
10761074
except (PermissionError, FileExistsError):
10771075
# Don't worry if you can't write bytecode or someone is writing

0 commit comments

Comments
 (0)