(self, name: str, data: bytes, mtime: float | None = None)
| 111 | return f.read() |
| 112 | |
| 113 | def write(self, name: str, data: bytes, mtime: float | None = None) -> bool: |
| 114 | assert not os.path.isabs(name), "Don't use absolute paths!" |
| 115 | |
| 116 | if not self.cache_dir_prefix: |
| 117 | return False |
| 118 | |
| 119 | path = os_path_join(self.cache_dir_prefix, name) |
| 120 | tmp_filename = path + "." + random_string() |
| 121 | try: |
| 122 | os.makedirs(os.path.dirname(path), exist_ok=True) |
| 123 | with open(tmp_filename, "wb") as f: |
| 124 | f.write(data) |
| 125 | os.replace(tmp_filename, path) |
| 126 | if mtime is not None: |
| 127 | os.utime(path, times=(mtime, mtime)) |
| 128 | |
| 129 | except OSError: |
| 130 | return False |
| 131 | return True |
| 132 | |
| 133 | def remove(self, name: str) -> None: |
| 134 | if not self.cache_dir_prefix: |
no test coverage detected