Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da68818d4f |
@@ -5,10 +5,33 @@ List of regex compiled strings that can be used
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
EMAIL_REGEX_BASIC = r"""
|
def compile_re(reg: str) -> re.Pattern[str]:
|
||||||
|
"""
|
||||||
|
compile a regex with verbose flag
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
reg {str} -- _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
re.Pattern[str] -- _description_
|
||||||
|
"""
|
||||||
|
return re.compile(reg, re.VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
|
# email regex
|
||||||
|
EMAIL_BASIC_REGEX = r"""
|
||||||
^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}
|
^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}
|
||||||
@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$
|
@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$
|
||||||
"""
|
"""
|
||||||
EMAIL_REGEX_BASIC_COMPILED = re.compile(EMAIL_REGEX_BASIC)
|
# Domain regex with localhost
|
||||||
|
DOMAIN_WITH_LOCALHOST_REGEX = r"""
|
||||||
|
^(?:localhost|(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,})$
|
||||||
|
"""
|
||||||
|
# domain regex with loclhost and optional port
|
||||||
|
DOMAIN_WITH_LOCALHOST_PORT_REGEX = r"""
|
||||||
|
^(?:localhost|(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,})(?::\d+)?$
|
||||||
|
"""
|
||||||
|
# Domain, no localhost
|
||||||
|
DOMAIN_REGEX = r"^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$"
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ Class of checks that can be run on value entries
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
from corelibs.check_handling.regex_constants import EMAIL_REGEX_BASIC
|
from corelibs.check_handling.regex_constants import (
|
||||||
|
EMAIL_BASIC_REGEX, DOMAIN_WITH_LOCALHOST_REGEX, DOMAIN_WITH_LOCALHOST_PORT_REGEX, DOMAIN_REGEX
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SettingsLoaderCheckValue(TypedDict):
|
class SettingsLoaderCheckValue(TypedDict):
|
||||||
@@ -45,27 +47,25 @@ class SettingsLoaderCheck:
|
|||||||
},
|
},
|
||||||
# This does a baisc email check, only alphanumeric with special characters
|
# This does a baisc email check, only alphanumeric with special characters
|
||||||
"string.email.basic": {
|
"string.email.basic": {
|
||||||
"regex": EMAIL_REGEX_BASIC,
|
"regex": EMAIL_BASIC_REGEX,
|
||||||
"regex_clean": None,
|
"regex_clean": None,
|
||||||
"replace": "",
|
"replace": "",
|
||||||
},
|
},
|
||||||
# Domain check, including localhost no port
|
# Domain check, including localhost no port
|
||||||
"string.domain.with-localhost": {
|
"string.domain.with-localhost": {
|
||||||
"regex": r"^(?:localhost|(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,})$",
|
"regex": DOMAIN_WITH_LOCALHOST_REGEX,
|
||||||
"regex_clean": None,
|
"regex_clean": None,
|
||||||
"replace": "",
|
"replace": "",
|
||||||
},
|
},
|
||||||
# Domain check, with localhost and port
|
# Domain check, with localhost and port
|
||||||
"string.domain.with-localhost.port": {
|
"string.domain.with-localhost.port": {
|
||||||
"regex": r"""
|
"regex": DOMAIN_WITH_LOCALHOST_PORT_REGEX,
|
||||||
^(?:localhost|(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,})(?::\d+)?$
|
|
||||||
""",
|
|
||||||
"regex_clean": None,
|
"regex_clean": None,
|
||||||
"replace": "",
|
"replace": "",
|
||||||
},
|
},
|
||||||
# Domain check, no pure localhost allowed
|
# Domain check, no pure localhost allowed
|
||||||
"string.domain": {
|
"string.domain": {
|
||||||
"regex": r"^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[A-Za-z]{2,}$",
|
"regex": DOMAIN_REGEX,
|
||||||
"regex_clean": None,
|
"regex_clean": None,
|
||||||
"replace": "",
|
"replace": "",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user