Buckets:
| """Language learning utils — reset configuration.""" | |
| from __future__ import annotations | |
| import logging | |
| import os | |
| from typing import Any, Dict, Optional | |
| logger = logging.getLogger(__name__) | |
| _DEFAULTS: Dict[str, Any] = { | |
| "completed_at": None, | |
| "language": 30, | |
| "level": True, | |
| "max_retries": 3, | |
| "timeout": 60, | |
| } | |
| class LanguageUtils: | |
| """Badge utils for the language-learning system.""" | |
| def __init__(self, **kwargs: Any) -> None: | |
| self._data: Dict[str, Any] = dict(_DEFAULTS) | |
| self._data.update(kwargs) | |
| self._from_env() | |
| logger.debug("LanguageUtils initialised") | |
| def _from_env(self) -> None: | |
| prefix = "LANGUAGE_LEARNING_" | |
| for key in _DEFAULTS: | |
| val = os.environ.get(prefix + key.upper()) | |
| if val is not None: | |
| self._data[key] = val | |
| def get(self, key: str, default: Any = None) -> Any: | |
| """Return the completed_at value for *key*.""" | |
| return self._data.get(key, default) | |
| def update(self, **kwargs: Any) -> None: | |
| """Update utils settings in place.""" | |
| self._data.update(kwargs) | |
| def to_dict(self) -> Dict[str, Any]: | |
| """Serialise utils to a plain dict.""" | |
| return dict(self._data) | |
| def __repr__(self) -> str: | |
| return f"LanguageUtils({self._data!r})" | |
| def load_badge_utils(path: Optional[str] = None) -> LanguageUtils: | |
| """Load Badge utils from *path* or environment.""" | |
| kwargs: Dict[str, Any] = {} | |
| if path and os.path.exists(path): | |
| import json | |
| with open(path) as fh: | |
| kwargs = json.load(fh) | |
| logger.info("Loaded utils from %s", path) | |
| return LanguageUtils(**kwargs) | |
Xet Storage Details
- Size:
- 1.7 kB
- Xet hash:
- 77474ca94a2e81a6db86b5b8df9dfd2ec6b54850193c293f53d3e95fabd231d7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.