From d5d2400c4aeba718945225e931629dca45eefb76 Mon Sep 17 00:00:00 2001 From: Mark Feit Date: Mon, 13 Jul 2026 18:28:12 +0000 Subject: [PATCH] Corrected regular expression quoting. #175 --- .../psconfig/client/psconfig/parsers/base_template.py | 4 ++-- .../psconfig/client/psconfig/parsers/template.py | 9 ++++----- psconfig/perfsonar-psconfig/psconfig/client/utils.py | 2 +- .../perfsonar-psconfig/psconfig/utilities/metrics.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/base_template.py b/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/base_template.py index f4da2a02..92f8ebbb 100644 --- a/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/base_template.py +++ b/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/base_template.py @@ -31,7 +31,7 @@ def expand(self, obj = None): #find the variables used template_var_map = {} - for template_var in re.findall('{%\s+(.+?)\s+%\}', obj_str): + for template_var in re.findall(r'{%\s+(.+?)\s+%\}', obj_str): template_var = template_var.strip() if template_var_map.get(template_var): continue @@ -99,7 +99,7 @@ def _bracket_ipv6_url(self, json_str): IPv6_re = "{}:(".format(G)+IPv6_re+"|{})".format(_) IPv6_re = ":(:" + G + "){0,5}((:" + G + "){1,2}|:" + IPv4 + ")|" + IPv6_re - IPv6_re = re.sub('\(', '(?:', IPv6_re) + IPv6_re = re.sub(r'\(', '(?:', IPv6_re) json_str = re.sub('(https?)://'+'('+IPv6_re+')', r'\g<1>://[\g<2>]', json_str) return json_str diff --git a/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/template.py b/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/template.py index 00f4c6cf..713c49b6 100644 --- a/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/template.py +++ b/psconfig/perfsonar-psconfig/psconfig/client/psconfig/parsers/template.py @@ -14,10 +14,10 @@ def __init__(self, **kwargs): self.flip = kwargs.get('flip', False) def _expand_var(self, template_var): - addr_match = re.match('^address\[(\d+)\]$', template_var) - pscheduler_address_match = re.match('^pscheduler_address\[(\d+)\]$', template_var) - lead_bind_address_match = re.match('^lead_bind_address\[(\d+)\]$', template_var) - jq_match = re.match('^jq (.+)$', template_var) + addr_match = re.match(r'^address\[(\d+)\]$', template_var) + pscheduler_address_match = re.match(r'^pscheduler_address\[(\d+)\]$', template_var) + lead_bind_address_match = re.match(r'^lead_bind_address\[(\d+)\]$', template_var) + jq_match = re.match(r'^jq (.+)$', template_var) if addr_match: val = self._parse_group_address(int(addr_match.group(1))) @@ -111,4 +111,3 @@ def _parse_localhost(self): #otherwise use localhost return 'localhost' - \ No newline at end of file diff --git a/psconfig/perfsonar-psconfig/psconfig/client/utils.py b/psconfig/perfsonar-psconfig/psconfig/client/utils.py index d5639539..bff8e820 100644 --- a/psconfig/perfsonar-psconfig/psconfig/client/utils.py +++ b/psconfig/perfsonar-psconfig/psconfig/client/utils.py @@ -111,7 +111,7 @@ def build_err_msg(http_response): def extract_url_uuid(url): url = url.strip() url = url.strip('"') - # pattern = re.compile('([0-9a-zA-Z\-]+)$') + # pattern = re.compile(r'([0-9a-zA-Z\-]+)$') # Raw string for a standard UUID v4 pattern: # 8-4-4-4-12 hex digits, with hyphens pattern = re.compile( diff --git a/psconfig/perfsonar-psconfig/psconfig/utilities/metrics.py b/psconfig/perfsonar-psconfig/psconfig/utilities/metrics.py index bdfea7b4..f2155af6 100644 --- a/psconfig/perfsonar-psconfig/psconfig/utilities/metrics.py +++ b/psconfig/perfsonar-psconfig/psconfig/utilities/metrics.py @@ -138,7 +138,7 @@ def run_metrics(self, guid_match='.+?'): stats.end = run_end_match.group(1) stats.pid = run_end_match.group(2) stats.guid = run_end_match.group(3) - run_start_regex = re.compile(f'^(.+) INFO pid={stats.pid} prog=.+? line=.+? guid={stats.guid} msg=Running agent\.\.\.$') + run_start_regex = re.compile(f'^(.+) INFO pid={stats.pid} prog=.+? line=.+? guid={stats.guid} msg=Running agent\\.\\.\\.$') #Check if we found a guid, return if not if stats.guid is None: