diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-30 22:53:19 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-30 22:53:19 (GMT) |
commit | d4c7290368a82a265c9905dc5c1e95591fb96333 (patch) | |
tree | 1a360de9ff63adcb7d7fcd26dd62841fceb71ba0 /Lib/re.py | |
parent | 65566984b08ab8aebb15ed1ead5969791921f6ca (diff) | |
download | cpython-d4c7290368a82a265c9905dc5c1e95591fb96333.zip cpython-d4c7290368a82a265c9905dc5c1e95591fb96333.tar.gz cpython-d4c7290368a82a265c9905dc5c1e95591fb96333.tar.bz2 |
Issue #22410: Module level functions in the re module now cache compiled
locale-dependent regular expressions taking into account the locale.
Diffstat (limited to 'Lib/re.py')
-rw-r--r-- | Lib/re.py | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -104,6 +104,7 @@ This module also defines an exception 'error'. import sys import sre_compile import sre_parse +import _locale # public symbols __all__ = [ "match", "search", "sub", "subn", "split", "findall", @@ -229,9 +230,12 @@ def _compile(*key): bypass_cache = flags & DEBUG if not bypass_cache: cachekey = (type(key[0]),) + key - p = _cache.get(cachekey) - if p is not None: - return p + try: + p, loc = _cache[cachekey] + if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE): + return p + except KeyError: + pass if isinstance(pattern, _pattern_type): if flags: raise ValueError('Cannot process flags argument with a compiled pattern') @@ -245,7 +249,11 @@ def _compile(*key): if not bypass_cache: if len(_cache) >= _MAXCACHE: _cache.clear() - _cache[cachekey] = p + if p.flags & LOCALE: + loc = _locale.setlocale(_locale.LC_CTYPE) + else: + loc = None + _cache[cachekey] = p, loc return p def _compile_repl(*key): |