File "robotparser.cpython-37.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python37/lib64/python3.7/urllib/__pycache__/robotparser.cpython-37.pyc
File size: 6.92 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit

B

 f"@s\dZddlZddlZddlZdgZeddZGdddZGdddZ	Gd	d
d
Z
dS)a% robotparser.py

    Copyright (C) 2000  Bastian Kleineidam

    You can choose between two licenses when using this package:
    1) GNU GPLv2
    2) PSF license for Python 2.2

    The robots.txt Exclusion Protocol is implemented as specified in
    http://www.robotstxt.org/norobots-rfc.txt
NRobotFileParserRequestRatezrequests secondsc@sjeZdZdZdddZddZddZd	d
ZddZd
dZ	ddZ
ddZddZddZ
ddZdS)rzs This class provides a set of methods to read, parse and answer
    questions about a single robots.txt file.

    cCs,g|_d|_d|_d|_||d|_dS)NFr)entries
default_entrydisallow_all	allow_allset_urllast_checked)selfurlr
7/opt/alt/python37/lib64/python3.7/urllib/robotparser.py__init__s
zRobotFileParser.__init__cCs|jS)zReturns the time the robots.txt file was last fetched.

        This is useful for long-running web spiders that need to
        check for new robots.txt files periodically.

        )r
)rr
r
rmtime$szRobotFileParser.mtimecCsddl}||_dS)zYSets the time the robots.txt file was last fetched to the
        current time.

        rN)timer
)rrr
r
rmodified-szRobotFileParser.modifiedcCs&||_tj|dd\|_|_dS)z,Sets the URL referring to a robots.txt file.N)rurllibparseurlparseZhostpath)rrr
r
rr	5szRobotFileParser.set_urlc
Csytj|j}WnRtjjk
rd}z0|jdkr:d|_n|jdkrT|jdkrTd|_Wdd}~XYnX|	}|
|ddS)z4Reads the robots.txt URL and feeds it to the parser.)iiTiiNzutf-8)
rZrequestZurlopenrerrorZ	HTTPErrorcoderrreadrdecode
splitlines)rferrrawr
r
rr:s
zRobotFileParser.readcCs,d|jkr|jdkr(||_n|j|dS)N*)
useragentsrrappend)rentryr
r
r
_add_entryGs

zRobotFileParser._add_entrycCs6d}t}|x|D]}|sT|dkr8t}d}n|dkrT||t}d}|d}|dkrr|d|}|}|sq|dd}t|dkr|d|d<tj	
|d|d<|ddkr|dkr||t}|j|dd}q|ddkr4|dkr|j
t|dd	d}q|dd
krh|dkr|j
t|ddd}q|ddkr|dkr|drt|d|_d}q|dd
kr|dkr|dd}t|dkr|dr|drtt|dt|d|_d}qW|dkr2||dS)zParse the input lines from a robots.txt file.

        We allow that a user-agent: line is not preceded by
        one or more blank lines.
        rr#N:z
user-agentZdisallowFZallowTzcrawl-delayzrequest-rate/)Entryrr%findstripsplitlenlowerrrunquoter"r#	rulelinesRuleLineisdigitintdelayrreq_rate)rlinesstater$lineiZnumbersr
r
rrPsd






 
zRobotFileParser.parsecCs|jr
dS|jrdS|jsdStjtj|}tjdd|j|j	|j
|jf}tj|}|sfd}x"|j
D]}||rn||SqnW|jr|j|SdS)z=using the parsed robots.txt decide if useragent can fetch urlFTrr))rrr
rrrr0
urlunparserZparamsZqueryZfragmentquoter
applies_to	allowancer)r	useragentrZ
parsed_urlr$r
r
r	can_fetchs$
zRobotFileParser.can_fetchcCs>|sdSx|jD]}||r|jSqW|jr:|jjSdS)N)rrr=r5r)rr?r$r
r
rcrawl_delays

zRobotFileParser.crawl_delaycCs>|sdSx|jD]}||r|jSqW|jr:|jjSdS)N)rrr=r6r)rr?r$r
r
rrequest_rates

zRobotFileParser.request_ratecCs0|j}|jdk	r||jg}dtt|dS)N
)rrjoinmapstr)rrr
r
r__str__s
zRobotFileParser.__str__N)r)__name__
__module____qualname____doc__rrrr	rr%rr@rArBrGr
r
r
rrs
	
	C

c@s(eZdZdZddZddZddZdS)	r2zoA rule line is a single "Allow:" (allowance==True) or "Disallow:"
       (allowance==False) followed by a path.cCs<|dkr|sd}tjtj|}tj||_||_dS)NrT)rrr;rr<rr>)rrr>r
r
rrs
zRuleLine.__init__cCs|jdkp||jS)Nr!)r
startswith)rfilenamer
r
rr=szRuleLine.applies_tocCs|jr
dndd|jS)NZAllowZDisallowz: )r>r)rr
r
rrGszRuleLine.__str__N)rHrIrJrKrr=rGr
r
r
rr2sr2c@s0eZdZdZddZddZddZdd	Zd
S)r*z?An entry has one or more user-agents and zero or more rulelinescCsg|_g|_d|_d|_dS)N)r"r1r5r6)rr
r
rrszEntry.__init__cCsg}x|jD]}|d|qW|jdk	r@|d|j|jdk	rj|j}|d|jd|j|tt|j	|dd
|S)NzUser-agent: z
Crawl-delay: zRequest-rate: r)rrC)r"r#r5r6ZrequestsZsecondsextendrErFr1rD)rZretagentZrater
r
rrGs


z
Entry.__str__cCsF|dd}x.|jD]$}|dkr*dS|}||krdSqWdS)z2check if this entry applies to the specified agentr)rr!TF)r-r/r")rr?rOr
r
rr=szEntry.applies_tocCs$x|jD]}||r|jSqWdS)zZPreconditions:
        - our agent applies to this entry
        - filename is URL decodedT)r1r=r>)rrMr9r
r
rr>s

zEntry.allowanceN)rHrIrJrKrrGr=r>r
r
r
rr*s


r*)rKcollectionsZurllib.parserZurllib.request__all__
namedtuplerrr2r*r
r
r
r<module>s6