Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9a7bbb2e
Kaydet (Commit)
9a7bbb2e
authored
Eyl 18, 2016
tarafından
Berker Peksag
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #25400: RobotFileParser now correctly returns default values for crawl_delay and request_rate
Initial patch by Peter Wirtz.
üst
85c98bf9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
20 deletions
+45
-20
test_robotparser.py
Lib/test/test_robotparser.py
+36
-18
robotparser.py
Lib/urllib/robotparser.py
+6
-2
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_robotparser.py
Dosyayı görüntüle @
9a7bbb2e
...
...
@@ -79,32 +79,17 @@ Disallow: /
bad
=
[
'/cyberworld/map/index.html'
,
'/'
,
'/tmp/'
]
class
CrawlDelayAndRequestRateTest
(
BaseRobotTest
,
unittest
.
TestCase
):
robots_txt
=
"""
\
User-agent: figtree
Crawl-delay: 3
Request-rate: 9/30
Disallow: /tmp
Disallow: /a
%3
cd.html
Disallow: /a
%2
fb.html
Disallow: /
%7
ejoe/index.html
"""
agent
=
'figtree'
request_rate
=
namedtuple
(
'req_rate'
,
'requests seconds'
)(
9
,
30
)
crawl_delay
=
3
good
=
[(
'figtree'
,
'/foo.html'
)]
bad
=
[
'/tmp'
,
'/tmp.html'
,
'/tmp/a.html'
,
'/a
%3
cd.html'
,
'/a
%3
Cd.html'
,
'/a
%2
fb.html'
,
'/~joe/index.html'
]
class
BaseRequestRateTest
(
BaseRobotTest
):
def
test_request_rate
(
self
):
for
url
in
self
.
good
:
for
url
in
self
.
good
+
self
.
bad
:
agent
,
url
=
self
.
get_agent_and_url
(
url
)
with
self
.
subTest
(
url
=
url
,
agent
=
agent
):
if
self
.
crawl_delay
:
self
.
assertEqual
(
self
.
parser
.
crawl_delay
(
agent
),
self
.
crawl_delay
)
if
self
.
request_rate
and
self
.
parser
.
request_rate
(
agent
)
:
if
self
.
request_rate
:
self
.
assertEqual
(
self
.
parser
.
request_rate
(
agent
)
.
requests
,
self
.
request_rate
.
requests
...
...
@@ -115,6 +100,24 @@ Disallow: /%7ejoe/index.html
)
class
CrawlDelayAndRequestRateTest
(
BaseRequestRateTest
,
unittest
.
TestCase
):
robots_txt
=
"""
\
User-agent: figtree
Crawl-delay: 3
Request-rate: 9/30
Disallow: /tmp
Disallow: /a
%3
cd.html
Disallow: /a
%2
fb.html
Disallow: /
%7
ejoe/index.html
"""
agent
=
'figtree'
request_rate
=
namedtuple
(
'req_rate'
,
'requests seconds'
)(
9
,
30
)
crawl_delay
=
3
good
=
[(
'figtree'
,
'/foo.html'
)]
bad
=
[
'/tmp'
,
'/tmp.html'
,
'/tmp/a.html'
,
'/a
%3
cd.html'
,
'/a
%3
Cd.html'
,
'/a
%2
fb.html'
,
'/~joe/index.html'
]
class
DifferentAgentTest
(
CrawlDelayAndRequestRateTest
):
agent
=
'FigTree Robot libwww-perl/5.04'
# these are not actually tested, but we still need to parse it
...
...
@@ -230,6 +233,19 @@ Disallow: /another/path?
bad
=
[
'/another/path?'
]
class
DefaultEntryTest
(
BaseRequestRateTest
,
unittest
.
TestCase
):
robots_txt
=
"""
\
User-agent: *
Crawl-delay: 1
Request-rate: 3/15
Disallow: /cyberworld/map/
"""
request_rate
=
namedtuple
(
'req_rate'
,
'requests seconds'
)(
3
,
15
)
crawl_delay
=
1
good
=
[
'/'
,
'/test.html'
]
bad
=
[
'/cyberworld/map/index.html'
]
class
RobotHandler
(
BaseHTTPRequestHandler
):
def
do_GET
(
self
):
...
...
@@ -309,6 +325,8 @@ class NetworkTestCase(unittest.TestCase):
self
.
assertTrue
(
parser
.
allow_all
)
self
.
assertFalse
(
parser
.
disallow_all
)
self
.
assertEqual
(
parser
.
mtime
(),
0
)
self
.
assertIsNone
(
parser
.
crawl_delay
(
'*'
))
self
.
assertIsNone
(
parser
.
request_rate
(
'*'
))
if
__name__
==
'__main__'
:
unittest
.
main
()
Lib/urllib/robotparser.py
Dosyayı görüntüle @
9a7bbb2e
...
...
@@ -175,16 +175,20 @@ class RobotFileParser:
return
True
def
crawl_delay
(
self
,
useragent
):
if
not
self
.
mtime
():
return
None
for
entry
in
self
.
entries
:
if
entry
.
applies_to
(
useragent
):
return
entry
.
delay
return
None
return
self
.
default_entry
.
delay
def
request_rate
(
self
,
useragent
):
if
not
self
.
mtime
():
return
None
for
entry
in
self
.
entries
:
if
entry
.
applies_to
(
useragent
):
return
entry
.
req_rate
return
Non
e
return
self
.
default_entry
.
req_rat
e
def
__str__
(
self
):
return
''
.
join
([
str
(
entry
)
+
"
\n
"
for
entry
in
self
.
entries
])
...
...
Misc/NEWS
Dosyayı görüntüle @
9a7bbb2e
...
...
@@ -29,6 +29,9 @@ Core and Builtins
Library
-------
- Issue #25400: RobotFileParser now correctly returns default values for
crawl_delay and request_rate. Initial patch by Peter Wirtz.
- Issue #27932: Prevent memory leak in win32_ver().
- Fix UnboundLocalError in socket._sendfile_use_sendfile.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment