Spaces:
Runtime error
Runtime error
Download src/tutor/services/storage/memory.py from blizzarman/polyglot-tutor: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/spaces/blizzarman/polyglot-tutor/resolve/main/src/tutor/services/storage/memory.py
- Command line
-
hf download hf://spaces/blizzarman/polyglot-tutor/src/tutor/services/storage/memory.py
-
curl -L -o memory.py https://huggingface.co/spaces/blizzarman/polyglot-tutor/resolve/main/src/tutor/services/storage/memory.py
948 Bytes
| """In-memory Repository: M0 default, and the reference fake for tests. | |
| Single-process only (fine for one Gradio app); durable backends (SQLite local, | |
| Supabase Postgres on the Space) land in M3. | |
| """ | |
| from tutor.domain.models import Attempt, Learner | |
| class InMemoryRepository: | |
| def __init__(self) -> None: | |
| self._learners: dict[str, Learner] = {} | |
| self._attempts: dict[str, Attempt] = {} | |
| async def save_learner(self, learner: Learner) -> None: | |
| self._learners[learner.id] = learner | |
| async def get_learner(self, learner_id: str) -> Learner | None: | |
| return self._learners.get(learner_id) | |
| async def save_attempt(self, attempt: Attempt) -> None: | |
| self._attempts[attempt.id] = attempt | |
| async def list_attempts(self, learner_id: str) -> list[Attempt]: | |
| attempts = [a for a in self._attempts.values() if a.learner_id == learner_id] | |
| return sorted(attempts, key=lambda a: a.created_at) | |