/snap/core18/2999/usr/lib/python3.6/urllib/__pycache__
NameSizeModeActions
error.cpython-36.pyc27540644editdlrm
parse.cpython-36.pyc321370644editdlrm
request.cpython-36.pyc726320644editdlrm
response.cpython-36.pyc32270644editdlrm
robotparser.cpython-36.pyc70510644editdlrm
__init__.cpython-36.pyc1200644editdlrm
Edit: /snap/core18/2999/usr/lib/python3.6/urllib/__pycache__/robotparser.cpython-36.pyc (7051B)
3 Nqi"@s\dZddlZddlZddlZdgZejddZGdddZGdddZ 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 NRobotFileParser RequestRatezrequests secondsc@sjeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ 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|_|j|d|_dS)NFr)entries default_entry disallow_all allow_allset_url last_checked)selfurlr (/usr/lib/python3.6/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 )r r r rmtime$szRobotFileParser.mtimecCsddl}|j|_dS)zYSets the time the robots.txt file was last fetched to the current time. rN)timer )r rr r rmodified-szRobotFileParser.modifiedcCs&||_tjj|dd\|_|_dS)z,Sets the URL referring to a robots.txt file.N)r urllibparseurlparseZhostpath)r r r r rr 5szRobotFileParser.set_urlcCsytjj|j}WnRtjjk rd}z2|jdkr:d|_n|jdkrT|jdkrTd|_WYdd}~XnX|j }|j |j dj dS) z4Reads the robots.txt URL and feeds it to the parser.TiiNzutf-8)rr) rZrequestZurlopenr errorZ HTTPErrorcoderrreadrdecode splitlines)r ferrrawr r rr:s zRobotFileParser.readcCs,d|jkr|jdkr(||_n |jj|dS)N*) useragentsrrappend)r entryr r r _add_entryGs  zRobotFileParser._add_entrycCs6d}t}|jx|D]}|sT|dkr8t}d}n|dkrT|j|t}d}|jd}|dkrr|d|}|j}|sq|jdd}t|dkr|djj|d<tj j |dj|d<|ddkr|dkr|j|t}|j j |dd}q|ddkr4|dkr|j j t|dd d}q|dd krh|dkr|j j t|dd d}q|dd kr|dkr|djjrt|d|_d}q|dd kr|dkr|djd}t|dkr|djjr|djjrtt|dt|d|_d}qW|dkr2|j|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-agentZdisallowFZallowTz crawl-delayz request-rate/)Entryrr'findstripsplitlenlowerrrunquoter$r% rulelinesRuleLineisdigitintdelayrreq_rate)r linesstater&lineiZnumbersr r rrPsd             zRobotFileParser.parsecCs|jr dS|jrdS|jsdStjjtjj|}tjjdd|j|j |j |j f}tjj |}|sfd}x"|j D]}|j|rn|j|SqnW|jr|jj|SdS)z=using the parsed robots.txt decide if useragent can fetch urlFTrr+)rrr rrrr2 urlunparserZparamsZqueryZfragmentquoter applies_to allowancer)r useragentr Z parsed_urlr&r r r can_fetchs$    zRobotFileParser.can_fetchcCs4|js dSx|jD]}|j|r|jSqW|jjS)N)rrr?r7r)r rAr&r r r crawl_delays    zRobotFileParser.crawl_delaycCs4|js dSx|jD]}|j|r|jSqW|jjS)N)rrr?r8r)r rAr&r r r request_rates    zRobotFileParser.request_ratecCs0|j}|jdk r||jg}djtt|dS)N )rrjoinmapstr)r rr r r__str__s  zRobotFileParser.__str__N)r)__name__ __module__ __qualname____doc__rrrr rr'rrBrCrDrIr r r rrs    Cc@s(eZdZdZddZddZddZdS) r4zoA rule line is a single "Allow:" (allowance==True) or "Disallow:" (allowance==False) followed by a path.cCs>|dkr| rd}tjjtjj|}tjj||_||_dS)NrT)rrr=rr>rr@)r rr@r r rrs zRuleLine.__init__cCs|jdkp|j|jS)Nr#)r startswith)r filenamer r rr?szRuleLine.applies_tocCs|jr dndd|jS)NZAllowZDisallowz: )r@r)r r r rrIszRuleLine.__str__N)rJrKrLrMrr?rIr r r rr4sr4c@s0eZdZdZddZddZddZdd Zd S) r,z?An entry has one or more user-agents and zero or more rulelinescCsg|_g|_d|_d|_dS)N)r$r3r7r8)r r r rrszEntry.__init__cCsg}x|jD]}|jd|q W|jdk r@|jd|j|jdk rj|j}|jd|jd|j|jtt|j |jddj |S)Nz User-agent: z Crawl-delay: zRequest-rate: r+rrE) r$r%r7r8ZrequestsZsecondsextendrGrHr3rF)r ZretagentZrater r rrIs    z Entry.__str__cCsF|jddj}x.|jD]$}|dkr*dS|j}||krdSqWdS)z2check if this entry applies to the specified agentr+rr#TF)r/r1r$)r rArQr r rr?s zEntry.applies_tocCs$x|jD]}|j|r|jSqWdS)zZPreconditions: - our agent applies to this entry - filename is URL decodedT)r3r?r@)r rOr;r r rr@s   zEntry.allowanceN)rJrKrLrMrrIr?r@r r r rr,s   r,) rM collectionsZ urllib.parserZurllib.request__all__ namedtuplerrr4r,r r r r s 2