Add winglob.fnmatch.

This commit is contained in:
Ethan Dalool 2020-01-28 17:35:49 -08:00
parent b88450b567
commit 2af2389b8d

View file

@ -8,11 +8,18 @@ But calling glob.escape would also escape asterisk which may not be desired.
So this module just provides a modified version of glob.glob which will escape
only square brackets when called on windows, and behave normally on linux.
'''
import fnmatch as python_fnmatch
import glob as python_glob
import os
import re
def glob(pattern):
def fix(pattern):
if os.name == 'nt':
pattern = re.sub(r'(\[|\])', r'[\1]', pattern)
return python_glob.glob(pattern)
return pattern
def glob(pattern):
return python_glob.glob(fix(pattern))
def fnmatch(name, pat):
return python_fnmatch.fnmatch(name, fix(pat))