Buckets:
| import os | |
| from pathlib import Path | |
| from typing import Dict, Any, Optional | |
| def ensure_dir(path: str) -> None: | |
| p = Path(path) | |
| p.mkdir(parents=True, exist_ok=True) | |
| def ensure_file(path: str, contents: str = "") -> None: | |
| p = Path(path) | |
| ensure_dir(str(p.parent)) | |
| if not p.exists(): | |
| p.write_text(contents) | |
| class SafeDictAccessReadOnly: | |
| def __init__(self, obj: Dict[str, Any]): | |
| self._d = obj | |
| def get(self, key: str, default: Any = None) -> Optional[Any]: | |
| ks = key.split(".", 1) | |
| if len(ks) == 1: | |
| return self._d.get(key, default) | |
| outer = self._d.get(ks[0], {}) | |
| if not isinstance(outer, dict): | |
| return default | |
| return SafeDictAccessReadOnly(outer)._d.get(ks[1], default) | |
| def string_with_default(self, key: str, default: str) -> str: | |
| v = self.get(key) | |
| return str(v) if v is not None else default | |
Xet Storage Details
- Size:
- 918 Bytes
- Xet hash:
- 2dd38b7c9519c16ac53448583371b2954da1c4316a64e29b94b82d3bad72970f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.