mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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.
This commit is contained in:
parent
793c14ea29
commit
a54aae0683
6 changed files with 60 additions and 19 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue