Download cases/cinema/raw/mcp_servers/utils.py from JoeYing/ReScopeBench: direct link, hf CLI and curl.
- Browser
- Download file 3.44 kB
-
https://huggingface.co/datasets/JoeYing/ReScopeBench/resolve/main/cases/cinema/raw/mcp_servers/utils.py
- Command line
-
hf download hf://datasets/JoeYing/ReScopeBench/cases/cinema/raw/mcp_servers/utils.py
-
curl -L -o utils.py https://huggingface.co/datasets/JoeYing/ReScopeBench/resolve/main/cases/cinema/raw/mcp_servers/utils.py
3.44 kB
| """Shared validation, ID, and response helpers for the cinema environment.""" | |
| from __future__ import annotations | |
| import copy | |
| import re | |
| from datetime import datetime, timezone | |
| from typing import Any, Dict, Iterable, Optional | |
| ID_PREFIXES: Dict[str, str] = { | |
| "venue": "venue", | |
| "auditorium": "auditorium", | |
| "seat": "seat", | |
| "movie": "movie", | |
| "pricing_plan": "price", | |
| "member": "member", | |
| "showtime": "showtime", | |
| "seat_hold": "hold", | |
| "booking": "booking", | |
| "ticket": "ticket", | |
| "concession_item": "item", | |
| "concession_order": "order", | |
| "payment": "payment", | |
| "group_reservation": "group", | |
| "promo_code": "promo", | |
| "box_office_day": "boxday", | |
| } | |
| LEGACY_ID_PREFIXES: Dict[str, str] = { | |
| "venue": "VEN", | |
| "auditorium": "AUD", | |
| "seat": "SEAT", | |
| "movie": "MOV", | |
| "pricing_plan": "PRICE", | |
| "member": "MEM", | |
| "showtime": "SHOW", | |
| "seat_hold": "HOLD", | |
| "booking": "BOOK", | |
| "ticket": "TICK", | |
| "concession_item": "ITEM", | |
| "concession_order": "ORDER", | |
| "payment": "PAY", | |
| "group_reservation": "GROUP", | |
| "promo_code": "PROMO", | |
| "box_office_day": "BOX", | |
| } | |
| def success_response(data: Dict[str, Any], message: str = "") -> Dict[str, Any]: | |
| return {"status": "success", "data": data, "message": message} | |
| def error_response(error_code: str, message: str) -> Dict[str, Any]: | |
| return {"status": "error", "data": {}, "message": f"{error_code}: {message}"} | |
| def now_iso() -> str: | |
| return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") | |
| def safe_copy(value: Any) -> Any: | |
| return copy.deepcopy(value) | |
| def slugify(value: Any) -> str: | |
| text = str(value or "").strip().lower() | |
| text = re.sub(r"[^a-z0-9]+", "-", text) | |
| text = re.sub(r"-+", "-", text).strip("-") | |
| return text or "record" | |
| def generate_id(entity_type: str, sequence: int) -> str: | |
| prefix = ID_PREFIXES.get(entity_type, slugify(entity_type)) | |
| return f"{prefix}-generated-{int(sequence)}" | |
| def validate_id_format(value: str, entity_type: str) -> bool: | |
| prefix = ID_PREFIXES.get(entity_type) | |
| if not prefix or not isinstance(value, str): | |
| return False | |
| return bool(re.match(rf"^{re.escape(prefix)}-[a-z0-9][a-z0-9-]*$", value)) | |
| def extract_id_sequence(value: Any, entity_type: Optional[str] = None) -> Optional[int]: | |
| if not isinstance(value, str): | |
| return None | |
| match = re.search(r"-(\d+)$", value) | |
| if not match: | |
| return None | |
| return int(match.group(1)) | |
| def build_humanized_id(entity_type: str, record: Dict[str, Any], *, existing_ids: Optional[Iterable[str]] = None) -> str: | |
| existing = set(existing_ids or []) | |
| prefix = ID_PREFIXES.get(entity_type, slugify(entity_type)) | |
| parts = [prefix] | |
| for key in ("name", "title", "full_name", "customer_name", "code", "business_date", "starts_at"): | |
| value = record.get(key) | |
| if value: | |
| parts.append(slugify(str(value).replace(":", "-")[:48])) | |
| break | |
| candidate = "-".join(parts) | |
| if candidate not in existing: | |
| return candidate | |
| index = 1 | |
| while f"{candidate}-{index}" in existing: | |
| index += 1 | |
| return f"{candidate}-{index}" | |
| def validate_email_address(value: Any) -> bool: | |
| return isinstance(value, str) and bool(re.match(r"^[^@\s]+@[^@\s]+\.[^@\s]+$", value)) | |
| def validate_phone(value: Any) -> bool: | |
| return isinstance(value, str) and bool(re.match(r"^\+?[0-9][0-9\- ()]{6,24}$", value)) | |