MCPcopy Index your code
hub / github.com/RustPython/RustPython / set_data

Method set_data

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

Write bytes data to a file.

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

Source from the content-addressed store, hash-verified

974 return self.set_data(bytecode_path, data, _mode=mode)
975
976 def set_data(self, path, data, *, _mode=0o666):
977 """Write bytes data to a file."""
978 parent, filename = _path_split(path)
979 path_parts = []
980 # Figure out what directories are missing.
981 while parent and not _path_isdir(parent):
982 parent, part = _path_split(parent)
983 path_parts.append(part)
984 # Create needed directories.
985 for part in reversed(path_parts):
986 parent = _path_join(parent, part)
987 try:
988 _os.mkdir(parent)
989 except FileExistsError:
990 # Probably another Python process already created the dir.
991 continue
992 except OSError as exc:
993 # Could be a permission error, read-only filesystem: just forget
994 # about writing the data.
995 _bootstrap._verbose_message('could not create {!r}: {!r}',
996 parent, exc)
997 return
998 try:
999 _write_atomic(path, data, _mode)
1000 _bootstrap._verbose_message('created {!r}', path)
1001 except OSError as exc:
1002 # Same as above: just don't write the bytecode.
1003 _bootstrap._verbose_message('could not create {!r}: {!r}', path,
1004 exc)
1005
1006
1007class SourcelessFileLoader(FileLoader, _LoaderBasics):

Callers 1

_cache_bytecodeMethod · 0.95

Calls 7

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

Tested by

no test coverage detected