diff options
author | Guido van Rossum <guido@python.org> | 2008-10-03 16:38:30 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2008-10-03 16:38:30 (GMT) |
commit | 3f2291f8025cf01ac96981d4e3a5284ba6e57f9f (patch) | |
tree | 8dceb6edf9d9616e5737db168df81e422d7dcee6 /Lib/fnmatch.py | |
parent | 7ed519603f5493cfb3fbf241a94157b2d1f0e8ae (diff) | |
download | cpython-3f2291f8025cf01ac96981d4e3a5284ba6e57f9f.zip cpython-3f2291f8025cf01ac96981d4e3a5284ba6e57f9f.tar.gz cpython-3f2291f8025cf01ac96981d4e3a5284ba6e57f9f.tar.bz2 |
Change fnmatch.py to use separate caches for str and bytes keys.
This is necessary to pass the tests with -bb.
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r-- | Lib/fnmatch.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py index dd01205..0397549 100644 --- a/Lib/fnmatch.py +++ b/Lib/fnmatch.py @@ -14,7 +14,8 @@ import re __all__ = ["filter", "fnmatch","fnmatchcase","translate"] -_cache = {} +_cache = {} # Maps text patterns to compiled regexen. +_cacheb = {} # Ditto for bytes patterns. def fnmatch(name, pat): """Test whether FILENAME matches PATTERN. @@ -38,7 +39,8 @@ def fnmatch(name, pat): return fnmatchcase(name, pat) def _compile_pattern(pat): - regex = _cache.get(pat) + cache = _cacheb if isinstance(pat, bytes) else _cache + regex = cache.get(pat) if regex is None: if isinstance(pat, bytes): pat_str = str(pat, 'ISO-8859-1') @@ -46,7 +48,7 @@ def _compile_pattern(pat): res = bytes(res_str, 'ISO-8859-1') else: res = translate(pat) - _cache[pat] = regex = re.compile(res) + cache[pat] = regex = re.compile(res) return regex.match def filter(names, pat): |