Return a file path based on a hash of the string, fontsize, and dpi.
(cls, tex, fontsize, dpi=None)
| 167 | |
| 168 | @classmethod |
| 169 | def _get_base_path(cls, tex, fontsize, dpi=None): |
| 170 | """ |
| 171 | Return a file path based on a hash of the string, fontsize, and dpi. |
| 172 | """ |
| 173 | src = cls._get_tex_source(tex, fontsize) + str(dpi) |
| 174 | filehash = hashlib.sha256( |
| 175 | src.encode('utf-8'), |
| 176 | usedforsecurity=False |
| 177 | ).hexdigest() |
| 178 | filepath = cls._cache_dir |
| 179 | |
| 180 | num_letters, num_levels = 2, 2 |
| 181 | for i in range(0, num_letters*num_levels, num_letters): |
| 182 | filepath = filepath / filehash[i:i+2] |
| 183 | |
| 184 | filepath.mkdir(parents=True, exist_ok=True) |
| 185 | return filepath / filehash |
| 186 | |
| 187 | @classmethod |
| 188 | def get_basefile(cls, tex, fontsize, dpi=None): # Kept for backcompat. |
no test coverage detected