Skip to content

Commit 3fd9f49

Browse files
authored
Update Lib/test/test_robotparser.py
1 parent 19250b7 commit 3fd9f49

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

‎Lib/test/test_robotparser.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -876,20 +876,17 @@ def test_read_404(self):
876876
self.assertIsNone(parser.request_rate('*'))
877877

878878

879-
class RepeatedUserAgentPerformanceTest(unittest.TestCase):
880-
"""Parsing many identical ``User-agent:`` lines must stay linear."""
879+
class RepeatedUserAgentTest(unittest.TestCase):
881880

882881
def test_many_duplicate_user_agents(self):
883-
import time
884-
body = ("User-agent: evil\n" * 50_000) + "Disallow: /\n"
882+
# gh-162282: a User-agent repeated within one group must not be
883+
# merged into that group once per repetition (quadratic time).
884+
body = "User-agent: evil\n" * 1000 + "Disallow: /\n"
885885
parser = urllib.robotparser.RobotFileParser()
886-
parser.modified()
887-
start = time.perf_counter()
888886
parser.parse(body.splitlines())
889-
elapsed = time.perf_counter() - start
890-
self.assertLess(elapsed, 5.0,
891-
f"parse of 50_000 duplicate User-agent lines "
892-
f"took {elapsed:.3f}s")
887+
entry = parser.groups["evil"]
888+
self.assertIs(entry, parser.entries[0])
889+
self.assertEqual(len(entry.rulelines), 1)
893890
self.assertFalse(parser.can_fetch("evil", "/"))
894891

895892

0 commit comments

Comments
 (0)