mirror of
https://github.com/simple-login/app.git
synced 2024-11-14 08:01:13 +01:00
18 lines
497 B
Python
18 lines
497 B
Python
import re
|
|
|
|
import re2
|
|
|
|
from app.log import LOG
|
|
|
|
|
|
def regex_match(rule_regex: str, local):
|
|
regex = re2.compile(rule_regex)
|
|
try:
|
|
if re2.fullmatch(regex, local):
|
|
return True
|
|
except TypeError: # re2 bug "Argument 'pattern' has incorrect type (expected bytes, got PythonRePattern)"
|
|
LOG.w("use re instead of re2 for %s %s", rule_regex, local)
|
|
regex = re.compile(rule_regex)
|
|
if re.fullmatch(regex, local):
|
|
return True
|
|
return False
|