summaryrefslogtreecommitdiffstats
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-24 20:58:14 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-24 20:58:14 (GMT)
commita54aae068325551bcc70c151b483f1b38ca0c687 (patch)
treeb9e9f9d33b597ea84421d22c19cbbb6f551c90ef /Lib/sre_parse.py
parent793c14ea2965a1584a7f85aa663d0fd7cfdef629 (diff)
downloadcpython-a54aae068325551bcc70c151b483f1b38ca0c687.zip
cpython-a54aae068325551bcc70c151b483f1b38ca0c687.tar.gz
cpython-a54aae068325551bcc70c151b483f1b38ca0c687.tar.bz2
Issue #23622: Unknown escapes in regular expressions that consist of ``'\'``
and ASCII letter now raise a deprecation warning and will be forbidden in Python 3.6.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 98afd7c..af729c3 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -21,6 +21,7 @@ DIGITS = frozenset("0123456789")
OCTDIGITS = frozenset("01234567")
HEXDIGITS = frozenset("0123456789abcdefABCDEF")
+ASCIILETTERS = frozenset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
WHITESPACE = frozenset(" \t\n\r\v\f")
@@ -344,6 +345,10 @@ def _class_escape(source, escape):
elif c in DIGITS:
raise ValueError
if len(escape) == 2:
+ if c in ASCIILETTERS:
+ import warnings
+ warnings.warn('bad escape %s' % escape,
+ DeprecationWarning, stacklevel=8)
return LITERAL, ord(escape[1])
except ValueError:
pass
@@ -407,6 +412,10 @@ def _escape(source, escape, state):
return GROUPREF, group
raise ValueError
if len(escape) == 2:
+ if c in ASCIILETTERS:
+ import warnings
+ warnings.warn('bad escape %s' % escape,
+ DeprecationWarning, stacklevel=8)
return LITERAL, ord(escape[1])
except ValueError:
pass
@@ -903,7 +912,10 @@ def parse_template(source, pattern):
try:
this = chr(ESCAPES[this][1])
except KeyError:
- pass
+ if c in ASCIILETTERS:
+ import warnings
+ warnings.warn('bad escape %s' % this,
+ DeprecationWarning, stacklevel=5)
lappend(this)
else:
lappend(this)