Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da68818d4f | ||
|
|
db6a3b53c5 | ||
|
|
82b089498e | ||
|
|
948b0dd5e7 | ||
|
|
4acc0b51b1 | ||
|
|
a626b738a9 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.12.6"
|
version = "0.13.1"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -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__
|
||||||
|
|||||||
@@ -258,6 +258,12 @@ class SettingsLoader:
|
|||||||
self.__build_from_to_equal(entry, check)
|
self.__build_from_to_equal(entry, check)
|
||||||
):
|
):
|
||||||
error = True
|
error = True
|
||||||
|
# after post clean up if we have empty entries and we are mandatory
|
||||||
|
if check == "mandatory:yes" and (
|
||||||
|
not settings[config_id].get(entry) or settings[config_id].get(entry) == ['']
|
||||||
|
):
|
||||||
|
error = True
|
||||||
|
self.__print(f"[!] Missing content entry for: {entry}", 'ERROR')
|
||||||
if error is True:
|
if error is True:
|
||||||
raise ValueError(self.__print("[!] Missing or incorrect settings data. Cannot proceed", 'CRITICAL'))
|
raise ValueError(self.__print("[!] Missing or incorrect settings data. Cannot proceed", 'CRITICAL'))
|
||||||
# set empty
|
# set empty
|
||||||
|
|||||||
@@ -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,10 +47,34 @@ 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
|
||||||
|
"string.domain.with-localhost": {
|
||||||
|
"regex": DOMAIN_WITH_LOCALHOST_REGEX,
|
||||||
|
"regex_clean": None,
|
||||||
|
"replace": "",
|
||||||
|
},
|
||||||
|
# Domain check, with localhost and port
|
||||||
|
"string.domain.with-localhost.port": {
|
||||||
|
"regex": DOMAIN_WITH_LOCALHOST_PORT_REGEX,
|
||||||
|
"regex_clean": None,
|
||||||
|
"replace": "",
|
||||||
|
},
|
||||||
|
# Domain check, no pure localhost allowed
|
||||||
|
"string.domain": {
|
||||||
|
"regex": DOMAIN_REGEX,
|
||||||
|
"regex_clean": None,
|
||||||
|
"replace": "",
|
||||||
|
},
|
||||||
|
# Basic date check, does not validate date itself
|
||||||
|
"string.date": {
|
||||||
|
"regex": r"^\d{4}[/-]\d{1,2}[/-]\d{1,2}$",
|
||||||
|
"regex_clean": None,
|
||||||
|
"replace": "",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
Settings loader test
|
Settings loader test
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from corelibs.iterator_handling.dump_data import dump_data
|
from corelibs.debug_handling.dump_data import dump_data
|
||||||
from corelibs.logging_handling.log import Log
|
from corelibs.logging_handling.log import Log
|
||||||
from corelibs.config_handling.settings_loader import SettingsLoader
|
from corelibs.config_handling.settings_loader import SettingsLoader
|
||||||
|
from corelibs.config_handling.settings_loader_handling.settings_loader_check import SettingsLoaderCheck
|
||||||
|
|
||||||
SCRIPT_PATH: Path = Path(__file__).resolve().parent
|
SCRIPT_PATH: Path = Path(__file__).resolve().parent
|
||||||
ROOT_PATH: Path = SCRIPT_PATH
|
ROOT_PATH: Path = SCRIPT_PATH
|
||||||
@@ -18,6 +20,11 @@ def main():
|
|||||||
Main run
|
Main run
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
value = "2025/1/1"
|
||||||
|
regex_c = re.compile(SettingsLoaderCheck.CHECK_SETTINGS['string.date']['regex'], re.VERBOSE)
|
||||||
|
result = regex_c.search(value)
|
||||||
|
print(f"regex {regex_c} check against {value} -> {result}")
|
||||||
|
|
||||||
# for log testing
|
# for log testing
|
||||||
script_path: Path = Path(__file__).resolve().parent
|
script_path: Path = Path(__file__).resolve().parent
|
||||||
log = Log(
|
log = Log(
|
||||||
|
|||||||
Reference in New Issue
Block a user