Use raw strings for robust matching in python
parent
91a0138fd6
commit
9dc5c99c57
|
|
@ -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)
|
||||
# <FS:Beq> Use raw strings to avoid python 3.6 complaints
|
||||
# match = re.match('([a-zA-Z]):\\\(.*)', path)
|
||||
match = re.match(r'([a-zA-Z]):\\(.*)', path)
|
||||
# </FS:Beq>
|
||||
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) # <FS:Beq/> 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._ ]*)')
|
||||
# <FS:Beq> 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._ ]*)')
|
||||
# </FS:Beq>
|
||||
dst_temp = dst_glob
|
||||
i = 1
|
||||
while dst_temp.count("*") > 0:
|
||||
dst_temp = dst_temp.replace('*', '\g<' + str(i) + '>', 1)
|
||||
i = i+1
|
||||
# <FS:Beq> 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
|
||||
# </FS:Beq>
|
||||
return re.compile(src_re), dst_temp
|
||||
|
||||
def check_file_exists(self, path):
|
||||
|
|
|
|||
Loading…
Reference in New Issue