Discussion:
[Python-3000-checkins] r66773 - python/branches/py3k/Lib/fnmatch.py
guido.van.rossum
2008-10-04 07:33:23 UTC
Permalink
Author: guido.van.rossum
Date: Fri Oct 3 18:38:30 2008
New Revision: 66773

Log:
Change fnmatch.py to use separate caches for str and bytes keys.
This is necessary to pass the tests with -bb.


Modified:
python/branches/py3k/Lib/fnmatch.py

Modified: python/branches/py3k/Lib/fnmatch.py
==============================================================================
--- python/branches/py3k/Lib/fnmatch.py (original)
+++ python/branches/py3k/Lib/fnmatch.py Fri Oct 3 18:38:30 2008
@@ -14,7 +14,8 @@

__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 @@
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 @@
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):

Loading...