INNER CODE UNIT · Python

is_unset

O-X-L/ansible-opnsense · plugins/module_utils/helper/main.py:77

def is_unset(value: (str, None, list, dict)) -> bool:
    """Determines if a value is effectively 'empty' (None, empty string, or empty collection)."""
    if isinstance(value, (list, dict)):
        return len(value) == 0

    if isinstance(value, str):
        value = value.strip()

    return value in ['', None]


def unset_check_error(params: dict, field: str, fail: bool) -> bool:
    """Validates that a required field is set; optionally exits the module on failure."""
    if is_unset(params[field]):
        if fail:
            exit_cnf(f"Field '{field}' must be set!")

        return False

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…