From 7da18e0f00794fcf1a74eb05498b51b3a1cec3e3 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 9 Jan 2026 16:15:38 +0900 Subject: [PATCH] Moved the compiled regex patterns to a new file regex_constants_compiled So we do not force the compiled build if not needed --- .../check_handling/regex_constants.py | 8 ------- .../regex_constants_compiled.py | 23 +++++++++++++++++++ test-run/check_handling/regex_checks.py | 17 ++++++++++---- .../check_handling/test_regex_constants.py | 4 +++- 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 src/corelibs/check_handling/regex_constants_compiled.py diff --git a/src/corelibs/check_handling/regex_constants.py b/src/corelibs/check_handling/regex_constants.py index d005259..1fe0ecd 100644 --- a/src/corelibs/check_handling/regex_constants.py +++ b/src/corelibs/check_handling/regex_constants.py @@ -51,12 +51,4 @@ DOMAIN_WITH_LOCALHOST_PORT_REGEX: str = r""" # Domain, no localhost DOMAIN_REGEX: str = r"^(?!-)[A-Za-z0-9-]{1,63}(?[^"]+)"\s*<(?P[^>]+)>| @@ -28,7 +32,7 @@ def domain_test(): "some-domain.org" ] - regex_domain_check = compile_re(DOMAIN_WITH_LOCALHOST_REGEX) + regex_domain_check = COMPILED_DOMAIN_WITH_LOCALHOST_REGEX print(f"REGEX: {DOMAIN_WITH_LOCALHOST_REGEX}") print(f"Check regex: {regex_domain_check.search('localhost')}") @@ -59,10 +63,15 @@ def email_test(): test open """ - basic_email = compile_re(EMAIL_BASIC_REGEX) + print(f"REGEX: SUB_EMAIL_BASIC_REGEX: {SUB_EMAIL_BASIC_REGEX}") + print(f"REGEX: EMAIL_BASIC_REGEX: {EMAIL_BASIC_REGEX}") + print(f"REGEX: COMPILED_NAME_EMAIL_SIMPLE_REGEX: {COMPILED_NAME_EMAIL_SIMPLE_REGEX}") + print(f"REGEX: NAME_EMAIL_BASIC_REGEX: {NAME_EMAIL_BASIC_REGEX}") + + basic_email = COMPILED_EMAIL_BASIC_REGEX sub_basic_email = compile_re(SUB_EMAIL_BASIC_REGEX) - simple_name_email_regex = compile_re(NAME_EMAIL_SIMPLE_REGEX) - full_name_email_regex = compile_re(NAME_EMAIL_BASIC_REGEX) + simple_name_email_regex = COMPILED_NAME_EMAIL_SIMPLE_REGEX + full_name_email_regex = COMPILED_NAME_EMAIL_BASIC_REGEX for email in email_list.splitlines(): email = email.strip() if not email: diff --git a/tests/unit/check_handling/test_regex_constants.py b/tests/unit/check_handling/test_regex_constants.py index a863a42..cf22fbc 100644 --- a/tests/unit/check_handling/test_regex_constants.py +++ b/tests/unit/check_handling/test_regex_constants.py @@ -14,7 +14,9 @@ from corelibs.check_handling.regex_constants import ( NAME_EMAIL_BASIC_REGEX, DOMAIN_WITH_LOCALHOST_REGEX, DOMAIN_WITH_LOCALHOST_PORT_REGEX, - DOMAIN_REGEX, + DOMAIN_REGEX +) +from corelibs.check_handling.regex_constants_compiled import ( COMPILED_EMAIL_BASIC_REGEX, COMPILED_NAME_EMAIL_SIMPLE_REGEX, COMPILED_NAME_EMAIL_BASIC_REGEX,