mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-30298: Weaken the condition of deprecation warnings for inline modifiers. (#1490)
Now allowed several subsequential inline modifiers at the start of the pattern (e.g. '(?i)(?s)...'). In verbose mode whitespaces and comments now are allowed before and between inline modifiers (e.g. '(?x) (?i) (?s)...').
This commit is contained in:
parent
211a392cc1
commit
305ccbe27e
3 changed files with 56 additions and 21 deletions
|
@ -1325,32 +1325,43 @@ class ReTests(unittest.TestCase):
|
|||
upper_char = '\u1ea0' # Latin Capital Letter A with Dot Below
|
||||
lower_char = '\u1ea1' # Latin Small Letter A with Dot Below
|
||||
|
||||
p = re.compile(upper_char, re.I | re.U)
|
||||
q = p.match(lower_char)
|
||||
p = re.compile('.' + upper_char, re.I | re.S)
|
||||
q = p.match('\n' + lower_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
p = re.compile(lower_char, re.I | re.U)
|
||||
q = p.match(upper_char)
|
||||
p = re.compile('.' + lower_char, re.I | re.S)
|
||||
q = p.match('\n' + upper_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
p = re.compile('(?i)' + upper_char, re.U)
|
||||
q = p.match(lower_char)
|
||||
p = re.compile('(?i).' + upper_char, re.S)
|
||||
q = p.match('\n' + lower_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
p = re.compile('(?i)' + lower_char, re.U)
|
||||
q = p.match(upper_char)
|
||||
p = re.compile('(?i).' + lower_char, re.S)
|
||||
q = p.match('\n' + upper_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
p = re.compile('(?iu)' + upper_char)
|
||||
q = p.match(lower_char)
|
||||
p = re.compile('(?is).' + upper_char)
|
||||
q = p.match('\n' + lower_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
p = re.compile('(?iu)' + lower_char)
|
||||
q = p.match(upper_char)
|
||||
p = re.compile('(?is).' + lower_char)
|
||||
q = p.match('\n' + upper_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
self.assertTrue(re.match('(?ixu) ' + upper_char, lower_char))
|
||||
self.assertTrue(re.match('(?ixu) ' + lower_char, upper_char))
|
||||
p = re.compile('(?s)(?i).' + upper_char)
|
||||
q = p.match('\n' + lower_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
p = re.compile('(?s)(?i).' + lower_char)
|
||||
q = p.match('\n' + upper_char)
|
||||
self.assertTrue(q)
|
||||
|
||||
self.assertTrue(re.match('(?ix) ' + upper_char, lower_char))
|
||||
self.assertTrue(re.match('(?ix) ' + lower_char, upper_char))
|
||||
self.assertTrue(re.match(' (?i) ' + upper_char, lower_char, re.X))
|
||||
self.assertTrue(re.match('(?x) (?i) ' + upper_char, lower_char))
|
||||
self.assertTrue(re.match(' (?x) (?i) ' + upper_char, lower_char, re.X))
|
||||
|
||||
p = upper_char + '(?i)'
|
||||
with self.assertWarns(DeprecationWarning) as warns:
|
||||
|
@ -1368,6 +1379,26 @@ class ReTests(unittest.TestCase):
|
|||
'Flags not at the start of the expression %s (truncated)' % p[:20]
|
||||
)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.match('(?s).(?i)' + upper_char, '\n' + lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.match('(?i) ' + upper_char + ' (?x)', lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.match(' (?x) (?i) ' + upper_char, lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.match('^(?i)' + upper_char, lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.match('$|(?i)' + upper_char, lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.match('(?:(?i)' + upper_char + ')', lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.fullmatch('(^)?(?(1)(?i)' + upper_char + ')',
|
||||
lower_char))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertTrue(re.fullmatch('($)?(?(1)|(?i)' + upper_char + ')',
|
||||
lower_char))
|
||||
|
||||
|
||||
def test_dollar_matches_twice(self):
|
||||
"$ matches the end of string, and just before the terminating \n"
|
||||
pattern = re.compile('$')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue