>>> pathmatch('**.py', 'templates/index.html')
False
+ >>> pathmatch('./foo/**.py', 'foo/bar/baz.py')
+ True
+ >>> pathmatch('./foo/**.py', 'bar/baz.py')
+ False
+
+ >>> pathmatch('^foo/**.py', 'foo/bar/baz.py')
+ True
+ >>> pathmatch('^foo/**.py', 'bar/baz.py')
+ False
+
>>> pathmatch('**/templates/*.html', 'templates/index.html')
True
>>> pathmatch('**/templates/*.html', 'templates/foo/bar.html')
'**/': '(?:.+/)*?',
'**': '(?:.+/)*?[^/]+',
}
- buf = []
+
+ if pattern.startswith('^'):
+ buf = ['^']
+ pattern = pattern[1:]
+ elif pattern.startswith('./'):
+ buf = ['^']
+ pattern = pattern[2:]
+ else:
+ buf = []
+
for idx, part in enumerate(re.split('([?*]+/?)', pattern)):
if idx % 2:
buf.append(symbols[part])
assert not util.pathmatch('**.py', 'templates/index.html')
assert util.pathmatch('**/templates/*.html', 'templates/index.html')
assert not util.pathmatch('**/templates/*.html', 'templates/foo/bar.html')
+ assert util.pathmatch('^foo/**.py', 'foo/bar/baz/blah.py')
+ assert not util.pathmatch('^foo/**.py', 'blah/foo/bar/baz.py')
+ assert util.pathmatch('./foo/**.py', 'foo/bar/baz/blah.py')
+ assert util.pathmatch('./blah.py', 'blah.py')
+ assert not util.pathmatch('./foo/**.py', 'blah/foo/bar/baz.py')
def test_odict_pop():