"""How the Proxmox VE API writes plain values: numbers as strings, flags as 0/1, lists as comma-separated strings.""" from __future__ import annotations import re from typing import Any _LIST_SEPARATORS = re.compile(r"[\s,;\0]+") def to_int(value: Any) -> int | None: return None if value is None else int(value) def to_flag(value: Any) -> bool: return bool(int(value or 0)) def split_list(value: Any) -> list[str]: """``"a,b"`` -> ``["a", "b"]``; PVE also separates with ``;``, blanks or NUL.""" return [part for part in _LIST_SEPARATORS.split(str(value or "")) if part] def vmid_list(value: Any) -> list[int]: """``"100,101"`` -> ``[100, 101]``; what is not a number is left out.""" return [int(part) for part in split_list(value) if part.isdigit()]