summaryrefslogtreecommitdiffstats
path: root/Lib/sre_compile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-05-05 07:42:46 (GMT)
committerGitHub <noreply@github.com>2017-05-05 07:42:46 (GMT)
commit7186cc29be352bed6f1110873283d073fd0643e4 (patch)
tree62b9aa53a22754f7e95cbde603643b8d33df6d07 /Lib/sre_compile.py
parent76a3e51a403bc84ed536921866c86dd7d07aaa7e (diff)
downloadcpython-7186cc29be352bed6f1110873283d073fd0643e4.zip
cpython-7186cc29be352bed6f1110873283d073fd0643e4.tar.gz
cpython-7186cc29be352bed6f1110873283d073fd0643e4.tar.bz2
bpo-30277: Replace _sre.getlower() with _sre.ascii_tolower() and _sre.unicode_tolower(). (#1468)
Diffstat (limited to 'Lib/sre_compile.py')
-rw-r--r--Lib/sre_compile.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index d7ee4e8..db8b8a2 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -69,13 +69,14 @@ def _compile(code, pattern, flags):
REPEATING_CODES = _REPEATING_CODES
SUCCESS_CODES = _SUCCESS_CODES
ASSERT_CODES = _ASSERT_CODES
- if (flags & SRE_FLAG_IGNORECASE and
- not (flags & SRE_FLAG_LOCALE) and
- flags & SRE_FLAG_UNICODE and
- not (flags & SRE_FLAG_ASCII)):
- fixes = _ignorecase_fixes
- else:
- fixes = None
+ tolower = None
+ fixes = None
+ if flags & SRE_FLAG_IGNORECASE and not flags & SRE_FLAG_LOCALE:
+ if flags & SRE_FLAG_UNICODE and not flags & SRE_FLAG_ASCII:
+ tolower = _sre.unicode_tolower
+ fixes = _ignorecase_fixes
+ else:
+ tolower = _sre.ascii_tolower
for op, av in pattern:
if op in LITERAL_CODES:
if not flags & SRE_FLAG_IGNORECASE:
@@ -85,7 +86,7 @@ def _compile(code, pattern, flags):
emit(OP_LOC_IGNORE[op])
emit(av)
else:
- lo = _sre.getlower(av, flags)
+ lo = tolower(av)
if fixes and lo in fixes:
emit(IN_IGNORE)
skip = _len(code); emit(0)
@@ -102,16 +103,12 @@ def _compile(code, pattern, flags):
elif op is IN:
if not flags & SRE_FLAG_IGNORECASE:
emit(op)
- fixup = None
elif flags & SRE_FLAG_LOCALE:
emit(IN_LOC_IGNORE)
- fixup = None
else:
emit(IN_IGNORE)
- def fixup(literal, flags=flags):
- return _sre.getlower(literal, flags)
skip = _len(code); emit(0)
- _compile_charset(av, flags, code, fixup, fixes)
+ _compile_charset(av, flags, code, tolower, fixes)
code[skip] = _len(code) - skip
elif op is ANY:
if flags & SRE_FLAG_DOTALL: