Issue #27030: Unknown escapes in re.sub() replacement template are allowed

again.  But they still are deprecated and will be disabled in 3.7.
This commit is contained in:
Serhiy Storchaka 2016-12-06 19:15:29 +02:00
parent b0f75c520e
commit 53c53ea4c5
5 changed files with 16 additions and 5 deletions

View file

@ -947,7 +947,9 @@ def parse_template(source, pattern):
this = chr(ESCAPES[this][1])
except KeyError:
if c in ASCIILETTERS:
raise s.error('bad escape %s' % this, len(this))
import warnings
warnings.warn('bad escape %s' % this,
DeprecationWarning, stacklevel=4)
lappend(this)
else:
lappend(this)

View file

@ -126,7 +126,7 @@ class ReTests(unittest.TestCase):
(chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)+chr(8)))
for c in 'cdehijklmopqsuwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
with self.subTest(c):
with self.assertRaises(re.error):
with self.assertWarns(DeprecationWarning):
self.assertEqual(re.sub('a', '\\' + c, 'a'), '\\' + c)
self.assertEqual(re.sub(r'^\s*', 'X', 'test'), 'Xtest')