-
Notifications
You must be signed in to change notification settings - Fork 0
/
Validators.py
38 lines (34 loc) · 1.37 KB
/
Validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from tracelog import *
class Validators:
# Validate floating point number such as latitude, longitude
@classmethod
@tracelog
def valid_float_in_range(cls, proposed_value: str, min_value: float, max_value: float) -> float:
"""Validate that a string is a floating point number in a given range"""
# print(f"validFloatInRange({proposed_value},{min},{max})")
# noinspection PyTypeChecker
result: float = None
try:
converted: float = float(proposed_value)
if (converted >= min_value) and (converted <= max_value):
result = converted
except ValueError:
# Let result go back as "none", indicating error
pass
return result
# Validate integer number
@classmethod
@tracelog
def valid_int_in_range(cls, proposed_value: str, min_value: int, max_value: int) -> int:
"""Validate that a string is an integer in a given range"""
# print(f"validIntInRange({proposed_value},{min},{max})")
# noinspection PyTypeChecker
result: int = None
try:
converted: int = int(proposed_value)
if (converted >= min_value) and (converted <= max_value):
result = converted
except ValueError:
# Let result go back as "none", indicating error
pass
return result