summaryrefslogtreecommitdiffstats
path: root/Lib/re.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-30 22:56:45 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-30 22:56:45 (GMT)
commit7cc0a1f7cb6af03ada42174404bed86bdbb4e16c (patch)
treea4f0f8e321275727722fe034af531f56529e4b92 /Lib/re.py
parentc689101a5eed64923993d61c4fe46d794d1293f5 (diff)
parent4659cc075667f6a38f3f69c9838585c71ec44d53 (diff)
downloadcpython-7cc0a1f7cb6af03ada42174404bed86bdbb4e16c.zip
cpython-7cc0a1f7cb6af03ada42174404bed86bdbb4e16c.tar.gz
cpython-7cc0a1f7cb6af03ada42174404bed86bdbb4e16c.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.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/re.py b/Lib/re.py
index 8f5b399..e731a69 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -122,6 +122,7 @@ This module also defines an exception 'error'.
import sys
import sre_compile
import sre_parse
+import _locale
# public symbols
__all__ = [
@@ -274,7 +275,9 @@ _MAXCACHE = 512
def _compile(pattern, flags):
# internal: compile pattern
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):
@@ -288,7 +291,11 @@ def _compile(pattern, flags):
if not (flags & DEBUG):
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):