Spaces:
Running on Zero
Running on Zero
File size: 930 Bytes
13fe947 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """Shared, dependency-free text and timestamp helpers.
Kept stdlib-only so it is safe to import from any runtime (Modal containers,
embedding subprocesses) and from the export modules without creating cycles.
"""
from __future__ import annotations
from datetime import datetime, timezone
from typing import Any
def clean(value: Any) -> str:
"""Collapse whitespace to single spaces; ``None`` becomes an empty string."""
if value is None:
return ""
return " ".join(str(value).split())
def list_of_dicts(value: Any) -> list[dict[str, Any]]:
"""Return only the ``dict`` items of ``value`` when it is a list, else ``[]``."""
if not isinstance(value, list):
return []
return [item for item in value if isinstance(item, dict)]
def utc_now() -> str:
"""Current UTC time as an ISO-8601 string at second resolution."""
return datetime.now(timezone.utc).isoformat(timespec="seconds")
|