INNER CODE UNIT · Python
is_number_in_list
arnonym/ha-plugins · ha-sip/src/account.py:178
def is_number_in_list(number: Optional[str], number_list: list[str]) -> bool:
def map_to_regex(st: str) -> str:
if st == '{*}':
return '.*'
if st == '{?}':
return '.'
return re.escape(st)
if not number:
return False
for n in number_list:
# split by {*} and {?} keeping delimiters
n_split = re.split(r'(\{\*}|\{\?})', n)
n_regex = '^' + ''.join(map(map_to_regex, n_split)) + '$'
match = re.match(n_regex, number)
if match:
return True
return False