icinga2-checks/checker/types.py

21 lines
411 B
Python
Raw Permalink Normal View History

2024-01-14 12:15:17 -07:00
from typing import Union
2024-02-18 12:55:45 -07:00
def try_float(value: str) -> float:
2023-12-19 22:43:21 -07:00
try:
return float(value)
except:
pass
try:
2024-02-18 12:55:45 -07:00
return float(int(value))
2023-12-19 22:43:21 -07:00
except:
pass
raise ValueError(f"Could not convert {value} to float or int")
2024-02-18 12:55:45 -07:00
def try_int(value: str) -> int:
try:
return int(value)
except:
raise ValueError(f"Could not convert {value} to float or int")