git_brcal/src/server/BreCal/validators/validation_base_utils.py

27 lines
1017 B
Python

import typing
from string import ascii_letters, digits
def check_if_string_has_special_characters(text:typing.Optional[str]):
"""
check, whether there are any characters within the provided string, which are not found in the ascii letters or digits
ascii_letters: abcd (...) and ABCD (...)
digits: 0123 (...)
Source: https://stackoverflow.com/questions/57062794/is-there-a-way-to-check-if-a-string-contains-special-characters
User: https://stackoverflow.com/users/10035985/andrej-kesely
returns bool
"""
if text is None:
return False
return bool(set(text).difference(ascii_letters + digits + ' '))
def check_if_int_is_valid_flag(value, enum_object):
if value is None: # when no value is provided, the value is considered valid.
return False
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
max_int = sum([int(val) for val in list(enum_object._value2member_map_.values())])
return 0 < value <= max_int