[3.6] bpo-30605: Fix compiling binary regexs with BytesWarnings enabled. (GH-2016) (#2214)
Running our unit tests with `-bb` enabled triggered this failure..
(cherry picked from commit 171b9a354e
)
This commit is contained in:
parent
86b95370c4
commit
523a243840
|
@ -736,7 +736,7 @@ def _parse(source, state, verbose, nested, first=False):
|
||||||
if not first or subpattern:
|
if not first or subpattern:
|
||||||
import warnings
|
import warnings
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
'Flags not at the start of the expression %s%s' % (
|
'Flags not at the start of the expression %r%s' % (
|
||||||
source.string[:20], # truncate long regexes
|
source.string[:20], # truncate long regexes
|
||||||
' (truncated)' if len(source.string) > 20 else '',
|
' (truncated)' if len(source.string) > 20 else '',
|
||||||
),
|
),
|
||||||
|
|
|
@ -1346,7 +1346,7 @@ class ReTests(unittest.TestCase):
|
||||||
self.assertTrue(re.match(p, lower_char))
|
self.assertTrue(re.match(p, lower_char))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(warns.warnings[0].message),
|
str(warns.warnings[0].message),
|
||||||
'Flags not at the start of the expression %s' % p
|
'Flags not at the start of the expression %r' % p
|
||||||
)
|
)
|
||||||
self.assertEqual(warns.warnings[0].filename, __file__)
|
self.assertEqual(warns.warnings[0].filename, __file__)
|
||||||
|
|
||||||
|
@ -1355,10 +1355,22 @@ class ReTests(unittest.TestCase):
|
||||||
self.assertTrue(re.match(p, lower_char))
|
self.assertTrue(re.match(p, lower_char))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(warns.warnings[0].message),
|
str(warns.warnings[0].message),
|
||||||
'Flags not at the start of the expression %s (truncated)' % p[:20]
|
'Flags not at the start of the expression %r (truncated)' % p[:20]
|
||||||
)
|
)
|
||||||
self.assertEqual(warns.warnings[0].filename, __file__)
|
self.assertEqual(warns.warnings[0].filename, __file__)
|
||||||
|
|
||||||
|
# bpo-30605: Compiling a bytes instance regex was throwing a BytesWarning
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.simplefilter('error', BytesWarning)
|
||||||
|
p = b'A(?i)'
|
||||||
|
with self.assertWarns(DeprecationWarning) as warns:
|
||||||
|
self.assertTrue(re.match(p, b'a'))
|
||||||
|
self.assertEqual(
|
||||||
|
str(warns.warnings[0].message),
|
||||||
|
'Flags not at the start of the expression %r' % p
|
||||||
|
)
|
||||||
|
self.assertEqual(warns.warnings[0].filename, __file__)
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertTrue(re.match('(?s).(?i)' + upper_char, '\n' + lower_char))
|
self.assertTrue(re.match('(?s).(?i)' + upper_char, '\n' + lower_char))
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
|
|
|
@ -1663,6 +1663,7 @@ Jakub Wilk
|
||||||
Gerald S. Williams
|
Gerald S. Williams
|
||||||
Jason Williams
|
Jason Williams
|
||||||
John Williams
|
John Williams
|
||||||
|
Roy Williams
|
||||||
Sue Williams
|
Sue Williams
|
||||||
Carol Willing
|
Carol Willing
|
||||||
Steven Willis
|
Steven Willis
|
||||||
|
|
|
@ -51,6 +51,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- bpo-30605: re.compile() no longer raises a BytesWarning when compiling a
|
||||||
|
bytes instance with misplaced inline modifier. Patch by Roy Williams.
|
||||||
|
|
||||||
- [Security] bpo-29591: Update expat copy from 2.1.1 to 2.2.0 to get fixes
|
- [Security] bpo-29591: Update expat copy from 2.1.1 to 2.2.0 to get fixes
|
||||||
of CVE-2016-0718 and CVE-2016-4472. See
|
of CVE-2016-0718 and CVE-2016-4472. See
|
||||||
https://sourceforge.net/p/expat/bugs/537/ for more information.
|
https://sourceforge.net/p/expat/bugs/537/ for more information.
|
||||||
|
|
Loading…
Reference in New Issue