summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-13 04:57:19 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-13 04:57:19 (GMT)
commita7364a887c97650e072acded7a37337287b0011c (patch)
treecab8c1ed96c31e7381541fe1926451ceffec33ae /Lib
parent61f61dc679390dd5c421551f4bf7428b413a9e33 (diff)
parent122541beceeccce4ef8a9bf739c727ccdcbf2f28 (diff)
downloadcpython-a7364a887c97650e072acded7a37337287b0011c.zip
cpython-a7364a887c97650e072acded7a37337287b0011c.tar.gz
cpython-a7364a887c97650e072acded7a37337287b0011c.tar.bz2
merge
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib/robotparser.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/urllib/robotparser.py b/Lib/urllib/robotparser.py
index 978ba58..1d7b751 100644
--- a/Lib/urllib/robotparser.py
+++ b/Lib/urllib/robotparser.py
@@ -7,7 +7,7 @@
2) PSF license for Python 2.2
The robots.txt Exclusion Protocol is implemented as specified in
- http://info.webcrawler.com/mak/projects/robots/norobots-rfc.html
+ http://www.robotstxt.org/norobots-rfc.txt
"""
import urllib.parse, urllib.request
@@ -57,7 +57,7 @@ class RobotFileParser:
except urllib.error.HTTPError as err:
if err.code in (401, 403):
self.disallow_all = True
- elif err.code >= 400:
+ elif err.code >= 400 and err.code < 500:
self.allow_all = True
else:
raw = f.read()
@@ -85,6 +85,7 @@ class RobotFileParser:
state = 0
entry = Entry()
+ self.modified()
for line in lines:
if not line:
if state == 1:
@@ -129,6 +130,12 @@ class RobotFileParser:
return False
if self.allow_all:
return True
+ # Until the robots.txt file has been read or found not
+ # to exist, we must assume that no url is allowable.
+ # This prevents false positives when a user erronenously
+ # calls can_fetch() before calling read().
+ if not self.last_checked:
+ return False
# search for given user agent matches
# the first match counts
parsed_url = urllib.parse.urlparse(urllib.parse.unquote(url))