"""Helpers shared by the parsers: WS-Management values are strings, lists or missing.""" from __future__ import annotations from typing import Any #: Values firmware puts where it has nothing to say (SMBIOS defaults), compared lowercased. PLACEHOLDERS = frozenset( { "", "0", "none", "default string", "not specified", "to be filled by o.e.m.", "system product name", "system serial number", "123456789", } ) def as_list(value: Any) -> list[Any]: """A repeated element as a list; a single one as a list of one; none as empty.""" if value is None or value == "": return [] return value if isinstance(value, list) else [value] def first(value: Any) -> Any: """The first of a value that may be repeated.""" values = as_list(value) return values[0] if values else None def to_int(value: Any) -> int | None: try: return int(str(first(value)).strip()) except (TypeError, ValueError): return None def is_true(value: Any) -> bool: return str(first(value)).strip().lower() in ("true", "1") def text(value: Any) -> str: """A string value, stripped; a missing or nested one as empty.""" value = first(value) return value.strip() if isinstance(value, str) else "" def meaningful(value: Any) -> str: """``text(value)``, or empty for a firmware placeholder.""" result = text(value) return "" if result.lower() in PLACEHOLDERS else result