Files
group_fqcd_jr/app/core/cursor.py
T

18 lines
590 B
Python
Raw Normal View History

2026-09-11 09:47:40 +08:00
"""Strict parsing for record-ID pagination cursors."""
from app.core.errors import InvalidCursorError
MAX_CURSOR_VALUE = 2**63 - 1
def parse_cursor(raw: str | None, *, field: str = "cursor") -> int | None:
if raw is None or not raw.strip():
return None
value = raw.strip()
if not value.isascii() or not value.isdigit():
raise InvalidCursorError(f"{field} must be an ASCII decimal record ID")
parsed = int(value)
if parsed < 1 or parsed > MAX_CURSOR_VALUE:
raise InvalidCursorError(f"{field} is outside the record ID range")
return parsed