diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-06-06 06:24:38 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-06-06 06:24:38 +0000 |
commit | 4d74dff64fb5df4c667988f6e3bbced2f6c9fa2c (patch) | |
tree | 08913e05750b3b52cb293429f2ac5dbf08225352 /Lib/fnmatch.py | |
parent | 7ea4ae9a2d1b06df9a37bac4440bff5c2c2a0940 (diff) | |
download | cpython-4d74dff64fb5df4c667988f6e3bbced2f6c9fa2c.tar.gz |
Patch #409973: Speedup glob.glob, add fnmatch.filter.
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r-- | Lib/fnmatch.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py index 182a9ef923..da0bb34c78 100644 --- a/Lib/fnmatch.py +++ b/Lib/fnmatch.py @@ -37,6 +37,26 @@ def fnmatch(name, pat): pat = os.path.normcase(pat) return fnmatchcase(name, pat) +def filter(names, pat): + """Return the subset of the list NAMES that match PAT""" + import os,posixpath + result=[] + pat=os.path.normcase(pat) + if not _cache.has_key(pat): + res = translate(pat) + _cache[pat] = re.compile(res) + match=_cache[pat].match + if os.path is posixpath: + # normcase on posix is NOP. Optimize it away from the loop. + for name in names: + if match(name): + result.append(name) + else: + for name in names: + if match(os.path.normcase(name)): + result.append(name) + return result + def fnmatchcase(name, pat): """Test whether FILENAME matches PATTERN, including case. |