ž
¨ÿfõ c @ sd d Z d d l Z d d l Z d g Z Gd d „ d ƒ Z Gd d „ d ƒ Z Gd d „ d ƒ Z d S( u< 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://info.webcrawler.com/mak/projects/robots/norobots-rfc.html
i Nu RobotFileParserc B s‰ | Ee Z d Z d Z d d d „ Z d d „ Z d d „ Z d d
„ Z d d „ Z d
d „ Z d d „ Z
d d „ Z d d „ Z d S( u RobotFileParserus This class provides a set of methods to read, parse and answer
questions about a single robots.txt file.
u c C s> g | _ d | _ d | _ d | _ | j | ƒ d | _ d S( Ni F( u entriesu Noneu
default_entryu Falseu disallow_allu allow_allu set_urlu last_checked( u selfu url( ( u7 /opt/alt/python33/lib64/python3.3/urllib/robotparser.pyu __init__ s
u RobotFileParser.__init__c C s | j S( u· Returns 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.
( u last_checked( u self( ( u7 /opt/alt/python33/lib64/python3.3/urllib/robotparser.pyu mtime s u RobotFileParser.mtimec C s d d l } | j ƒ | _ d S( uY Sets the time the robots.txt file was last fetched to the
current time.
i N( u timeu last_checked( u selfu time( ( u7 /opt/alt/python33/lib64/python3.3/urllib/robotparser.pyu modified( s u RobotFileParser.modifiedc C s5 | | _ t j j | ƒ d d … \ | _ | _ d S( u, Sets the URL referring to a robots.txt file.i i N( u urlu urllibu parseu urlparseu hostu path( u selfu url( ( u7 /opt/alt/python33/lib64/python3.3/urllib/robotparser.pyu set_url0 s u RobotFileParser.set_urlc C s© y t j j | j ƒ } Wna t j j k
r| } z; | j d k rO d | _ n | j d k rj d | _ n WYd d } ~ Xn) X| j
ƒ } | j | j d ƒ j
ƒ ƒ d S( u4 Reads the robots.txt URL and feeds it to the parser.i‘ i“ i Nu utf-8( i‘ i“ T( u urllibu requestu urlopenu urlu erroru HTTPErroru codeu Trueu disallow_allu allow_allu readu parseu decodeu
splitlines( u selfu fu erru raw( ( u7 /opt/alt/python33/lib64/python3.3/urllib/robotparser.pyu read5 s u RobotFileParser.readc C sA d | j k r- | j d k r= | | _ q= n | j j | ƒ d S( Nu *( u
useragentsu
default_entryu Noneu entriesu append( u selfu entry( ( u7 /opt/alt/python33/lib64/python3.3/urllib/robotparser.pyu
_add_entryB s u RobotFileParser._add_entryc C s d } t ƒ } xã| D]Û} | sn | d k r@ t ƒ } d } qn | d k rn | j | ƒ t ƒ } d } qn n | j d ƒ } | d k rœ | d | … } n | j ƒ } | s´ q n | j d d ƒ } t | ƒ d k r | d j ƒ j ƒ | d