INNER CODE UNIT · Python
is_true
O-X-L/ansible-opnsense · plugins/module_utils/helper/main.py:42
def is_true(data: (str, int, bool)) -> bool:
"""Checks if input equates to a boolean 'True' (1, '1', or True)."""
return data in [1, '1', True]
def to_digit(data: bool) -> int:
"""Converts a boolean to an integer (1 or 0)."""
return 1 if data else 0
def format_int(data: (int, str)) -> (int, str, None):
"""Safely converts numeric strings to integers while preserving None or non-numeric strings."""
if isinstance(data, int):
return data
if data is None:
return None