Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73f570b

Browse files
committed
Correctly set default entry in all cases.
1 parent d22368f commit 73f570b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Lib/robotparser.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def read(self):
5858
_debug("parse lines")
5959
self.parse(lines)
6060

61+
def _add_entry(self, entry):
62+
if "*" in entry.useragents:
63+
# the default entry is considered last
64+
self.default_entry = entry
65+
else:
66+
self.entries.append(entry)
67+
6168
def parse(self, lines):
6269
"""parse the input lines from a robot.txt file.
6370
We allow that a user-agent: line is not preceded by
@@ -76,11 +83,7 @@ def parse(self, lines):
7683
entry = Entry()
7784
state = 0
7885
elif state==2:
79-
if "*" in entry.useragents:
80-
# the default entry is considered last
81-
self.default_entry = entry
82-
else:
83-
self.entries.append(entry)
86+
self._add_entry(entry)
8487
entry = Entry()
8588
state = 0
8689
# remove optional comment and strip line
@@ -99,7 +102,7 @@ def parse(self, lines):
99102
_debug("line %d: warning: you should insert a blank"
100103
" line before any user-agent"
101104
" directive" % linenumber)
102-
self.entries.append(entry)
105+
self._add_entry(entry)
103106
entry = Entry()
104107
entry.useragents.append(line[1])
105108
state = 1

0 commit comments

Comments
 (0)