mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
bpo-30215: Make re.compile() locale agnostic. (#1361)
Compiled regular expression objects with the re.LOCALE flag no longer depend on the locale at compile time. Only the locale at matching time affects the result of matching.
This commit is contained in:
parent
647c3d381e
commit
898ff03e1e
9 changed files with 141 additions and 23 deletions
12
Lib/re.py
12
Lib/re.py
|
@ -268,9 +268,7 @@ _MAXCACHE = 512
|
|||
def _compile(pattern, flags):
|
||||
# internal: compile pattern
|
||||
try:
|
||||
p, loc = _cache[type(pattern), pattern, flags]
|
||||
if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE):
|
||||
return p
|
||||
return _cache[type(pattern), pattern, flags]
|
||||
except KeyError:
|
||||
pass
|
||||
if isinstance(pattern, _pattern_type):
|
||||
|
@ -284,13 +282,7 @@ def _compile(pattern, flags):
|
|||
if not (flags & DEBUG):
|
||||
if len(_cache) >= _MAXCACHE:
|
||||
_cache.clear()
|
||||
if p.flags & LOCALE:
|
||||
if not _locale:
|
||||
return p
|
||||
loc = _locale.setlocale(_locale.LC_CTYPE)
|
||||
else:
|
||||
loc = None
|
||||
_cache[type(pattern), pattern, flags] = p, loc
|
||||
_cache[type(pattern), pattern, flags] = p
|
||||
return p
|
||||
|
||||
@functools.lru_cache(_MAXCACHE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue