Unverified Kaydet (Commit) 861d3844 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) GitHub

[2.7] bpo-32861: robotparser fix incomplete __str__ methods. (GH-5711) (GH-6795) (GH-6817)

The robotparser's __str__ representation now includes wildcard
entries.
(cherry picked from commit c3fa1f2b)

Co-authored-by: Michael Lazar <lazar.michael22@gmail.com>.
üst 84fc6c59
......@@ -160,7 +160,10 @@ class RobotFileParser:
def __str__(self):
return ''.join([str(entry) + "\n" for entry in self.entries])
entries = self.entries
if self.default_entry is not None:
entries = entries + [self.default_entry]
return '\n'.join(map(str, entries)) + '\n'
class RuleLine:
......
......@@ -136,6 +136,31 @@ Disallow: /cyberworld/map/
bad = ['/cyberworld/map/index.html']
class StringFormattingTest(BaseRobotTest, unittest.TestCase):
robots_txt = """\
User-agent: *
Crawl-delay: 1
Request-rate: 3/15
Disallow: /cyberworld/map/ # This is an infinite virtual URL space
# Cybermapper knows where to go.
User-agent: cybermapper
Disallow: /some/path
"""
expected_output = """\
User-agent: cybermapper
Disallow: /some/path
User-agent: *
Disallow: /cyberworld/map/
"""
def test_string_formatting(self):
self.assertEqual(str(self.parser), self.expected_output)
class RobotHandler(BaseHTTPRequestHandler):
def do_GET(self):
......@@ -226,6 +251,7 @@ def test_main():
UseFirstUserAgentWildcardTest,
EmptyQueryStringTest,
DefaultEntryTest,
StringFormattingTest,
PasswordProtectedSiteTestCase,
NetworkTestCase)
......
......@@ -807,6 +807,7 @@ Ben Laurie
Simon Law
Julia Lawall
Chris Lawrence
Michael Lazar
Brian Leair
Mathieu Leduc-Hamel
Amandine Lee
......
The urllib.robotparser's ``__str__`` representation now includes wildcard
entries and the "Crawl-delay" and "Request-rate" fields. Patch by
Michael Lazar.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment