From 9dc5c99c57384c853345ba9f53918da0754c57dd Mon Sep 17 00:00:00 2001 From: Beq Date: Sat, 28 Dec 2024 17:03:33 +0000 Subject: [PATCH] Use raw strings for robust matching in python --- indra/lib/python/indra/util/llmanifest.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/indra/lib/python/indra/util/llmanifest.py b/indra/lib/python/indra/util/llmanifest.py index 79fa9d3f88..d1a2f9af8c 100755 --- a/indra/lib/python/indra/util/llmanifest.py +++ b/indra/lib/python/indra/util/llmanifest.py @@ -73,7 +73,10 @@ def proper_windows_path(path, current_platform = sys.platform): rel = None match = re.match("/cygdrive/([a-z])/(.*)", path) if not match: - match = re.match('([a-zA-Z]):\\\(.*)', path) + # Use raw strings to avoid python 3.6 complaints + # match = re.match('([a-zA-Z]):\\\(.*)', path) + match = re.match(r'([a-zA-Z]):\\(.*)', path) + # if not match: return None # not an absolute path drive_letter = match.group(1) @@ -313,7 +316,7 @@ def main(extra=[]): class LLManifestRegistry(type): def __init__(cls, name, bases, dct): super(LLManifestRegistry, cls).__init__(name, bases, dct) - match = re.match("(\w+)Manifest", name) + match = re.match(r"(\w+)Manifest", name) # fix up for python 3.6 string behaviour if match: cls.manifests[match.group(1).lower()] = cls @@ -813,13 +816,22 @@ class LLManifest(object, metaclass=LLManifestRegistry): def wildcard_regex(self, src_glob, dst_glob): + # assume src_glob of form "foo/*.bar" src_re = re.escape(src_glob) - src_re = src_re.replace('\*', '([-a-zA-Z0-9._ ]*)') + # fix up python 3.6 literal support + # src_re = src_re.replace('\*', '([-a-zA-Z0-9._ ]*)') + # src_re is foo/\\*\\.bar + # replace '\\*' with ([-a-zA-Z0-9._ ]*) in the source regex + src_re = src_re.replace(r'\*', r'([-a-zA-Z0-9._ ]*)') + # dst_temp = dst_glob i = 1 while dst_temp.count("*") > 0: - dst_temp = dst_temp.replace('*', '\g<' + str(i) + '>', 1) - i = i+1 + # fix up python 3.6 literal support + # dst_temp = dst_temp.replace('\*', '\g<' + str(i) + '>', 1) + dst_temp = dst_temp.replace('*', r'\g<' + str(i) + '>', 1) + i = i + 1 + # return re.compile(src_re), dst_temp def check_file_exists(self, path):