diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-30 22:53:49 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-30 22:53:49 (GMT) |
commit | 4659cc075667f6a38f3f69c9838585c71ec44d53 (patch) | |
tree | a8c87ba44a24a3e66f87d55f596b8b2962948f59 /Lib/re.py | |
parent | 35903c809f85de1532c2df4f82550e079a3711a7 (diff) | |
download | cpython-4659cc075667f6a38f3f69c9838585c71ec44d53.zip cpython-4659cc075667f6a38f3f69c9838585c71ec44d53.tar.gz cpython-4659cc075667f6a38f3f69c9838585c71ec44d53.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 | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -122,6 +122,7 @@ This module also defines an exception 'error'. import sys import sre_compile import sre_parse +import _locale # public symbols __all__ = [ "match", "fullmatch", "search", "sub", "subn", "split", "findall", @@ -275,7 +276,9 @@ def _compile(pattern, flags): bypass_cache = flags & DEBUG if not bypass_cache: try: - return _cache[type(pattern), pattern, flags] + p, loc = _cache[type(pattern), pattern, flags] + if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE): + return p except KeyError: pass if isinstance(pattern, _pattern_type): @@ -289,7 +292,11 @@ def _compile(pattern, flags): if not bypass_cache: if len(_cache) >= _MAXCACHE: _cache.clear() - _cache[type(pattern), pattern, flags] = p + if p.flags & LOCALE: + loc = _locale.setlocale(_locale.LC_CTYPE) + else: + loc = None + _cache[type(pattern), pattern, flags] = p, loc return p def _compile_repl(repl, pattern): |