WebsiteBench / tasks /everyplate /environment /reference /clone /websitebench /site_backend /backend.py
Download tasks/everyplate/environment/reference/clone/websitebench/site_backend/backend.py from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/everyplate/environment/reference/clone/websitebench/site_backend/backend.py
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/everyplate/environment/reference/clone/websitebench/site_backend/backend.py
-
curl -L -o backend.py https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/everyplate/environment/reference/clone/websitebench/site_backend/backend.py
1.6 kB
| """The small public interface for one site-isolated backend.""" | |
| from __future__ import annotations | |
| from collections.abc import Callable, Mapping | |
| from pathlib import Path | |
| from typing import Any | |
| import sqlite3 | |
| from .database import SiteDatabaseLifecycle | |
| from .mail import SiteMail | |
| from .payments import SitePayments | |
| from .runtime import RuntimeConfig, load_runtime | |
| class SiteBackend: | |
| """One runtime contract, one site binding, and three deep capabilities.""" | |
| def __init__( | |
| self, | |
| runtime: RuntimeConfig, | |
| lifecycle: SiteDatabaseLifecycle, | |
| ) -> None: | |
| self.config = runtime | |
| self.lifecycle = lifecycle | |
| self.mail = SiteMail(runtime, lifecycle) | |
| self.payments = SitePayments(runtime, lifecycle) | |
| def open( | |
| cls, | |
| config: Path | str | Mapping[str, Any], | |
| *, | |
| data_root: Path | None = None, | |
| migration_hook: Callable[[sqlite3.Connection], None] | None = None, | |
| seed_hook: Callable[[sqlite3.Connection], None] | None = None, | |
| ) -> "SiteBackend": | |
| runtime = load_runtime(config) | |
| lifecycle = SiteDatabaseLifecycle( | |
| runtime, | |
| data_root=data_root, | |
| migration_hook=migration_hook, | |
| seed_hook=seed_hook, | |
| ) | |
| return cls(runtime, lifecycle) | |
| def session_cookie(self) -> dict[str, Any]: | |
| """Framework-neutral Host-only cookie facts; intentionally no Domain.""" | |
| return { | |
| "name": self.config.cookie_name, | |
| **dict(self.config.cookie_options), | |
| } | |