Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_urllib2.cpython-39.pyc

a

��g�:�@sddlZddlmZddlmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Zddl
mZmZmZmZmZmZmZmZddlmZddlZddlZGdd�dej�ZGd	d
�d
ej�ZGdd�d�ZGd
d�d�Z Gdd�de!�Z"Gdd�dej#�Z$Gdd�d�Z%Gdd�d�Z&Gdd�dej'�Z(Gdd�d�Z)Gdd�d�Z*dd�Z+dd �Z,Gd!d"�d"ej-j.�Z/Gd#d$�d$ej-j0�Z1Gd%d&�d&ej-j.�Z2Gd'd(�d(�Z3Gd)d*�d*ej�Z4d+d,�Z5Gd-d.�d.ej�Z6Gd/d0�d0ej�Z7Gd1d2�d2ej�Z8e9d3k�re�:�dS)4�N)�support)�
socket_helper)�test_urllib)�Request�OpenerDirector�HTTPBasicAuthHandler�HTTPPasswordMgrWithPriorAuth�_parse_proxy�_proxy_bypass_winreg_override�_proxy_bypass_macosx_sysconf�AbstractDigestAuthHandler)�urlparsec@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TrivialTestsc
Cs�dD]�}i}td||�|d=|dkrdtjdkrd|�d�|�d�}}|�|jd�|�|jd�|��D](\}}|�|jd	|d
|||jf�qlqdS)N)�request�response�parse�error�robotparserzfrom urllib.%s import *�__builtins__r�nt�url2pathname�pathname2urlZ
nturl2pathz	urllib.%sz.%r is exposed in 'urllib.%s' but defined in %r)�exec�os�name�pop�assertEqual�
__module__�items)�self�module�context�u�p�k�v�r&�-/usr/local/lib/python3.9/test/test_urllib2.py�test___all__"s
��zTrivialTests.test___all__cCs�|�tjj�|�ttjjd�tj�	tjj
��tjd�}tj
dkrNd|}nd|}tj�|��}|��Wd�n1s�0YdS)Nz	bogus url�/rz
file:///%s�	file://%s)�
addCleanup�urllibr�
urlcleanup�assertRaises�
ValueError�urlopenr�path�abspath�__file__�replace�sepr�read)rZfnameZfile_url�fr&r&r'�test_trivial1s

zTrivialTests.test_trivialcCsRdgd�fdddgfdgd�fdgd	�fg}|D]\}}|�tj�|�|�q0dS)
Nza,b,c)�a�b�czpath"o,l"og"i"cal, examplezpath"o,l"og"i"calZexampleza, b, "c", "d", "e,f", g, h)r9r:z"c"z"d"z"e,f"�g�hza="b\"c", d="e\,f", g="h\\i")za="b"c"zd="e,f"zg="h\i")rr,rZparse_http_list)r�tests�string�listr&r&r'�test_parse_http_listDs

���z!TrivialTests.test_parse_http_listcCs"tj�d�}|�|jt|��dS)N�reason)r,r�URLError�assertInrB�str)r�errr&r&r'�test_URLError_reasonstrOsz$TrivialTests.test_URLError_reasonstrN)�__name__r�__qualname__r(r8rArGr&r&r&r'r src@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�RequestHdrsTestscCsDd}|�t|ddid�jdd�|�t|ddid�jdd�dS)a(
        The Request.headers dictionary is not a documented interface.  It
        should stay that way, because the complete set of headers are only
        accessible through the .get_header(), .has_header(), .header_items()
        interface.  However, .headers pre-dates those methods, and so real code
        will be using the dictionary.

        The introduction in 2.4 of those methods was a mistake for the same
        reason: code that previously saw all (urllib2 user)-provided headers in
        .headers now sees only a subset.

        �http://example.com�	Spam-eggs�blah��headersz	spam-EggSN)rrrO)r�urlr&r&r'�test_request_headers_dictVs
������z*RequestHdrsTests.test_request_headers_dictcCs�d}t|ddid�}|�|�d��|�|��dg�|�dd�|�t|���ddg�|�|�d	��|�|�	d	��|�|�	d	d
�d
�|�
d�|�|�d��|�dd�|�|�d��|�
d�|�|�d��d
S)a;
        Note the case normalization of header names here, to
        .capitalize()-case.  This should be preserved for
        backwards-compatibility.  (In the HTTP case, normalization to
        .title()-case is done by urllib2 before sending headers to
        http.client).

        Note that e.g. r.has_header("spam-EggS") is currently False, and
        r.get_header("spam-EggS") returns None, but that could be changed in
        future.

        Method r.remove_header should remove items both from r.headers and
        r.unredirected_hdrs dictionaries
        rKrLrMrN)rLrMzFoo-Bar�baz)zFoo-barrRz	Not-there�defaultzUnredirected-spamZEggsN)r�
assertTrue�
has_headerrZheader_items�
add_header�sorted�assertFalse�assertIsNone�
get_headerZ
remove_header�add_unredirected_header)rrP�reqr&r&r'�test_request_headers_methodsks"�

z-RequestHdrsTests.test_request_headers_methodscCs`tj��}|j}|j}|dddd�|dddd�|dddd	�|dd
dd�|dd
dd�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|d	ddd�|d	ddd�|d	ddd�|�|d	d�d�|�|d	d�d�|�|d	d�d�|�|d	d�d�|�|d	d �d�|�|d	d!�d"�|d	d#d$d%�|�|d	d&�d"�|�|d	d#�d'�|�|d	d(�d'�|d)dd*d+�|d)dd,d-�|�|d)d�d.�|d/dd0d/�|�|d/d�d1�|�|d/d2�d"�|�|dd3�d"�|�|dd4�d5�|�|dd�d5�|�|dd
�d6�|�|dd
�d7�dS)8Nz
Some Realm�http://example.com/�joe�passwordzhttp://example.com/ni�nizhttp://c.example.com:3128�3r;z
d.example.com�4�dze.example.com:3128�5�e�example.com)r_r`rKzhttp://example.com/spamzhttp://example.com/spam/spamzhttp://example.com/foo�foozhttp://example.com/bar�bar�ninizhttp://example.com/foo/barZfoobarZnibar)rhra)rirjzhttp://example.com/foo/zhttp://example.com/foo/bazzhttp://example.com/foobar�NNzhttp://example.com/baz/rR�nininizhttp://example.com/baz)rRrlzhttp://example.com/baz/barr:�firstrM�second�spam)rnror9�1)rpr9zhttp://a.example.com/z
c.example.comzc.example.com:3128)rbr;)rcrd)rerf�r,rZHTTPPasswordMgr�add_password�find_user_passwordr�rZmgr�addZfind_user_passr&r&r'�test_password_manager�s�
�������������������������z&RequestHdrsTests.test_password_managercCsrtj��}|j}|j}|dddd�|dddd�|d	d
dd�|d
ddd�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|d	d�d�|�|d	d
�d�|�|d	d�d�|�|d
d�d�|�|d
d �d�|�|d
d!�d�|�|d
d"�d�d#S)$z�
        The point to note here is that we can't guess the default port if
        there's no scheme.  This applies to both add_password and
        find_user_password.
        r7zhttp://g.example.com:80�10�jr<zhttp://h.example.com�11r$r=zi.example.com:80�12�l�iz
j.example.com�13�mzg.example.com:100rkzg.example.com:80)rwrxz
g.example.comzhttp://g.example.com:100zhttp://g.example.comz
h.example.com)ryr$zh.example.com:80zhttp://h.example.com:80z
i.example.com)rzr{zhttp://i.example.com:80)r}r~zj.example.com:80zhttp://j.example.comzhttp://j.example.com:80Nrqrtr&r&r'�"test_password_manager_default_port�sZ
�����������z3RequestHdrsTests.test_password_manager_default_portN)rHrrIrQr]rvrr&r&r&r'rJTs$VrJc@s(eZdZgZdejfdd�Zdd�ZdS)�
MockOpenerNcCs||||_|_|_dS�N)r\�data�timeout)rr\r�r�r&r&r'�openszMockOpener.opencGs|||_|_dSr�)�proto�args)rr�r�r&r&r'rszMockOpener.error)rHrrI�
addheaders�socket�_GLOBAL_DEFAULT_TIMEOUTr�rr&r&r&r'r�sr�c@s(eZdZddd�Zd	dd�Zdd�ZdS)
�MockFileNcCsdSr�r&�r�countr&r&r'r6sz
MockFile.readcCsdSr�r&r�r&r&r'�readlineszMockFile.readlinecCsdSr�r&�rr&r&r'�close szMockFile.close)N)N)rHrrIr6r�r�r&r&r&r'r�s

r�c@seZdZdd�ZdS)�MockHeaderscCst|���Sr�)r@�values)rrr&r&r'�
getheaders%szMockHeaders.getheadersN)rHrrIr�r&r&r&r'r�$sr�c@s&eZdZddd�Zdd�Zdd�ZdS)	�MockResponseNcCs.tj�||�||||f\|_|_|_|_dSr�)�io�StringIO�__init__�code�msgrOrP)rr�r�rOr�rPr&r&r'r�*szMockResponse.__init__cCs|jSr�rNr�r&r&r'�info.szMockResponse.infocCs|jSr��rPr�r&r&r'�geturl1szMockResponse.geturl)N)rHrrIr�r�r�r&r&r&r'r�)s
r�c@seZdZdd�Zdd�ZdS)�
MockCookieJarcCs
||_dSr�)�ach_req)rrr&r&r'�add_cookie_header6szMockCookieJar.add_cookie_headercCs|||_|_dSr�)�ec_req�ec_r)rrrr&r&r'�extract_cookies9szMockCookieJar.extract_cookiesN)rHrrIr�r�r&r&r&r'r�5sr�c@seZdZdd�Zdd�ZdS)�
FakeMethodcCs||_||_||_dSr�)�	meth_name�handle�action)rr�r�r�r&r&r'r�>szFakeMethod.__init__cGs|j|j|jg|�R�Sr�)r�r�r�)rr�r&r&r'�__call__CszFakeMethod.__call__N)rHrrIr�r�r&r&r&r'r�=sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�MockHTTPResponsecCs"||_||_||_||_d|_dS)N��)�fpr��statusrBr�)rr�r�r�rBr&r&r'r�Hs
zMockHTTPResponse.__init__cCsdS)N�r&r�r&r&r'r6OszMockHTTPResponse.readcCsiSr�r&r�r&r&r'r�RszMockHTTPResponse.infocCs|jSr�r�r�r&r&r'r�UszMockHTTPResponse.geturlN)rHrrIr�r6r�r�r&r&r&r'r�Gsr�c@sTeZdZdd�Zejfdd�Zdd�Zddd	�Zdd
d�dd
�Z	dd�Z
dd�ZdS)�
MockHTTPClasscCs(d|_g|_d|_d|_d|_i|_dS)NrF)�level�req_headersr��raise_on_endheaders�sock�_tunnel_headersr�r&r&r'r�ZszMockHTTPClass.__init__cCs||_||_|Sr�)�hostr�)rr�r�r&r&r'r�bszMockHTTPClass.__call__cCs
||_dSr�)r�)rr�r&r&r'�set_debuglevelgszMockHTTPClass.set_debuglevelNcCs&||_||_|r||_n
|j��dSr�)�_tunnel_hostZ_tunnel_portr��clear)rr��portrOr&r&r'�
set_tunneljs
zMockHTTPClass.set_tunnelF)�encode_chunkedcCsP||_||_|dur&|j|��7_|j��|r:||_||_|jrLt��dSr�)	�method�selectorr�r�sortr�r�r��OSError)rr�rP�bodyrOr�r&r&r'rrs
zMockHTTPClass.requestcCstt�idd�S)Nr��OK)r�r�r�r&r&r'�getresponseszMockHTTPClass.getresponsecCsdSr�r&r�r&r&r'r��szMockHTTPClass.close)NN)NN)rHrrIr�r�r�r�r�r�rr�r�r&r&r&r'r�Ys
�
r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�MockHandler��cCs|�|�dSr�)�_define_methods)r�methodsr&r&r'r��szMockHandler.__init__cCsJ|D]@}t|�dkr|\}}n
|d}}t|||j�}t|j||�qdS)N�)�lenr�r��setattr�	__class__)rr��specrr��methr&r&r'r��s

zMockHandler._define_methodscOs�|jj�||||f�|dur"dS|dkr.|S|dkrHtddid�}|S|dkrXtd�S|�d�r�||�d	�d
d�}zt|�}Wnty�Yn0tddid�}|j�	d|d||di�S|d
kr�t
j	�d��ds�J�dS)N�return self�return responser�r�r��return requestzhttp://blah/r� ��httpr�raiserMF)�parent�calls�appendr�r�
startswith�rfind�intr/rr,rC)rZfn_namer�r��kwds�resr�r&r&r'r��s*
zMockHandler.handlecCsdSr�r&r�r&r&r'r��szMockHandler.closecCs||_g|j_dSr�)r�r�)rr�r&r&r'�
add_parent�szMockHandler.add_parentcCst|d�sdS|j|jkS)N�
handler_orderT)�hasattrr�)r�otherr&r&r'�__lt__�s
zMockHandler.__lt__N)
rHrrIr�r�r�r�r�r�r�r&r&r&r'r��s	r�cCsbg}d}|D]P}Gdd�dt�}||�}|j|7_|�|�|d}|�|�|�|�q|S)a�Create MockHandlers and add them to an OpenerDirector.

    meth_spec: list of lists of tuples and strings defining methods to define
    on handlers.  eg:

    [["http_error", "ftp_open"], ["http_open"]]

    defines methods .http_error() and .ftp_open() on one handler, and
    .http_open() on another.  These methods just record their arguments and
    return None.  Using a tuple instead of a string causes the method to
    perform some action (see MockHandler.handle()), eg:

    [["http_error"], [("http_open", "return request")]]

    defines .http_error() on one handler (which simply returns None), and
    .http_open() on another handler, which returns a Request object.

    rc@seZdZdS)z6add_ordered_mock_handlers.<locals>.MockHandlerSubclassN�rHrrIr&r&r&r'�MockHandlerSubclass�sr�r�)r�r�r�r��add_handler)�opener�	meth_spec�handlersr��methsr�r=r&r&r'�add_ordered_mock_handlers�s

r�cGst�}|D]}|�|�q
|Sr�)rr�)Zhandler_instancesr�r=r&r&r'�build_test_opener�sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�MockHTTPHandlercCs||_||_|��dSr�)r�rO�reset)rr�rOr&r&r'r��szMockHTTPHandler.__init__cCsd|_g|_dS)Nr)�_count�requestsr�r&r&r'r��szMockHTTPHandler.resetcCs�ddl}ddl}|j�|�|��|jdkrl|jd|_tjj|j	}|�
|j�}|j�
d|t�|j	||�S||_|�
d�}tdd|d|���SdS)Nrr�r��

r�r�r�)�email�copyr�r��deepcopyr�r��client�	responsesr�Zmessage_from_stringrOr�rr�r\r��get_full_url)rr\r�r�rr�r&r&r'�	http_open�s
�
zMockHTTPHandler.http_openN�rHrrIr�r�r�r&r&r&r'r��sr�c@seZdZddd�Zdd�ZdS)�MockHTTPSHandlerrcCstjjj||d�t�|_dS)N��
debuglevel)r,r�AbstractHTTPHandlerr�r��httpconn)rr�r&r&r'r�szMockHTTPSHandler.__init__cCs|�|j|�Sr�)�do_openr��rr\r&r&r'�
https_open	szMockHTTPSHandler.https_openN)r)rHrrIr�r�r&r&r&r'r�s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�MockHTTPHandlerCheckAuthcCs||_d|_dS�NF)r��has_auth_header)rr�r&r&r'r�sz!MockHTTPHandlerCheckAuth.__init__cCs
d|_dSr�)r�r�r&r&r'r�szMockHTTPHandlerCheckAuth.resetcCs6|�d�rd|_tjj|j}t|j|t�d|���S)N�
AuthorizationTr�)	rUr�r�r�r�r�r�r�r�)rr\rr&r&r'r�s
z"MockHTTPHandlerCheckAuth.http_openNr�r&r&r&r'r�
sr�c@seZdZdd�Zdd�ZdS)�MockPasswordManagercCs||_||_||_||_dSr�)�realmrP�userr`)rrZurirr`r&r&r'rr!sz MockPasswordManager.add_passwordcCs||_||_|j|jfSr�)�target_realm�
target_urlrr`)rrZauthurir&r&r'rs'sz&MockPasswordManager.find_user_passwordN)rHrrIrrrsr&r&r&r'r src@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�OpenerDirectorTestscCs(Gdd�dt�}|�tt�j|��dS)Nc@seZdZdS)z<OpenerDirectorTests.test_add_non_handler.<locals>.NonHandlerNr�r&r&r&r'�
NonHandler0sr)�objectr.�	TypeErrorrr�)rrr&r&r'�test_add_non_handler/s
�z(OpenerDirectorTests.test_add_non_handlercCs\ddlm}t�}ddgdgg}t||�|�tj���dD]}|�||j	|d�q>dS)Nr)rC)r�r�)Z
proxy_openr�)Zredirect_requestr�)Zdo�proxy�redirectz://example.com/)
�urllib.errorrCrr�r�r,rZUnknownHandlerr.r�)rrC�or��schemer&r&r'�test_badly_named_methods5s	�
z,OpenerDirectorTests.test_badly_named_methodsc
Cs�t�}gd�dgdgdgg}t||�}td�}|�|�}|�||d�|ddf|ddfg}t||j�D]2\}}|\}	}
}}|�|	|
f|�|�||f�qldS)N)r��ftp_open�http_error_302r�r�r�r^r�rr�)rr�rr�r�zipr�)
rr
r�r�r\�rr��expected�got�handlerrr�r�r&r&r'�test_handledJs�

z OpenerDirectorTests.test_handledcCs�t�}g}dgdfdgdffD]:\}}Gdd�dt�}||�}||_|�|�|�|�q|�d�|�|jdd|d�|�|jdd|d�dS)	Nrr�r�rc@seZdZdS)zCOpenerDirectorTests.test_handler_order.<locals>.MockHandlerSubclassNr�r&r&r&r'r�isr�r^r�)rr�r�r�r�r�rr�)rr
r�r�r�r�r=r&r&r'�test_handler_orderds�

z&OpenerDirectorTests.test_handler_ordercCsZt�}dgdgg}t||�}td�}|�tjj|j|�|�|j	|dd|fifg�dS)N)r�r�rr^rr�)
rr�rr.r,rrCr�rr�)rr
r�r�r\r&r&r'�
test_raisevs�
zOpenerDirectorTests.test_raisecCs�t�}dgddggd�dgg}t||�}td�}|�|�t|j�dksLJ�|dd|ff|dd|tjd	d
iffg}t||j�D]:\}}|\}}	}
|�	||	f|dd��|�	|
|d�q�dS)N)r�z	error 302)Zhttp_error_400r�r�))rr�Zhttp_error_303Z
http_errorrr^r�r�.r�)
rr�rr�r�r�rZ	ALWAYS_EQrr)rr
r�r�r\r�rrrZmethod_namer�r&r&r'�test_http_error�s&�

��
z#OpenerDirectorTests.test_http_errorcCst�}ddgddgg}t||�}td�}|�|�|ddf|ddf|ddf|ddfg}t|j�D]�\}\}}}	}
|dkr�|�||f||�|�t|	�d�|�|	dt�qh|�||f||�|�t|	�d�|�|	dt�|	ddurh|�|	dt	�qhdS)	N)�http_requestr�)�
http_responser�r^rrr�rr�)
rr�rr��	enumerater�rr�ZassertIsInstancer�)rr
r�r�r\r�r|rrr�r�r&r&r'�test_processors�s0���

�z#OpenerDirectorTests.test_processorsN)
rHrrIr	rrrrrr r&r&r&r'r-s
rcCs\z|�d�Wnty*t�d��Yn0tj�|�}tjdkrX|�	d�rX|dd�}|S)Nzutf-8zpath is not encodable to utf8rz///r�)
�encode�UnicodeEncodeError�unittestZSkipTestr,rrrrr�)r1�urlpathr&r&r'�sanepathname2url�sr%c@sxeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Ze� e!j"d9kd:�d;d<��Z#e� e$j%d=kd>�d?d@��Z&dAdB�Z'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+dKdL�Z,dMdN�Z-dOdP�Z.dQdR�Z/dSdT�Z0dUdV�Z1dWS)X�HandlerTestscs�Gdd�d��G�fdd�dtjj�}ddl}d}||�}t�|_dd|jd	d	d
ddgd
df	dd|jdd	d
ddgd
df	dd|jdd	d
ddgd
df	dd|jdd	d
ddgd
df	dddd	d	dddgd	df	dd|jd	d	dgddf	fD]�\	}}}}}	}
}}}
t|�}d|_|�	|�}|�
|j|�|�
|j|	�|�
|j
t�|��|�
|j|�|�
|j|�|�
|jj|�|�
|jj|
�|��}|�
|�d�|
�|�
t|d�t|��q�dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)z-HandlerTests.test_ftp.<locals>.MockFTPWrappercSs
||_dSr��r��rr�r&r&r'r��sz6HandlerTests.test_ftp.<locals>.MockFTPWrapper.__init__cSs$|||_|_t�|j�t|j�fSr�)�filename�filetyper�r�r�r�)rr)r*r&r&r'�retrfile�sz6HandlerTests.test_ftp.<locals>.MockFTPWrapper.retrfilecSsdSr�r&r�r&r&r'r��sz3HandlerTests.test_ftp.<locals>.MockFTPWrapper.closeN)rHrrIr�r+r�r&r&r&r'�MockFTPWrapper�sr,cs&eZdZdd�Zejf�fdd�	ZdS)z-HandlerTests.test_ftp.<locals>.NullFTPHandlercSs
||_dSr�r'r(r&r&r'r��sz6HandlerTests.test_ftp.<locals>.NullFTPHandler.__init__cs4|||_|_|||_|_||_�|j�|_|jSr�)r�passwdr�r��dirsr��
ftpwrapper)rrr-r�r�r.r��r,r&r'�connect_ftp�s
z9HandlerTests.test_ftp.<locals>.NullFTPHandler.connect_ftpN)rHrrIr�r�r�r1r&r0r&r'�NullFTPHandler�s�r2rzrheum rhaponicumz ftp://localhost/foo/bar/baz.html�	localhostr��Irhrizbaz.htmlz	text/htmlz'ftp://parrot@localhost/foo/bar/baz.htmlZparrotz*ftp://%25parrot@localhost/foo/bar/baz.htmlz%parrotz,ftp://%2542parrot@localhost/foo/bar/baz.htmlz	%42parrotzftp://localhost:80/foo/bar/�P�Dzftp://localhost/baz.gif;type=a�Azbaz.gif�Content-type�Content-length)r,rZ
FTPHandler�ftplibr�r�ZFTP_PORTrr�rrrr-r�r��
gethostbynamer�r.r/r)r*r��getr�r�)rr2r:r�r=rPr�r�rr-�type_r.r)Zmimetyper\rrOr&r0r'�test_ftp�sX
�
�
�
�

���
zHandlerTests.test_ftpc
Cs�ddl}tj��}t�}|_tj}tt	j
�|��}d}d|d|dt�
d�|fg}zt�
t���}Wntjy�d}Yn0|r�|�d||f�|D]�}	t|d�}
z�z|
�|�W|
��n
|
��0|�t|	��}z$|��}|��}
|��}W|��n
|��0t	�|�}|jj|jd	d
�}Wt	�|�nt	�|�0|�||�|�|
dd�|�|
d
d�|�|
d|�|�||	�q�d|dddt�
d�t	��|fdt	��|ffD]f}	zRt|d�}
z|
�|�W|
��n
|
��0|� tj!j"|jt|	��Wt	�|�nt	�|�0�q�tj��}t�}|_dD]r\}	}t|	�}z|�|�Wn"tj!j"�y�|�#|�Yn0|�$|j%|�|�|j&d�|�|j&dk|��qBdS)Nrs
hello, world
zfile://localhost%sr*zfile://%s%sr3r��wbT)Zusegmtr8z
text/plainr9r}z
Last-modifiedzfile://localhost:80%szfile:///file_does_not_exist.txtz)file://not-a-local-host.com//dir/file.txtzfile://%s:80%s/%sz,file://somerandomhost.ontheinternet.com%s/%s))zfile://ftp.example.com//foo.txtF)z file://ftp.example.com///foo.txtF)zfile://ftp.example.com/foo.txtF)z"file://somehost//foo/something.txtF)z#file://localhost//foo/something.txtF�ftp)'Zemail.utilsr,r�FileHandlerr�r�r�TESTFNr%rr1r2r�r;�gethostname�gaierrorr�r��writer�Z	file_openrr6r�r��statZutilsZ
formatdate�st_mtime�remover�getcwdr.rrCrX�assertIsr\�type)rr�r=r
rBr$Ztowrite�urlsZ	localaddrrPr7rr�rOZrespurlZstatsZmodifiedr@r\r&r&r'�	test_files�
�




�
��	


�
zHandlerTests.test_filecCsftj��}t�}|_d}dD]�\}}t||ddi�}d|_|�dd�t�}|�	||�}|j
|j|j|j
|j|jdkdf|��}	|	j|	j|�|�
�|�|�|jd	�|�|jd
�|�|j|�|�|jd�|�|jgd��|�|j|�qd
|_|�tjj|j	||�tdd�}|�t|j|�dg|_dD�]}td|�}t ddid�}|�|�}
|du�r�|�!d|j"�|�!d|j"�n$|�|j"dd�|�|j"dd�|�|j"dd	�|�|j"dd�|�dd�|�dd�|�dd�|�dd�|�|�}
|�|j"dd�|�|j"dd�|�|j"dd�|�|j"dd��qDdS)Nr^))�GETN)�POSTsblah�Foori�Spam�eggsr�r�rgrr)))�
Connectionr�)rPri�rQrRTZbadpostrT)�Nr�r9r8�0z!application/x-www-form-urlencoded�HostrhrR)#r,rr�r�r�rr�r[r�r�r6r�r�r�r�r�r<�__contains__rr�r�r�r�r�r�r�r.rrCr�do_request_r�r��assertNotIn�unredirected_hdrs)rr=r
rPr�r�r\r�r�hdrs�newreqr&r&r'�	test_httphsd
�




�
zHandlerTests.test_httpc	Cstj��}t�}|_tjddd�}|j}|��|�	t
j|�t|d��L}t
d|i�}|�|�}|�d�}|�|d�|�|�d��Wd�n1s�0Yt|d��P}t
d|d	d
i�}|�|�}|�t|�d��d
�|�|�d��Wd�n1�s0YdS)Nzw+bF)�mode�delete�rbr^�Transfer-encoding�chunkedr9�Content-Length�)r,rr�r�r��tempfile�NamedTemporaryFilerr�r+r�unlinkr�rrYrZrrXrUr�)	rr=r
�file_objZ	file_pathr7r\r]�ter&r&r'�test_http_body_file�s"


.
z HandlerTests.test_http_body_filecCs�tj��}t�}|_t��}td|i�}|�|�}|�	|�
d�d�|�|�d��ddi}td||�}|�|�}|�	t
|�
d��d�|�|�d��|��dS)Nr^rbrcr9rdre)r,rr�r�r�r��BytesIOrrYrrZrXrUr�r�)rr=r
rir\r]rOr&r&r'�test_http_body_fileobj�s


z#HandlerTests.test_http_body_fileobjc	Cs�tj��}t�}|_tjddg}iddifD]�}tj|tj	d��h}t
d|j|�}|�|�}|s�|�
|�d�d�|�
|�d�d	�n|�
t|�d��d�Wd�q.1s�0Yq.dS)
Nz-c�passrdre)�stdoutr^r9rbrc)r,rr�r�r��sys�
executable�
subprocess�Popen�PIPErrorYrrZr�)rr=r
�cmdrO�procr\r]r&r&r'�test_http_body_pipe�s

��z HandlerTests.test_http_body_pipecCs�tj��}t�}|_dd�}iddifD]\}td|�|�}|�|�}|sp|�|�d�d�|�|�d�d�q*|�t	|�d��d�q*dS)	Ncss
dVdS)Nsoner&r&r&r&r'�
iterable_body�sz;HandlerTests.test_http_body_iterable.<locals>.iterable_bodyrd�r^r9rbrc)
r,rr�r�r�rrYrrZr�)rr=r
rxrOr\r]r&r&r'�test_http_body_iterable�s

�z$HandlerTests.test_http_body_iterablecCsHtj��}t�|_|�tdd��}|�|�d�d�|�	|�
d��dS)Nr^r&rbrcr9)r,rr�r�r�rYrrrZrXrU)rr=r\r&r&r'�test_http_body_empty_seqs

z%HandlerTests.test_http_body_empty_seqcCshtj��}t�}|_t�dgd��}iddifD]0}td||�}|�|�}|�t	|�
d��d�q2dS)Nr4)r�r���rd�r^r9)r,rr�r�r��arrayrrYrr�rZ)rr=r
Ziterable_arrayrOr\r]r&r&r'�test_http_body_arrays

z!HandlerTests.test_http_body_arraycCs6t�}tdd�}|�|�|�d�|�|jd�dS)Nr�r�zhttps://www.example.com)rr�r�r�rZ_debuglevel)rr
r=r&r&r'�test_http_handler_debuglevels



z)HandlerTests.test_http_handler_debuglevelcCsztj��}t�|_d}gd�}|D]R}t||�}|�|�}|�|jdd�|�	dd�|�|�}|�|jdd�q"dS)NrU)z#http://example.com/foo/bar/baz.htmlz$http://example.com//foo/bar/baz.htmlz$http://example.com/foo//bar/baz.htmlz$http://example.com/foo/bar//baz.htmlrWrgzsomeproxy:3128)
r,rr�r�r�rrYrr[�	set_proxy)rr=r�Zds_urlsZds_urlZds_reqZ	np_ds_reqZp_ds_reqr&r&r'�test_http_doubleslash s



z"HandlerTests.test_http_doubleslashcCshgd�}td�}|D]N}||_t|�}|�|��|�|�|jpBd|j�|�t|���j|j�qdS)N)zhttp://example.com?foo=bar#bazz)http://example.com?foo=bar&spam=eggs#bashrKrKr�)r�full_urlr
rr��fragment�query)rrLrrP�parsedr&r&r'�test_full_url_setter;sz!HandlerTests.test_full_url_settercCs6td�}|`|�|j�|�|j�|�|jd�dS)N�http://www.example.comr�)rr�rYr�rr�)rrr&r&r'�test_full_url_deleterRs
z"HandlerTests.test_full_url_deletercCsztj��}t�|_d}t|�}|�|�}|�|jd�|�|j	d�d}t|�}|�|�}|�|jd�|�|j	d�dS)Nzhttp://www.python.org?getspam�www.python.orgz	/?getspam�http://www.python.orgr�)
r,rr�r�r�rrYrr�r�)rr=Z	weird_urlr\r]Zurl_without_pathr&r&r'�test_fixpath_in_weirdurlsYs


z&HandlerTests.test_fixpath_in_weirdurlscCstj��}t�}|_d}t|�}tddid|�}|�||�}|�||�|�	t
|d��tddid|�}|�||�}|�||�|�	t
|d��tdd	id|�}|�||�}|�||�|�	t
|d��td
did|�}|�|�||��|�|j
d�|�|j||d
dif�dS)
Nr^r�r�r�r���ZAccepted��zPartial contenti�zBad gatewayr�)r,rZHTTPErrorProcessorr�r�rr�rrJrXr�rYrr�r�)rr=r
rPr\r�newrr&r&r'�test_errorsls(
zHandlerTests.test_errorscCs�t�}tj�|�}t�|_td�}tddid�}|�|�}|�	|j
|�|�	|j
|�|�|jd�|�
|j�|�||�}|�	|j|�|�	|j|�|�	||�dS)Nr^r�r�r�rg)r�r,r�HTTPCookieProcessorr�r�rr�rrJr�r�origin_req_hostrXZunverifiablerr�r�)r�cjr=r\rr]r�r&r&r'�test_cookies�s
zHandlerTests.test_cookiesc
Csdd}d}tj��}t�}|_dD�]Z}dD�]N}t|d|�}t||�}tj|_	|�
dd�|durz|�
dtt|���|�
d	d
�z||t�|dtd|i��Wn,tjjy�|�|d
�|�|�Yn0|�|j��|�z|�|j��d�Wn"t�y|�|jj�Yn0dd�|jjD�}	|�d|	�|�d|	�|�|jjdd�|�d	|jj�|�d	|jj�q,q"t|�}tj|_	|fdd�}
t|dd�}d}tj|_	z|
||d�|d}�q�Wn*tjj�y�|�|tjjj�Yn0t|dd�}d}tj|_	z |
||d|�|d}�qWn*tjj�y^|�|tjjj�Yn0dS)N�http://example.com/a.htmlzhttp://example.com/b.html)i-ri/�3)Nz
blah
blah
z
http_error_%sZNonsensezviking=withholdrdrQro�Blah�locationr�rNcSsg|]}|���qSr&)�lower)�.0�xr&r&r'�
<listcomp>�rUz.HandlerTests.test_redirect.<locals>.<listcomp>zcontent-lengthzcontent-typec	Ss |�|t�ddtd|i��dS)Nrr�r�)rr�r�)r=r\rPr&r&r'r�s
�z,HandlerTests.test_redirect.<locals>.redirectrg)r�rr^r�zhttp://example.com/%d)r,r�HTTPRedirectHandlerr�r��getattrrr�r�r�rVrEr�r[r�r�r�	HTTPErrorr�assertIsNotNoner\r��
get_method�AttributeErrorrXr�rOrZr[Zmax_repeatsZmax_redirections)r�from_urlZto_urlr=r
r�r�r�r\rOrr�r&r&r'�
test_redirect�sl




���zHandlerTests.test_redirectcCs�d}gd�}gd�}d}tj��}t�}|_t|�}tj|_|D]6}|d|}	|�	tj
j|j|t
�ddtd|	i��qB|D]>}|d|}
|�|t
�dd	td|
i��|�|j��|
�q~dS)
Nr�)r��httpsr@)�file�imapZldapzexample.com/b.htmlz://rzSecurity Loopholer��That's fine)r,rr�r�r�rr�r�r�r.rr�rr�r�rr\r�)rr�Z
valid_schemesZinvalid_schemesZschemeless_urlr=r
r\rZinvalid_url�	valid_urlr&r&r'�test_invalid_redirect�s(


�
�z"HandlerTests.test_invalid_redirectc	Csnd}d}tj��}t�}|_t|�}tj|_tj	�
||�}|�|t�ddt
d|i��|�|j��|�dS)Nr�z/b.htmlrr�r�)r,rr�r�r�rr�r�r�r�urljoinrr�r�rr\r�)rr�Zrelative_urlr=r
r\r�r&r&r'�test_relative_redirect�s

�z#HandlerTests.test_relative_redirectc	Cs�ddlm}ddlm}|�}||dd�tdd�}tj��}tj��}tj�	|�}t
||||�}|�d�|�|j
�d��dS)	Nr)�	CookieJar)�interact_netscapezhttp://www.example.com/z	spam=eggsrz%Location: http://www.cracker.com/

�Cookie)Zhttp.cookiejarr�Ztest.test_http_cookiejarr�r�r,r�HTTPDefaultErrorHandlerr�r�r�r�rXr\rU)	rr�r�r��hh�hdeh�hrhZcpr
r&r&r'�test_cookie_redirects



z!HandlerTests.test_cookie_redirectcCsTd}tdd|�}tj��}tj��}t|||�}|�d�}|�|��|�	��dS)Nz(http://www.example.com/index.html#OK

rz
Location: r�)
r�r,rr�r�r�r�rr��strip)rZredirected_urlr�r�r�r
r�r&r&r'�test_redirect_fragments


z#HandlerTests.test_redirect_fragmentcs|��tjj�tjj�d}t�|�tj_��t	tjd��t
d�����fdd�}|tjj_tj�d�}��|�
�d�dS)Ns(HTTP/1.1 302 Found
Location: ?query

�HTTPConnection)z/pathz/path?querycs8��|t����j|||g|�Ri|��d|j_dS)NsHTTP/1.1 200 OK

Hello!)r�nextrr�Zfakedata)�connr�rP�pos�kw�Z
real_classrrLr&r'r&sz3HandlerTests.test_redirect_no_path.<locals>.requestzhttp://python.org/pathzhttp://python.org/path?query)r+r,rr-r�r�r�r�fakehttpr��iterr0rr�)rZ	response1rr�r&r�r'�test_redirect_no_paths
z"HandlerTests.test_redirect_no_pathc
	Cs�Gdd�dtjj�}|�}tj�|�}d}|D]|\}}|�t|���Vt�d|d�|_|�	d�}d|d}|j
}	|�|	�|�t|	��Wd�q.1s�0Yq.dS)	Nc@seZdZdd�ZdS)z4HandlerTests.test_redirect_encoding.<locals>.HandlercSs(|�|j|�}|jj|_t�d�|_|S)Ns)HTTP/1.1 200 OK
Content-Length: 3

123)r��
connection�buf�last_bufrr�)rr\�resultr&r&r'r�3s
�z>HandlerTests.test_redirect_encoding.<locals>.Handler.http_openN)rHrrIr�r&r&r&r'�Handler2sr�))s/på-dansk/s/p%C3%A5-dansk/)�/spaced%20path/r�)s
/spaced path/r�)s/?på-dansks/?p%C3%A5-dansks!HTTP/1.1 302 Redirect
Location: s

r^sGET � )
r,r�HTTPHandler�build_opener�subTest�reprrr�r�r�r�rTr�)
rr�rr�r>r�r�rrrr&r&r'�test_redirect_encoding/s"���
z#HandlerTests.test_redirect_encodingcCs�d}t|d�t|d�fD]�}t�}tj�|�}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	|�|�|ddfgd	d
�|jD��qdS)N�proxy.example.com:3128�r�)ZHTTP)r�r�zhttp://acme.example.com/zacme.example.comrr�cSsg|]}|dd��qS�rr�r&�r��tupr&r&r'r�brUz+HandlerTests.test_proxy.<locals>.<listcomp>)�dictrr,r�ProxyHandlerr�r�rrr�r�r�)rr"rdr
�phr�r�r\r&r&r'�
test_proxyRs
�

�zHandlerTests.test_proxycCs�dtjd<t�}tj�tdd��}|�|�td�}|�	|j
d�|�|�|�	|j
d�td�}|�	|j
d�|�|�|�	|j
d�tjd=dS)	Nz
python.org�no_proxy�proxy.example.comr�zhttp://www.perl.org/�www.perl.orgr�r��r�environrr,rr�r�r�rrr�r��rr
r�r\r&r&r'�test_proxy_no_proxyds



z HandlerTests.test_proxy_no_proxycCsfdtjd<t�}tj�tdd��}|�|�td�}|�	|j
d�|�|�|�	|j
d�tjd=dS)N�*r�r�r�r�r�r�r�r&r&r'�test_proxy_no_proxy_allss


z$HandlerTests.test_proxy_no_proxy_allcCs�t�}tj�tdd��}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	d�|�|ddfgdd	�|jD��dS)
Nr��r�)r�r��https://www.example.com/�www.example.comrr�cSsg|]}|dd��qSr�r&r�r&r&r'r��rUz1HandlerTests.test_proxy_https.<locals>.<listcomp>)rr,rr�r�r�r�rrr�r�r�)rr
r�r�r�r\r&r&r'�test_proxy_https~s
�

�zHandlerTests.test_proxy_httpscCs�t�}tj�tdd��}|�|�t�}|�|�td�}|�dd�|�dd�|�	|j
d�|�|j�|�
|�|�d	|jj�|�d
|jj�|�|j�|�	|j
d�|�	|�d�d�dS)Nr�r�r��Proxy-Authorization�FooBar�
User-Agent�Grailr�)r�r�)r�r��Proxy-authorization)rr,rr�r�r�r�rrVrr�rYr�r�rZr�r�rDr�rZ)rr
r�Z
https_handlerr\r&r&r'�$test_proxy_https_proxy_authorization�s(


��z1HandlerTests.test_proxy_https_proxy_authorizationrzonly relevant for WindowscCs�d}t}dD]}|�|||�d|�qdD]}|�|||�d|�q,d}|�|d|�d|�|�|d|�d|�d	D]}|�|||�d
|�q|dS)Nz*www.example.com;*.example.net; 192.168.0.1)r�zwww.example.netz192.168.0.1z expected bypass of %s to be true)rgzwww.example.org�example.netz192.168.0.2�!expected bypass of %s to be Falsezexample.com; <local>rgr�)�testr3z.expect <local> to bypass intranet address '%s')r
rTrX)rZproxy_overrideZproxy_bypassr�r&r&r'�test_winreg_proxy_bypass�s.������z%HandlerTests.test_winreg_proxy_bypass�darwinzonly relevant for OSXcCs�dgd�d�}dD]}|�t||�d|�qdD]}|�t||�d|�q2dgd�}|�td	|��dd
dgd�}d}|�t||�d|�d
}|�t||�d|�dS)NF)�foo.barz	*.bar.com�	127.0.0.1z10.10z10.0/16)Zexclude_simple�
exceptions)r�zwww.bar.comr�z	10.10.0.1z10.0.0.1z expected bypass of %s to be True)zabc.foo.barzbar.comz	127.0.0.2z	10.11.0.1Znotinbypassr�Tr�z10.0.0.0/40z172.19.10.0/24z172.19.10.5z10.0.1.5)rTrrX)rZbypassr�r&r&r'�test_osx_proxy_bypass�s0���
���z"HandlerTests.test_osx_proxy_bypasscCs�|j||d��lt�}t�}tj�|�}d�|�d}td|�}|�|�|�|�|�	||d|||dd�Wd�n1s�0YdS)N)rrOz
r��r��!http://acme.example.com/protected)
r�rrr,rr�joinr�r��_test_basic_auth)rrOrr��password_manager�auth_handlerr��http_handlerr&r&r'�check_basic_auth�s



�zHandlerTests.check_basic_authc

Cs.d}d}d|�d�}d|�d�}d}d|�d�}d|�d�d|�d�d|�d	�|�d
|��|�d
|��|�d
|��|�d
|��|�d
|��fD]}d|��g}|�||�q�t�dtf��(d
|��g}|�||�Wd�n1s�0Y||g||g||gfD] }	dd�|	D�}|�||��qdS)Nzrealm2@example.comz
Basic realm="�"zOtherscheme xxxzDigest realm="zn", qop="auth, auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"z
Basic realm='�'z", charset="UTF-8"z, �WWW-Authenticate: zBasic Auth Realm was unquotedzWWW-Authenticate: Basic realm=cSsg|]}d|���qS)r�r&)r�Z	challenger&r&r'r�s�z0HandlerTests.test_basic_auth.<locals>.<listcomp>)r�rZcheck_warnings�UserWarning)
rrZrealm2�basicZbasic2Zother_no_realm�digestZ	realm_strrOZ
challengesr&r&r'�test_basic_auth�s<


��*��zHandlerTests.test_basic_authc
Csvt�}tj�tdd��}|�|�t�}tj�|�}d}tdd|�}|�|�|�|�|�	||d|||dd�dS)Nr�r��
ACME Networksi�z(Proxy-Authenticate: Basic realm="%s"

r�z&http://acme.example.com:3128/protected)
rr,rr�r�r�rZProxyBasicAuthHandlerr�r�)rr�r�r�r�rr�r&r&r'�test_proxy_basic_auths 
�


�z"HandlerTests.test_proxy_basic_authc

Cs�Gdd�dt�}Gdd�dtjj�}Gdd�dtjj�}|�}t�}||�}||�}d}tdd	|�}	|�|�|�|�|�|	�|�||d
||	|dd�|�	|j
dd
gd�dS)Nc@seZdZdd�Zdd�ZdS)zQHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirectorcSst�|�g|_dSr�)rr��recordedr�r&r&r'r�5s
zZHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.__init__cSs|j�|�dSr�)rr�)rr�r&r&r'�record9szXHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.recordN)rHrrIr�rr&r&r&r'�RecordingOpenerDirector4src@seZdZdd�ZdS)zOHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandlerc_s,|j�d�tjjj|g|�Ri|��dS)Nr�)r�rr,r�HTTPDigestAuthHandler�http_error_401�rr�r�r&r&r'r=s��z^HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandler.http_error_401N�rHrrIrr&r&r&r'�TestDigestAuthHandler<sr
c@seZdZdd�ZdS)zNHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandlerc_s,|j�d�tjjj|g|�Ri|��dS)Nr�)r�rr,rrrrr&r&r'rCs��z]HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandler.http_error_401Nr	r&r&r&r'�TestBasicAuthHandlerBsrrr��&WWW-Authenticate: Basic realm="%s"

r�r�r�r�r�)rr,rrrrr�r�r�rr)
rrr
rr�r�Zdigest_handlerZ
basic_handlerrr�r&r&r'�#test_basic_and_digest_auth_handlers+s(	�



�z0HandlerTests.test_basic_and_digest_auth_handlerscCsDt�}tj�d�}tdd�}|�|�|�|�|�t|jd�dS)Nr�zWWW-Authenticate: Kerberos

r�)	rr,rrr�r�r.r/r�)rr�Zdigest_auth_handlerr�r&r&r'�$test_unsupported_auth_digest_handler]s�

z1HandlerTests.test_unsupported_auth_digest_handlercCsDt�}tj�d�}tdd�}|�|�|�|�|�t|jd�dS)Nr�zWWW-Authenticate: NTLM

r�)	rr,rrr�r�r.r/r�)rr�Zbasic_auth_handlerr�r&r&r'�#test_unsupported_auth_basic_handlergs�

z0HandlerTests.test_unsupported_auth_basic_handlerc	CsHddl}	d\}
}|�|||
|�|�||j�|�||j�|�|
|j�|�||j�|�|�|�|j|�|�|j	|�|�t
|j�d�|�|jd�
|��td|
|fd�}d|	�|�����}
|�|jd�|�|
�|�|jdj||
�d|_|_|��|�|�|�t
|j�d�|�|jd�
|��dS)Nr�ZwileZcoyoter�z%s:%s�asciizBasic r�)�base64rrrrrPrr`r�rrr�r�rXrU�bytesZencodebytesr��decoderZr[r�)rr�r�Zauth_headerrr�r��request_urlZ
protected_urlrrr`ZuserpassZauth_hdr_valuer&r&r'r�qs6
���
zHandlerTests._test_basic_authcCs�d\}}d}td�}t�}t|�}|jd|||dd�|�|�|��|�|�|d��|�|�|d��t�}|�|�|�|�|�	|�|�|j
�dS)Nrr�r�T)�is_authenticatedz/nestedZplain)r�rrrrrTrrXrr�r�r�)rrr`rr��pwd_manager�auth_prior_handlerr�r&r&r'�test_basic_prior_auth_auto_send�s 
�


z,HandlerTests.test_basic_prior_auth_auto_sendc
Cs�d\}}d}d}t�}t|�}|�||||�|�|�}|�|�t�}|�|�tddd�}	|�|	�|�|�|�|�}|�	|�t
d�}	|�|	j�t�}|�|�|�|	�|�|�|�	|	j�dS)Nrr�ZACMEr�rr�)rrrrrrXrr�r�r�rTr�r�)
rrr`rrrrZis_authr�r�r&r&r'�.test_basic_prior_auth_send_after_first_success�s0


�






z;HandlerTests.test_basic_prior_auth_send_after_first_successc	Cs�dD]�\}}d�|�}t�|��|�}tj��}td�}d|_|�	||��}|�
�Wd�n1sj0Y|�|jj
d�|��qdS)z=Test the connection is cleaned up when the response is closed))zConnection: close�data)zTransfer-Encoding: chunkeds4
data
0

)zContent-Length: 4rzHTTP/1.1 200 OK
{}

�
http://dummy/NzConnection not closed with {!r})�formatrr�r!r,rr�rr�r�r6rT�fakesock�closed)rZtransferr��headerr�rr\Zrespr&r&r'�test_http_closed�s

&
�zHandlerTests.test_http_closedcCspt�d�}tj��}td�}d|_|�tj	j
��|�||�Wd�n1sR0Y|�|j
jd�dS)z;Test the connection is cleaned up after an invalid responserUrNzConnection not closed)rr�r,rr�rr�r.r�r�Z
BadStatusLiner�rTrr)rr�rr\r&r&r'�test_invalid_closed�s

*z HandlerTests.test_invalid_closedN)2rHrrIr>rMr^rkrmrwrzr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r#Z
skipUnlessrrr�rp�platformr�r�rrr
rrr�rrr!r"r&r&r&r'r&�sV@\B
J
	#

!-2

%(r&c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	MiscTestscs"|�t�fdd�|jD���dS)Nc3s|]}|j�kVqdSr�)r�)r�r=��
handler_classr&r'�	<genexpr>�s�z/MiscTests.opener_has_handler.<locals>.<genexpr>)rT�anyr�)rr�r&r&r%r'�opener_has_handler�s�zMiscTests.opener_has_handlercCs(Gdd�dtjj�}Gdd�dtjj�}Gdd�dtjj�}tjj}|||�}|�||�|�||�|||��}|�||�|�||�||�}|�||�|�}|�|tjj�|tjj�}|�|tjj�|tj���}|�|tjj�Gdd�dtjj�}|||�}|�||�|�||�dS)	Nc@seZdZdS)z2MiscTests.test_build_opener.<locals>.MyHTTPHandlerNr�r&r&r&r'�
MyHTTPHandler�sr*c@seZdZdd�ZdS)z/MiscTests.test_build_opener.<locals>.FooHandlercSsdSr�r&r�r&r&r'�foo_opensz8MiscTests.test_build_opener.<locals>.FooHandler.foo_openN)rHrrIr+r&r&r&r'�
FooHandler�sr,c@seZdZdd�ZdS)z/MiscTests.test_build_opener.<locals>.BarHandlercSsdSr�r&r�r&r&r'�bar_opensz8MiscTests.test_build_opener.<locals>.BarHandler.bar_openN)rHrrIr-r&r&r&r'�
BarHandlersr.c@seZdZdS)z7MiscTests.test_build_opener.<locals>.MyOtherHTTPHandlerNr�r&r&r&r'�MyOtherHTTPHandler sr/)r,rr��BaseHandlerr�r))rr*r,r.r�r
r/r&r&r'�test_build_opener�s,

zMiscTests.test_build_openercCs�d}d}}}d}tj�|||||�}|�t|d��|�|jd�|�t|d��|�|jd�d|j|j	f}|�t
|�|�d|j|j	f}|�t|�|�dS)z�
        Issue 13211 reveals that HTTPError didn't implement the URLError
        interface even though HTTPError is a subclass of URLError.
        zsomething bad happenedNzContent-Length: 42rBrOzHTTP Error %s: %sz<HTTPError %s: %r>)r,rr�rTr�rrBrOr�r�rEr�)rr�rPr�r�r\rFZexpected_errmsgr&r&r'�test_HTTPError_interface'sz"MiscTests.test_HTTPError_interfacecCs:gd�}|D]\}}|�t|�|�q|�ttd�fdS)N)�r�)NNNr��r�)NNNr�r3r4)zjoe:password@proxy.example.com)Nr_r`r�)z#joe:password@proxy.example.com:3128)Nr_r`r�)zhttp://proxy.example.com/)r�NNr�)zhttp://proxy.example.com:3128/)r�NNr�)z&http://joe:password@proxy.example.com/�r�r_r`r�)z*http://joe:password@proxy.example.com:3128)r�r_r`r�)z1ftp://joe:password@proxy.example.com/rubbish:3128)r@r_r`r�)z%http://joe:password@proxy.example.comr5)z&http://user/name:password@localhost:22)r��	user/namer`�localhost:22)z&http://username:pass/word@localhost:22)r��username�	pass/wordr7)z'http://user/name:pass/word@localhost:22)r�r6r9r7zfile:/ftp.example.com)rr	r.r/)rZparse_proxy_test_casesZtcrr&r&r'�test_parse_proxy9s'zMiscTests.test_parse_proxycCsPt�}|�t��}|�d�Wd�n1s00Y|�t|j�d�dS)N�invalidz5Unsupported digest authentication algorithm 'invalid')rr.r/Zget_algorithm_implsrrE�	exception)rr�excr&r&r'�test_unsupported_algorithmfs(�z$MiscTests.test_unsupported_algorithmN)rHrrIr)r1r2r:r>r&r&r&r'r$�s
,-r$c@s�eZdZGdd�de�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS) �RequestTestsc@seZdZdZdS)zRequestTests.PutRequest�PUTN)rHrrIr�r&r&r&r'�
PutRequestqsrAcCsLtd�|_tddddid�|_tddd�|_|�d�|_|jddd�|_dS)	N�http://www.python.org/~jeremy/r�zX-Testr�rN�HEAD)r�rO)rr<�post�headrA�put�
force_postr�r&r&r'�setUpts
��zRequestTests.setUpcCs^|�d|j���|�d|j���|�d|j���|�d|j���|�d|j���dS)NrOrNrCr@)rrDr�r<rErFrGr�r&r&r'�test_method~s
zRequestTests.test_methodcCsL|�|jj�|�d|j���d|j_|�|jj�|�d|j���dS)NrNrorO)rXr<r�rr�rTr�r&r&r'�	test_data�s
zRequestTests.test_datacCsN|�d|jj�|j�dd�|�d|jjd�d|j_|�d|jj�dS)Nr9�*ro)rZr<r[r[rr�r�r&r&r'�.test_setting_data_should_remove_content_length�s
z;RequestTests.test_setting_data_should_remove_content_lengthcCsT|�d|jj�d|j_|j�dd�|�d|jjd�|j`|�d|jj�dS)Nr9rhr|)rZr<r[r�r[rr�r&r&r'�/test_deleting_data_should_remove_content_length�sz<RequestTests.test_deleting_data_should_remove_content_lengthcCs|�d|j���dS)NrB)rr<r�r�r&r&r'�test_get_full_url�s�zRequestTests.test_get_full_urlcCs*|�d|jj�td�}|�d|j�dS)Nz	/~jeremy/zhttp://www.python.org/r))rr<r�rr�r&r&r'�
test_selector�szRequestTests.test_selectorcCs|�d|jj�dS)Nr�)rr<rKr�r&r&r'�
test_get_type�szRequestTests.test_get_typecCs|�d|jj�dS)Nr�)rr<r�r�r&r&r'�
test_get_host�szRequestTests.test_get_hostcCstd�}|�d|j�dS)Nzhttp://www.%70ython.org/r��rrr�r�r&r&r'�test_get_host_unquote�sz"RequestTests.test_get_host_unquotecCsR|�|j���|j�dd�|�|j���|�d|jj�|�d|jj�dS)Nr�r�r�)rXr<Z	has_proxyr�rTrr�r�r�r&r&r'r��s
zRequestTests.test_proxycCstd�}|�d|j�dS)Nz<URL:http://www.python.org>r�rRr�r&r&r'�test_wrapped_url�szRequestTests.test_wrapped_urlcCsLtd�}|�d|j�td�}|�d|j�d}t|�}|�|��|�dS)N�-http://www.python.org/?qs=query#fragment=truez
/?qs=queryzhttp://www.python.org/#fun=truer)�.http://docs.python.org/library/urllib2.html#OK)rrr�r�)rr\rPr&r&r'�test_url_fragment�szRequestTests.test_url_fragmentcCs0gd�}|D]}t|�}|�|��|j�qdS)N)zhttp://docs.python.orgrVrU)rrr�r�)rrLrPr\r&r&r'�test_url_fullurl_get_full_url�sz*RequestTests.test_url_fullurl_get_full_urlN)rHrrIrrArHrIrJrLrMrNrOrPrQrSr�rTrWrXr&r&r&r'r?ps

r?�__main__);r#r�rZtest.supportrrrr�r�rrprfrrZurllib.requestr,rrrrr	r
rr�urllib.parser
rZhttp.clientr�ZTestCaserrJr�r�r�r�r�r�r�r��IOBaser�r�r�r�r�rr0r�r�r�r�rrr%r&r$r?rH�mainr&r&r&r'�<module>sb(4<

-6"
3{a


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists