Your IP : 216.73.216.52


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_robotparser.cpython-35.opt-2.pyc



���]i�@s&ddlZddlZddlZddlmZmZddlmZddl	m
Z
ddlmZm
Z
yddlZWnek
r�dZYnXGdd�dej�Zej�Zdd	d
�ZdZdd
gZdddgZedeee�dZdd
dOgZdgZedeee�dZgZdddgZedeee�dZgZdddddddgZed eeed!�ed"eeed#�d$ZdgZddddd%d&gZed'eee�d(ZdgZgZed)eee�d*Zd+gZd,gZed-eeed.d/�d0ZgZd1gZed2eeed.d/�gZd1gZed3eeed.d4�d5ZgZd1gZed6eeed.d/�d1gZgZed7eeed.d4�d*Zd+gZd,gZed8eeed.d9�d:Zd;gZd<gZed=eee�d>Zd?gZd;gZed@eee�dAZdBgZdCgZedDeee�GdEdF�dFe�ZejedG�GdHdI�dIej��ZGdJdK�dKej�ZdLdM�ZedNkr"ej�dS)P�N)�URLError�	HTTPError)�urlopen)�support)�BaseHTTPRequestHandler�
HTTPServerc@sCeZdZddddddd�Zdd�Zdd�ZdS)�
RobotTestCaseNcCszt|t�sdStjj|�|r?d||f|_nd||f|_||_||_||_||_	dS)NzRobotTest(%d, good, %s)zRobotTest(%d, bad, %s))
�
isinstance�int�unittest�TestCase�__init__�str�parser�url�good�agent)�self�indexrrrr�r�5/opt/alt/python35/lib64/python3.5/test_robotparser.pyr
s			zRobotTestCase.__init__cCs~t|jt�r$|j\}}n|j}|j}|jr^|j|jj||��n|j|jj||��dS)N)	r	r�tuplerr�
assertTruer�	can_fetch�assertFalse)rrrrrr�runTests			zRobotTestCase.runTestcCs|jS)N)r)rrrr�__str__(szRobotTestCase.__str__)�__name__�
__module__�__qualname__r
rrrrrrrsrZtest_robotparsercCs�tj|�j�}tjj�}|j|�x-|D]%}tjt	|||d|��q8Wx-|D]%}tjt	|||d|��qhWdS)N�r)
�io�StringIO�	readlines�urllib�robotparser�RobotFileParser�parse�tests�addTestr)rZ
robots_txtZ	good_urlsZbad_urlsr�linesrrrrr�	RobotTest-s

#
r+z�
User-agent: *
Disallow: /cyberworld/map/ # This is an infinite virtual URL space
Disallow: /tmp/ # these will soon disappear
Disallow: /foo.html
�/z
/test.html�/cyberworld/map/index.htmlz/tmp/xxxz	/foo.htmlr z�
# robots.txt for http://www.example.com/

User-agent: *
Disallow: /cyberworld/map/ # This is an infinite virtual URL space

# Cybermapper knows where to go.
User-agent: cybermapper
Disallow:

�cybermapper�z%
# go away
User-agent: *
Disallow: /
z/tmp/�zm
User-agent: figtree
Disallow: /tmp
Disallow: /a%3cd.html
Disallow: /a%2fb.html
Disallow: /%7ejoe/index.html
z/tmpz	/tmp.htmlz/tmp/a.htmlz/a%3cd.htmlz/a%3Cd.htmlz/a%2fb.htmlz/~joe/index.html�Zfigtree�zFigTree Robot libwww-perl/5.04zf
User-agent: *
Disallow: /tmp/
Disallow: /a%3Cd.html
Disallow: /a/b.html
Disallow: /%7ejoe/index.html
z	/a/b.htmlz/%7Ejoe/index.html�z
User-Agent: *
Disallow: /.
�zG
User-agent: Googlebot
Allow: /folder1/myfile.html
Disallow: /folder1/
z/folder1/myfile.htmlz/folder1/anotherfile.html�rZ	GooglebotzJ
User-agent: Googlebot
Disallow: /

User-agent: Googlebot-Mobile
Allow: /
z/something.jpg�	�
zGooglebot-MobilezJ
User-agent: Googlebot-Mobile
Allow: /

User-agent: Googlebot
Disallow: /
���
Z	googlebotz/
User-agent: *
Disallow: /some/path?name=value
z
/some/pathz/some/path?name=value�zK
User-agent: *
Disallow: /some/path

User-agent: *
Disallow: /another/path
z
/another/path�z;
User-agent: *
Allow: /some/path?
Disallow: /another/path?
z/some/path?z/another/path?�c@s(eZdZdd�Zdd�ZdS)�RobotHandlercCs|jdd�dS)Ni�zForbidden access)Z
send_error)rrrr�do_GETszRobotHandler.do_GETcGsdS)Nr)r�format�argsrrr�log_messageszRobotHandler.log_messageN)rrrr?rBrrrrr>sr>z threading required for this testc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�PasswordProtectedSiteTestCasecCsettjdft�|_tjddd|jjdddi�|_d|j_	|jj
�dS)	Nr�namezHTTPServer serving�target�kwargsZ
poll_intervalg{�G�z�?T)rr�HOSTr>�server�	threading�ThreadZ
serve_forever�t�daemon�start)rrrr�setUps	z#PasswordProtectedSiteTestCase.setUpcCs+|jj�|jj�|jj�dS)N)rH�shutdownrK�joinZserver_close)rrrr�tearDowns

z&PasswordProtectedSiteTestCase.tearDowncCs|j�dS)N)�testPasswordProtectedSite)rrrrrsz%PasswordProtectedSiteTestCase.runTestcCsx|jj}dtjdt|d�}|d}tjj�}|j|�|j	�|j
|jd|��dS)Nzhttp://�:r z/robots.txt�*)rHZserver_addressrrGrr$r%r&Zset_url�readrr)r�addrrZ
robots_urlrrrrrR!s


z7PasswordProtectedSiteTestCase.testPasswordProtectedSitecCsd|jjS)Nz%s)�	__class__r)rrrrr*sz%PasswordProtectedSiteTestCase.__str__N)rrrrNrQrrRrrrrrrC	s

	rCc@s+eZdZejd�dd��ZdS)�NetworkTestCasez7does not handle the gzip encoding delivered by pydotorgcCs]tjd�tjd��:tjjd�}|j�|j|jdd��WdQRXdS)NZnetworkzwww.python.orgz http://www.python.org/robots.txtrT)	rZrequiresZtransient_internetr$r%r&rUrr)rrrrr�
testPythonOrg/s
		
zNetworkTestCase.testPythonOrgN)rrrr�skiprYrrrrrX-srXcCs0tjt�}|jt�|jt��|S)N)rZ	makeSuiterXr)r(rC)�loaderZsuite�patternrrr�
load_tests9s
r]�__main__)r.r-)r!rZurllib.robotparserr$Zurllib.errorrrZurllib.requestrZtestrZhttp.serverrrrI�ImportErrorrrZ	TestSuiter(r+�docrZbadr>Z
skipUnlessrCrXr]r�mainrrrr�<module>s�

												
																#