diff options
author | Tim Peters <tim.peters@gmail.com> | 2022-03-21 17:49:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-21 17:49:43 (GMT) |
commit | 5c3201e146b251017cd77202015f47912ddcb980 (patch) | |
tree | ce73de73a7ab00cda60b49f83e7deed1f3bec044 /Lib/test/test_fnmatch.py | |
parent | 345b390ed69f36681dbc41187bc8f49cd9135b54 (diff) | |
download | cpython-5c3201e146b251017cd77202015f47912ddcb980.zip cpython-5c3201e146b251017cd77202015f47912ddcb980.tar.gz cpython-5c3201e146b251017cd77202015f47912ddcb980.tar.bz2 |
bpo-47080: Use atomic groups to simplify fnmatch (GH-32029)
Use re's new atomic groups to greatly simplify the construction of worst-case linear-time patterns.
Diffstat (limited to 'Lib/test/test_fnmatch.py')
-rw-r--r-- | Lib/test/test_fnmatch.py | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py index 10668e4..ca695d6 100644 --- a/Lib/test/test_fnmatch.py +++ b/Lib/test/test_fnmatch.py @@ -124,17 +124,9 @@ class TranslateTestCase(unittest.TestCase): self.assertEqual(translate('A*********?[?]?'), r'(?s:A.*.[?].)\Z') # fancy translation to prevent exponential-time match failure t = translate('**a*a****a') - digits = re.findall(r'\d+', t) - self.assertEqual(len(digits), 4) - self.assertEqual(digits[0], digits[1]) - self.assertEqual(digits[2], digits[3]) - g1 = f"g{digits[0]}" # e.g., group name "g4" - g2 = f"g{digits[2]}" # e.g., group name "g5" - self.assertEqual(t, - fr'(?s:(?=(?P<{g1}>.*?a))(?P={g1})(?=(?P<{g2}>.*?a))(?P={g2}).*a)\Z') + self.assertEqual(t, r'(?s:(?>.*?a)(?>.*?a).*a)\Z') # and try pasting multiple translate results - it's an undocumented - # feature that this works; all the pain of generating unique group - # names across calls exists to support this + # feature that this works r1 = translate('**a**a**a*') r2 = translate('**b**b**b*') r3 = translate('*c*c*c*') |