• File: robotparser.pyo
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python27/lib64/python2.7/robotparser.pyo
  • Date Modified: 10/26/2026 8:10 PM
  • File size: 8.12 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

jc@s}dZddlZddlZdgZdddYZdddYZdd
dYZd	ejfd
YZdS(s& 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

iNtRobotFileParsercBsbeZdZddZdZdZdZdZdZdZ	d	Z
d
ZRS(ss This class provides a set of methods to read, parse and answer
    questions about a single robots.txt file.

    tcCs>g|_d|_t|_t|_|j|d|_dS(Ni(tentriestNonet
default_entrytFalsetdisallow_allt	allow_alltset_urltlast_checked(tselfturl((s0/opt/alt/python27/lib64/python2.7/robotparser.pyt__init__s				
cCs|jS(sReturns 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	(R
((s0/opt/alt/python27/lib64/python2.7/robotparser.pytmtime!scCsddl}|j|_dS(sYSets the time the robots.txt file was last fetched to the
        current time.

        iN(ttimeR	(R
R((s0/opt/alt/python27/lib64/python2.7/robotparser.pytmodified*scCs/||_tj|dd!\|_|_dS(s,Sets the URL referring to a robots.txt file.iiN(Rturlparsethosttpath(R
R((s0/opt/alt/python27/lib64/python2.7/robotparser.pyR2s	cCst}|j|j}g|D]}|j^q"}|j|j|_|jdkrkt|_nO|jdkr|jdkrt|_n%|jdkr|r|j	|ndS(s4Reads the robots.txt URL and feeds it to the parser.iiiiiN(ii(
t	URLopenertopenRtstriptcloseterrcodetTrueRRtparse(R
topenertftlinetlines((s0/opt/alt/python27/lib64/python2.7/robotparser.pytread7s	
cCsAd|jkr-|jdkr=||_q=n|jj|dS(Nt*(t
useragentsRRRtappend(R
tentry((s0/opt/alt/python27/lib64/python2.7/robotparser.pyt
_add_entryEscCs&d}d}t}|jx|D]}|d7}|s|dkrZt}d}q|dkr|j|t}d}qn|jd}|dkr|| }n|j}|sq&n|jdd}t|dkr&|djj|d<tj	|dj|d<|ddkru|dkrX|j|t}n|j
j|dd}q|ddkr|dkr|jjt
|dtd}qq|ddkr|dkr|jjt
|dtd}qqq&q&W|dkr"|j|nd	S(
sparse the input lines from a robots.txt file.
           We allow that a user-agent: line is not preceded by
           one or more blank lines.iiit#t:s
user-agenttdisallowtallowN(tEntryRR#tfindRtsplittlentlowerturllibtunquoteR R!t	rulelinestRuleLineRR(R
Rtstatet
linenumberR"Rti((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRNsP	


		
	

	cCs|jr
tS|jrtS|js'tStjtj|}tjdd|j	|j
|j|jf}tj
|}|sd}nx-|jD]"}|j|r|j|SqW|jr|jj|StS(s=using the parsed robots.txt decide if useragent can fetch urlRt/(RRRRR	RR-R.t
urlunparseRtparamstquerytfragmenttquoteRt
applies_tot	allowanceR(R
t	useragentRt
parsed_urlR"((s0/opt/alt/python27/lib64/python2.7/robotparser.pyt	can_fetchs$					cCsE|j}|jdk	r+||jg}ndjtt|dS(Ns
(RRRtjointmaptstr(R
R((s0/opt/alt/python27/lib64/python2.7/robotparser.pyt__str__s	(t__name__t
__module__t__doc__RR
RRRR#RR>RB(((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRs								4	 R0cBs)eZdZdZdZdZRS(soA rule line is a single "Allow:" (allowance==True) or "Disallow:"
       (allowance==False) followed by a path.cCsS|dkr|rt}ntjtj|}tj||_||_dS(NR(RRR5R-R9RR;(R
RR;((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRs
	cCs|jdkp|j|jS(NR(Rt
startswith(R
tfilename((s0/opt/alt/python27/lib64/python2.7/robotparser.pyR:scCs|jrdpdd|jS(NtAllowtDisallows: (R;R(R
((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRBs(RCRDRERR:RB(((s0/opt/alt/python27/lib64/python2.7/robotparser.pyR0s		R(cBs2eZdZdZdZdZdZRS(s?An entry has one or more user-agents and zero or more rulelinescCsg|_g|_dS(N(R R/(R
((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRs	cCsjg}x'|jD]}|jd|dgqWx*|jD]}|jt|dgq:Wdj|S(NsUser-agent: s
R(R textendR/RAR?(R
trettagentR((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRBscCs]|jddj}x=|jD]2}|dkr9tS|j}||kr#tSq#WtS(s2check if this entry applies to the specified agentR4iR(R*R,R RR(R
R<RL((s0/opt/alt/python27/lib64/python2.7/robotparser.pyR:scCs.x'|jD]}|j|r
|jSq
WtS(sZPreconditions:
        - our agent applies to this entry
        - filename is URL decoded(R/R:R;R(R
RGR((s0/opt/alt/python27/lib64/python2.7/robotparser.pyR;s(RCRDRERRBR:R;(((s0/opt/alt/python27/lib64/python2.7/robotparser.pyR(s
			
RcBs#eZdZdZdZRS(cGs tjj||d|_dS(Ni(R-tFancyURLopenerRR(R
targs((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRscCsdS(N(NN(R(R
Rtrealm((s0/opt/alt/python27/lib64/python2.7/robotparser.pytprompt_user_passwdscCs(||_tjj||||||S(N(RR-RMthttp_error_default(R
RtfpRterrmsgtheaders((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRQs	(RCRDRRPRQ(((s0/opt/alt/python27/lib64/python2.7/robotparser.pyRs		((((	RERR-t__all__RR0R(RMR(((s0/opt/alt/python27/lib64/python2.7/robotparser.pyt<module>s	$