From 2af2389b8dde7a6089cc977bf06c2fbd39e15f4f Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 28 Jan 2020 17:35:49 -0800 Subject: [PATCH] Add winglob.fnmatch. --- voussoirkit/winglob.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/voussoirkit/winglob.py b/voussoirkit/winglob.py index 9f80089..2477ec2 100644 --- a/voussoirkit/winglob.py +++ b/voussoirkit/winglob.py @@ -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))