From 812aada0a236fe11b8dc21a0b64d7ee2a4a17d6c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 26 Mar 2026 14:28:56 +0100 Subject: [PATCH] Move _has_word_re from Mbed TLS's analyze_outcomes.py Signed-off-by: Gilles Peskine --- scripts/mbedtls_framework/outcome_analysis.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/mbedtls_framework/outcome_analysis.py b/scripts/mbedtls_framework/outcome_analysis.py index 2a79fd57d..87a978013 100644 --- a/scripts/mbedtls_framework/outcome_analysis.py +++ b/scripts/mbedtls_framework/outcome_analysis.py @@ -152,6 +152,23 @@ class Task: # see the `name_matches_pattern` function. IGNORED_TESTS = {} #type: typing.Dict[str, typing.List[IgnoreEntry]] + @staticmethod + def _has_word_re(words: typing.Iterable[str], + exclude: typing.Optional[str] = None) -> typing.Pattern: + """Construct a regex that matches if any of the words appears. + + The occurrence must start and end at a word boundary. + + If exclude is specified, strings containing a match for that + regular expression will not match the returned pattern. + """ + exclude_clause = r'' + if exclude: + exclude_clause = r'(?!.*' + exclude + ')' + return re.compile(exclude_clause + + r'.*\b(?:' + r'|'.join(words) + r')\b.*', + re.DOTALL) + def __init__(self, options) -> None: """Pass command line options to the tasks.