]> granicus.if.org Git - python/commitdiff
backport r57626
authorSkip Montanaro <skip@pobox.com>
Tue, 28 Aug 2007 23:26:55 +0000 (23:26 +0000)
committerSkip Montanaro <skip@pobox.com>
Tue, 28 Aug 2007 23:26:55 +0000 (23:26 +0000)
Lib/robotparser.py
Lib/test/test_robotparser.py

index 48ea066682e1878d3402c4275cbcf45276ff5fae..cf0a58d6ee329dd0f7bf0de94cbb1dd2b077588d 100644 (file)
@@ -233,6 +233,11 @@ class URLopener(urllib.FancyURLopener):
         urllib.FancyURLopener.__init__(self, *args)
         self.errcode = 200
 
+    def prompt_user_passwd(self, host, realm):
+        ## If robots.txt file is accessible only with a password,
+        ## we act as if the file wasn't there.
+        return None, None
+
     def http_error_default(self, url, fp, errcode, errmsg, headers):
         self.errcode = errcode
         return urllib.FancyURLopener.http_error_default(self, url, fp, errcode,
index 6a23b22db3c0a1d2029db9d8deca5575ed59042b..a8e1eaaaeeeeee9fca449c351e6dfc1bc67fa0d4 100644 (file)
@@ -134,8 +134,19 @@ bad = [] # Bug report says "/" should be denied, but that is not in the RFC
 
 RobotTest(7, doc, good, bad)
 
+class TestCase(unittest.TestCase):
+    def runTest(self):
+        test_support.requires('network')
+        # whole site is password-protected.
+        url = 'http://mueblesmoraleda.com'
+        parser = robotparser.RobotFileParser()
+        parser.set_url(url)
+        parser.read()
+        self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
+
 def test_main():
     test_support.run_suite(tests)
+    TestCase().run()
 
 if __name__=='__main__':
     test_support.Verbose = 1