MCPcopy Create free account
hub / github.com/psf/cachecontrol / _write

Method _write

cachecontrol/caches/file_cache.py:80–96  ·  view source on GitHub ↗

Safely write the data to the given path.

(self, path: str, data: bytes)

Source from the content-addressed store, hash-verified

78 self._write(name, value)
79
80 def _write(self, path: str, data: bytes) -> None:
81 """
82 Safely write the data to the given path.
83 """
84 # Make sure the directory exists
85 dirname = os.path.dirname(path)
86 os.makedirs(dirname, self.dirmode, exist_ok=True)
87
88 with self.lock_class(path + ".lock"):
89 # Write our actual file
90 (fd, name) = tempfile.mkstemp(dir=dirname)
91 try:
92 os.write(fd, data)
93 finally:
94 os.close(fd)
95 os.chmod(name, self.filemode)
96 os.replace(name, path)
97
98 def _delete(self, key: str, suffix: str) -> None:
99 name = self._fn(key) + suffix

Callers 2

setMethod · 0.95
set_bodyMethod · 0.80

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected