"""Util for getting type of data.""" import json from typing import Any from video.constants import field_types def stringify(value: Any) -> str: """Stringify value.""" return json.dumps(value) def unstringify(value: Any) -> Any: """Unstringify value.""" try: return json.loads(value) except Exception: return value def typer(data_to_type: Any) -> str | None: """Return the ows-video type string for an arbitrary value, or None if unrecognized.""" if isinstance(data_to_type, dict): return field_types.JSON if isinstance(data_to_type, list): return field_types.JSON if isinstance(data_to_type, str): return field_types.STRING if isinstance(data_to_type, bool): return field_types.BOOLEAN if isinstance(data_to_type, int): return field_types.INTEGER if isinstance(data_to_type, float): return field_types.FLOAT if isinstance(data_to_type, type(None)): return field_types.NULL return None