MCPcopy Index your code
hub / github.com/python/cpython / set_data

Method set_data

Lib/importlib/_bootstrap_external.py:948–976  ·  view source on GitHub ↗

Write bytes data to a file.

(self, path, data, *, _mode=0o666)

Source from the content-addressed store, hash-verified

946 return self.set_data(bytecode_path, data, _mode=mode)
947
948 def set_data(self, path, data, *, _mode=0o666):
949 """Write bytes data to a file."""
950 parent, filename = _path_split(path)
951 path_parts = []
952 # Figure out what directories are missing.
953 while parent and not _path_isdir(parent):
954 parent, part = _path_split(parent)
955 path_parts.append(part)
956 # Create needed directories.
957 for part in reversed(path_parts):
958 parent = _path_join(parent, part)
959 try:
960 _os.mkdir(parent)
961 except FileExistsError:
962 # Probably another Python process already created the dir.
963 continue
964 except OSError as exc:
965 # Could be a permission error, read-only filesystem: just forget
966 # about writing the data.
967 _bootstrap._verbose_message('could not create {!r}: {!r}',
968 parent, exc)
969 return
970 try:
971 _write_atomic(path, data, _mode)
972 _bootstrap._verbose_message('created {!r}', path)
973 except OSError as exc:
974 # Same as above: just don't write the bytecode.
975 _bootstrap._verbose_message('could not create {!r}: {!r}', path,
976 exc)
977
978
979class SourcelessFileLoader(FileLoader, _LoaderBasics):

Callers 1

_cache_bytecodeMethod · 0.95

Calls 6

_path_splitFunction · 0.85
_path_isdirFunction · 0.85
_path_joinFunction · 0.85
_write_atomicFunction · 0.85
appendMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected