Skip to content

bpo-30605: Fix compiling binary regexs with BytesWarnings enabled. #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/sre_parse.py
Original file line number Diff line number Diff line change
@@ -765,7 +765,7 @@ def _parse(source, state, verbose, nested, first=False):
if not first or subpattern:
import warnings
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
' (truncated)' if len(source.string) > 20 else '',
),
16 changes: 14 additions & 2 deletions Lib/test/test_re.py
Original file line number Diff line number Diff line change
@@ -1368,7 +1368,7 @@ def test_inline_flags(self):
self.assertTrue(re.match(p, lower_char))
self.assertEqual(
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__)

@@ -1377,10 +1377,22 @@ def test_inline_flags(self):
self.assertTrue(re.match(p, lower_char))
self.assertEqual(
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__)

# 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):
self.assertTrue(re.match('(?s).(?i)' + upper_char, '\n' + lower_char))
with self.assertWarns(DeprecationWarning):
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
@@ -1685,6 +1685,7 @@ Jakub Wilk
Gerald S. Williams
Jason Williams
John Williams
Roy Williams
Sue Williams
Carol Willing
Steven Willis
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
@@ -350,6 +350,9 @@ Extension Modules
Library
-------

- bpo-30605: re.compile() no longer raises a BytesWarning when compiling a
bytes instance with misplaced inline modifier. Patch by Roy Williams.

- bpo-29870: Fix ssl sockets leaks when connection is aborted in asyncio/ssl
implementation. Patch by Michaël Sghaïer.