Issue #21032: Deprecated the use of re.LOCALE flag with str patterns or

re.ASCII. It was newer worked.
This commit is contained in:
Serhiy Storchaka 2014-12-01 11:50:07 +02:00
parent 720b8c9dd7
commit 22a309a434
4 changed files with 84 additions and 17 deletions

View file

@ -751,6 +751,11 @@ def _parse(source, state):
def fix_flags(src, flags):
# Check and fix flags according to the type of pattern (str or bytes)
if isinstance(src, str):
if flags & SRE_FLAG_LOCALE:
import warnings
warnings.warn("LOCALE flag with a str pattern is deprecated. "
"Will be an error in 3.6",
DeprecationWarning, stacklevel=6)
if not flags & SRE_FLAG_ASCII:
flags |= SRE_FLAG_UNICODE
elif flags & SRE_FLAG_UNICODE:
@ -758,6 +763,11 @@ def fix_flags(src, flags):
else:
if flags & SRE_FLAG_UNICODE:
raise ValueError("can't use UNICODE flag with a bytes pattern")
if flags & SRE_FLAG_LOCALE and flags & SRE_FLAG_ASCII:
import warnings
warnings.warn("ASCII and LOCALE flags are incompatible. "
"Will be an error in 3.6",
DeprecationWarning, stacklevel=6)
return flags
def parse(str, flags=0, pattern=None):