зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575375 - Fix mozpath.match with python 3.7. r=nalexander
Python 3.7 changed what it escapes with re.escape. Adapt mozpath.match to account for this. Differential Revision: https://phabricator.services.mozilla.com/D42750 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
388ef77faf
Коммит
ade6505592
|
@ -93,6 +93,13 @@ def basedir(path, bases):
|
|||
|
||||
|
||||
re_cache = {}
|
||||
# Python versions < 3.7 return r'\/' for re.escape('/').
|
||||
if re.escape('/') == '/':
|
||||
MATCH_STAR_STAR_RE = re.compile(r'(^|/)\\\*\\\*/')
|
||||
MATCH_STAR_STAR_END_RE = re.compile(r'(^|/)\\\*\\\*$')
|
||||
else:
|
||||
MATCH_STAR_STAR_RE = re.compile(r'(^|\\\/)\\\*\\\*\\\/')
|
||||
MATCH_STAR_STAR_END_RE = re.compile(r'(^|\\\/)\\\*\\\*$')
|
||||
|
||||
|
||||
def match(path, pattern):
|
||||
|
@ -121,8 +128,8 @@ def match(path, pattern):
|
|||
return True
|
||||
if pattern not in re_cache:
|
||||
p = re.escape(pattern)
|
||||
p = re.sub(r'(^|\\\/)\\\*\\\*\\\/', r'\1(?:.+/)?', p)
|
||||
p = re.sub(r'(^|\\\/)\\\*\\\*$', r'(?:\1.+)?', p)
|
||||
p = MATCH_STAR_STAR_RE.sub(r'\1(?:.+/)?', p)
|
||||
p = MATCH_STAR_STAR_END_RE.sub(r'(?:\1.+)?', p)
|
||||
p = p.replace(r'\*', '[^/]*') + '(?:/.*)?$'
|
||||
re_cache[pattern] = re.compile(p)
|
||||
return re_cache[pattern].match(path) is not None
|
||||
|
|
Загрузка…
Ссылка в новой задаче