INNER CODE UNIT · Python

_finite_json_float

mars-tw/anti-gambling-trader-tw · core/ui/server.py:97

def _finite_json_float(value: str) -> float:
    """Parse a JSON decimal only when Python can represent it finitely."""

    number = float(value)
    if not math.isfinite(number):
        raise ValueError("JSON 數字必須是有限值")
    return number


def _static_path(name: str) -> Path:
    return Path(__file__).resolve().parent / "static" / name


def _ascii_download_name(filename: str) -> str:
    normalized = unicodedata.normalize("NFKD", filename)
    raw = normalized.encode("ascii", "ignore").decode("ascii")
    safe = re.sub(r"[^A-Za-z0-9._-]+", "_", raw).strip("._")
    suffix = Path(filename).suffix.lower()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…