Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_urllib2.cpython-310.pyc
o

�9j�6�@s4ddlZddlmZddlmZddlmZddlmZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZddlmZddlZddlZGd	d
�d
ej�ZGdd�dej�ZGd
d�d�Z Gdd�d�Z!Gdd�de"�Z#Gdd�de	j$�Z%Gdd�d�Z&Gdd�d�Z'Gdd�de	j(�Z)Gdd�d�Z*Gdd�d�Z+dd �Z,d!d"�Z-Gd#d$�d$ej.j/�Z0Gd%d&�d&ej.j1�Z2Gd'd(�d(ej.j/�Z3Gd)d*�d*�Z4Gd+d,�d,ej�Z5d-d.�Z6Gd/d0�d0ej�Z7Gd1d2�d2ej�Z8Gd3d4�d4ej�Z9e:d5k�re�;�dSdS)6�N)�support)�	os_helper)�
socket_helper)�warnings_helper)�test_urllib)�Request�OpenerDirector�HTTPBasicAuthHandler�HTTPPasswordMgrWithPriorAuth�_parse_proxy�_proxy_bypass_macosx_sysconf�AbstractDigestAuthHandler)�urlparsec@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TrivialTestsc
Cs�dD]I}i}td||�|d=|dkr2tjdkr2|�d�|�d�}}|�|jd�|�|jd�|��D]\}}|�|jd	|d
|||jf�q6qdS)N)�request�response�parse�error�robotparserzfrom urllib.%s import *�__builtins__r�nt�url2pathname�pathname2url�
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/lib/python3.10/test/test_urllib2.py�test___all__#s 
����zTrivialTests.test___all__cCs�|�tjj�|�ttjjd�tj�	tjj
��tjd�}tj
dkr'd|}nd|}tj�|��
}|��Wd�dS1sAwYdS)Nz	bogus url�/rz
file:///%s�	file://%s)�
addCleanup�urllibr�
urlcleanup�assertRaises�
ValueError�urlopenr�path�abspath�__file__�replace�sepr�read)r"�fname�file_url�fr)r)r*�test_trivial2s


"�zTrivialTests.test_trivialcCsRdgd�fdddgfdgd�fdgd	�fg}|D]\}}|�tj�|�|�qdS)
Nza,b,c)�a�b�czpath"o,l"og"i"cal, examplezpath"o,l"og"i"cal�exampleza, b, "c", "d", "e,f", g, h)r>r?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/r�parse_http_list)r"�tests�string�listr)r)r*�test_parse_http_listEs

����z!TrivialTests.test_parse_http_listcCs"tj�d�}|�|jt|��dS)N�reason)r/r�URLError�assertInrI�str)r"�errr)r)r*�test_URLError_reasonstrPsz$TrivialTests.test_URLError_reasonstrN)�__name__r �__qualname__r+r=rHrNr)r)r)r*r!s
rc@r)
�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)rrrV)r"�urlr)r)r*�test_request_headers_dictWs
������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
        rRrSrTrU)rSrTzFoo-Bar�baz)zFoo-barrYz	Not-there�defaultzUnredirected-spam�EggsN)r�
assertTrue�
has_headerr�header_items�
add_header�sorted�assertFalse�assertIsNone�
get_header�
remove_header�add_unredirected_header)r"rW�reqr)r)r*�test_request_headers_methodsls"�

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)rirjrRzhttp://example.com/spamzhttp://example.com/spam/spamzhttp://example.com/foo�foozhttp://example.com/bar�bar�ninizhttp://example.com/foo/bar�foobar�nibar)rrrk)rsrtzhttp://example.com/foo/zhttp://example.com/foo/bazzhttp://example.com/foobar�NNzhttp://example.com/baz/rY�nininizhttp://example.com/baz)rYrxzhttp://example.com/baz/barr?�firstrT�second�spam)rzr{r>�1)r|r>zhttp://a.example.com/z
c.example.comzc.example.com:3128)rlr@)rmrn)rorp�r/r�HTTPPasswordMgr�add_password�find_user_passwordr�r"�mgr�add�find_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.
        r<zhttp://g.example.com:80�10�jrBzhttp://h.example.com�11r'rCzi.example.com:80�12�l�iz
j.example.com�13�mzg.example.com:100rwzg.example.com:80)r�r�z
g.example.comzhttp://g.example.com:100zhttp://g.example.comz
h.example.com)r�r'zh.example.com:80zhttp://h.example.com:80z
i.example.com)r�r�zhttp://i.example.com:80)r�r�zj.example.com:80zhttp://j.example.comzhttp://j.example.com:80Nr}r�r)r)r*�"test_password_manager_default_port�sZ
�����������z3RequestHdrsTests.test_password_manager_default_portN)rOr rPrXrgr�r�r)r)r)r*rQUs
$VrQc@s(eZdZgZdejfdd�Zdd�ZdS)�
MockOpenerNcCs||||_|_|_dS�N)rf�data�timeout)r"rfr�r�r)r)r*�openszMockOpener.opencGs|||_|_dSr�)�proto�args)r"r�r�r)r)r*r�zMockOpener.error)rOr rP�
addheaders�socket�_GLOBAL_DEFAULT_TIMEOUTr�rr)r)r)r*r�sr�c@s(eZdZddd�Zddd�Zdd�ZdS)	�MockFileNcC�dSr�r)�r"�countr)r)r*r9�z
MockFile.readcCr�r�r)r�r)r)r*�readliner�zMockFile.readlinecCr�r�r)�r"r)r)r*�close!r�zMockFile.closer�)rOr rPr9r�r�r)r)r)r*r�s

r�c@�eZdZdd�ZdS)�MockHeaderscCst|���Sr�)rG�values)r"rr)r)r*�
getheaders&szMockHeaders.getheadersN)rOr rPr�r)r)r)r*r�%�r�c@s&eZdZddd�Zdd�Zdd�ZdS)	�MockResponseNcCs.tj�||�||||f\|_|_|_|_dSr�)�io�StringIO�__init__�code�msgrVrW)r"r�r�rVr�rWr)r)r*r�+s zMockResponse.__init__cC�|jSr�rUr�r)r)r*�info/�zMockResponse.infocCr�r��rWr�r)r)r*�geturl2r�zMockResponse.geturlr�)rOr rPr�r�r�r)r)r)r*r�*s
r�c@�eZdZdd�Zdd�ZdS)�
MockCookieJarcC�
||_dSr�)�ach_req)r"rr)r)r*�add_cookie_header7�
zMockCookieJar.add_cookie_headercCs|||_|_dSr�)�ec_req�ec_r)r"rrr)r)r*�extract_cookies:r�zMockCookieJar.extract_cookiesN)rOr rPr�r�r)r)r)r*r�6sr�c@r�)�
FakeMethodcCs||_||_||_dSr�)�	meth_name�handle�action)r"r�r�r�r)r)r*r�?s
zFakeMethod.__init__cGs|j|j|jg|�R�Sr�)r�r�r�)r"r�r)r)r*�__call__DszFakeMethod.__call__N)rOr rPr�r�r)r)r)r*r�>sr�c@r)
�MockHTTPResponsecCs"||_||_||_||_d|_dS)N��)�fpr��statusrIr�)r"r�r�r�rIr)r)r*r�Is

zMockHTTPResponse.__init__cCsdS)N�r)r�r)r)r*r9Pr�zMockHTTPResponse.readcCsiSr�r)r�r)r)r*r�Sr�zMockHTTPResponse.infocCr�r�r�r�r)r)r*r�Vr�zMockHTTPResponse.geturlN)rOr rPr�r9r�r�r)r)r)r*r�Hs
r�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�[s
zMockHTTPClass.__init__cCs||_||_|Sr�)�hostr�)r"r�r�r)r)r*r�cszMockHTTPClass.__call__cCr�r�)r�)r"r�r)r)r*�set_debuglevelhr�zMockHTTPClass.set_debuglevelNcCs(||_||_|r
||_dS|j��dSr�)�_tunnel_host�_tunnel_portr��clear)r"r��portrVr)r)r*�
set_tunnelks

zMockHTTPClass.set_tunnelF)�encode_chunkedcCsP||_||_|dur|j|��7_|j��|r||_||_|jr&t��dSr�)	�method�selectorr�r!�sortr�r�r��OSError)r"r�rW�bodyrVr�r)r)r*rss
�zMockHTTPClass.requestcCstt�idd�S)Nr��OK)r�r�r�r)r)r*�getresponse��zMockHTTPClass.getresponsecCr�r�r)r�r)r)r*r��r�zMockHTTPClass.closerw)rOr rPr�r�r�r�r�r�rr�r�r)r)r)r*r�Zs
�
r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�MockHandler��cCs|�|�dSr�)�_define_methods)r"�methodsr)r)r*r���zMockHandler.__init__cCsJ|D] }t|�dkr|\}}n|d}}t|||j�}t|j||�qdS)N�)�lenr�r��setattr�	__class__)r"r��specrr��methr)r)r*r��s

�zMockHandler._define_methodscOs�|jj�||||f�|durdS|dkr|S|dkr$tddid�}|S|dkr,td�S|�d�r`||�d	�d
d�}zt|�}Wn	tyKYnwtddid�}|j�	d|d||di�S|d
krjt
j	�d��J�)N�return self�return responser�r�r��return requestzhttp://blah/r� ��httpr�raiserT)�parent�calls�appendr�r�
startswith�rfind�intr2rr/rJ)r"�fn_namer�r��kwds�resr�r)r)r*r��s,
�zMockHandler.handlecCr�r�r)r�r)r)r*r��r�zMockHandler.closecCs||_g|j_dSr�)r�r�)r"r�r)r)r*�
add_parent�szMockHandler.add_parentcCst|d�sdS|j|jkS)N�
handler_orderT)�hasattrr�)r"�otherr)r)r*�__lt__�s
zMockHandler.__lt__N)
rOr rPr�r�r�r�r�r�r�r)r)r)r*r��s	r�cCsbg}d}|D](}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@�eZdZdS)z6add_ordered_mock_handlers.<locals>.MockHandlerSubclassN�rOr rPr)r)r)r*�MockHandlerSubclass��r�r�)r�r�r�r��add_handler)�opener�	meth_spec�handlersr��methsr�rCr)r)r*�add_ordered_mock_handlers�s

rcGst�}|D]}|�|�q|Sr�)rr�)�handler_instancesrrCr)r)r*�build_test_opener�src@�$eZdZdd�Zdd�Zdd�ZdS)�MockHTTPHandlercCs||_||_|��dSr�)r�rV�reset)r"r�rVr)r)r*r���zMockHTTPHandler.__init__cCsd|_g|_dS)Nr)�_count�requestsr�r)r)r*r	��
zMockHTTPHandler.resetcCs�ddl}ddl}|j�|�|��|jdkr6|jd|_tjj|j	}|�
|j�}|j�
d|t�|j	||�S||_|�
d�}tdd|d|���S)Nrr�r��

r�r�r�)�email�copyrr��deepcopyrr��client�	responsesr��message_from_stringrVr�rr�rfr��get_full_url)r"rfrrrr�r)r)r*�	http_open�s
�
zMockHTTPHandler.http_openN�rOr rPr�r	rr)r)r)r*r�src@seZdZddd�Zdd�ZdS)�MockHTTPSHandlerrcCstjjj||d�t�|_dS)N��
debuglevel)r/r�AbstractHTTPHandlerr�r��httpconn)r"rr)r)r*r�szMockHTTPSHandler.__init__cCs|�|j|�Sr�)�do_openr�r"rfr)r)r*�
https_open
r�zMockHTTPSHandler.https_openN)r)rOr rPr�rr)r)r)r*rs
rc@r)�MockHTTPHandlerCheckAuthcCs||_d|_dS�NF)r��has_auth_header)r"r�r)r)r*r�r
z!MockHTTPHandlerCheckAuth.__init__cCs
d|_dSr!)r"r�r)r)r*r	r�zMockHTTPHandlerCheckAuth.resetcCs6|�d�rd|_tjj|j}t|j|t�d|���S)N�
AuthorizationTr�)	r]r"r�rrr�r�r�r)r"rfrr)r)r*rs
z"MockHTTPHandlerCheckAuth.http_openNrr)r)r)r*r sr c@r�)�MockPasswordManagercCs||_||_||_||_dSr�)�realmrW�userrj)r"r%�urir&rjr)r)r*r"s
z MockPasswordManager.add_passwordcCs||_||_|j|jfSr�)�target_realm�
target_urlr&rj)r"r%�authurir)r)r*r�(r
z&MockPasswordManager.find_user_passwordN)rOr rPrr�r)r)r)r*r$!sr$c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�OpenerDirectorTestscCs(Gdd�dt�}|�tt�j|��dS)Nc@r�)z<OpenerDirectorTests.test_add_non_handler.<locals>.NonHandlerNr�r)r)r)r*�
NonHandler1r�r,)�objectr1�	TypeErrorrr�)r"r,r)r)r*�test_add_non_handler0s
�z(OpenerDirectorTests.test_add_non_handlercCs\ddlm}t�}ddgdgg}t||�|�tj���dD]}|�||j	|d�qdS)Nr)rJ)rr�)�
proxy_openr�)�redirect_requestr�)�do�proxy�redirectz://example.com/)
�urllib.errorrJrrr�r/r�UnknownHandlerr1r�)r"rJ�or�schemer)r)r*�test_badly_named_methods6s	�
�z,OpenerDirectorTests.test_badly_named_methodsc
Cs�t�}gd�dgdgdgg}t||�}td�}|�|�}|�||d�|ddf|ddfg}t||j�D]\}}|\}	}
}}|�|	|
f|�|�||f�q6dS)N)r�ftp_open�http_error_302r:�rr�rhr�rr)rrrr�r�zipr�)
r"r7rrrf�rr��expected�got�handlerrr�r�r)r)r*�test_handledKs �

�z OpenerDirectorTests.test_handledcCs�t�}g}dgdfdgdffD]\}}Gdd�dt�}||�}||_|�|�|�|�q|�d�|�|jdd|d�|�|jdd|d�dS)	Nr<r�rrc@r�)zCOpenerDirectorTests.test_handler_order.<locals>.MockHandlerSubclassNr�r)r)r)r*r�jr�r�rhr�)rr�r�r�r�r�rr�)r"r7rrr�r�rCr)r)r*�test_handler_orderes�

z&OpenerDirectorTests.test_handler_ordercCsZt�}dgdgg}t||�}td�}|�tjj|j|�|�|j	|dd|fifg�dS)N)rr�r<rhrr)
rrrr1r/rrJr�rr�)r"r7rrrfr)r)r*�
test_raisews�
"zOpenerDirectorTests.test_raisecCs�t�}dgddggd�dgg}t||�}td�}|�|�t|j�dks&J�|dd|ff|dd|tjd	d
iffg}t||j�D]\}}|\}}	}
|�	||	f|dd��|�	|
|d�qAdS)N)rz	error 302)�http_error_400r�r))r;r��http_error_303�
http_errorr;rhr�r�.r�)
rrrr�r�r�r�	ALWAYS_EQr=r)r"r7rrrfr�r?r@rA�method_namer�r)r)r*�test_http_error�s(�

��
�z#OpenerDirectorTests.test_http_errorcCst�}ddgddgg}t||�}td�}|�|�|ddf|ddf|ddf|ddfg}t|j�D]O\}\}}}	}
|dkr[|�||f||�|�t|	�d�|�|	dt�q4|�||f||�|�t|	�d�|�|	dt�|	ddur�|�|	dt	�q4dS)	N)�http_requestr�)�
http_responser�rhrrLr�rMr�)
rrrr��	enumerater�rr��assertIsInstancer�)r"r7rrrfr�r�rArr�r�r)r)r*�test_processors�s4���

���z#OpenerDirectorTests.test_processorsN)
rOr rPr/r9rBrCrDrKrPr)r)r)r*r+.s
r+cCsXz|�d�Wntyt�d��wtj�|�}tjdkr*|�	d�r*|dd�}|S)Nzutf-8zpath is not encodable to utf8rz///r�)
�encode�UnicodeEncodeError�unittest�SkipTestr/rrrrr�)r4�urlpathr)r)r*�sanepathname2url�s
�rVc@s^eZdZdd�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#d=d>�Z$d?d@�Z%dAdB�Z&dCdD�Z'dEdF�Z(dGdH�Z)dIdJ�Z*dKdL�Z+dMdN�Z,dOdP�Z-dQdR�Z.dSS)T�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]f\	}}}}}	}
}}}
t|�}d|_|�	|�}|�
|j|�|�
|j|	�|�
|j
t�|��|�
|j|�|�
|j|�|�
|jj|�|�
|jj|
�|��}|�
|�d�|
�|�
t|d�t|��qndS)Nc@r)z-HandlerTests.test_ftp.<locals>.MockFTPWrappercSr�r��r��r"r�r)r)r*r��r�z6HandlerTests.test_ftp.<locals>.MockFTPWrapper.__init__cSs$|||_|_t�|j�t|j�fSr�)�filename�filetyper�r�r�r�)r"rZr[r)r)r*�retrfile�sz6HandlerTests.test_ftp.<locals>.MockFTPWrapper.retrfilecSr�r�r)r�r)r)r*r��r�z3HandlerTests.test_ftp.<locals>.MockFTPWrapper.closeN)rOr rPr�r\r�r)r)r)r*�MockFTPWrapper�sr]cs&eZdZdd�Zejf�fdd�	ZdS)z-HandlerTests.test_ftp.<locals>.NullFTPHandlercSr�r�rXrYr)r)r*r��r�z6HandlerTests.test_ftp.<locals>.NullFTPHandler.__init__cs4|||_|_|||_|_||_�|j�|_|jSr�)r&�passwdr�r��dirsr��
ftpwrapper)r"r&r^r�r�r_r��r]r)r*�connect_ftp�s
z9HandlerTests.test_ftp.<locals>.NullFTPHandler.connect_ftpN)rOr rPr�r�r�rbr)rar)r*�NullFTPHandler�s�rcrzrheum rhaponicumz ftp://localhost/foo/bar/baz.html�	localhostr��Irrrszbaz.htmlz	text/htmlz'ftp://parrot@localhost/foo/bar/baz.html�parrotz*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/r�
FTPHandler�ftplibr�r��FTP_PORTrr�r:rr&r^r�r��
gethostbynamer�r_r`rZr[r��getr�r�)r"rcrmr�rCrWr�r�r&r^�type_r_rZ�mimetyperfr>rVr)rar*�test_ftp�sZ
�
�
�
�

���
�zHandlerTests.test_ftpc
Cs�ddl}tj��}t�}|_tj}tt	j
�|��}d}d|d|dt�
d�|fg}z	t�
t���}WntjyAd}Ynw|rM|�d||f�|D]w}	t|d�}
zEz|
�|�W|
��n|
��w|�t|	��}z|��}|��}
|��}W|��n|��wt	�|�}|jj|jd	d
�}Wt	�|�nt	�|�w|�||�|�|
dd�|�|
d
d�|�|
d|�|�||	�qOd|dddt�
d�t	��|fdt	��|ffD]1}	z)t|d�}
z|
�|�W|
��n|
��w|� tj!j"|jt|	��Wt	�|�q�t	�|�wtj��}t�}|_dD]9\}	}t|	�}z|�|�Wntj!j"�y?|�#|�Ynw|�$|j%|�|�|j&d�|�|j&dk|��qdS)Nrs
hello, world
zfile://localhost%sr-zfile://%s%srdr��wbT)�usegmtrjz
text/plainrkr�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)'�email.utilsr/r�FileHandlerr�r�r�TESTFNrVrr4r5r�ro�gethostname�gaierrorr�r��writer��	file_openrr9r�r��stat�utils�
formatdate�st_mtime�remover�getcwdr1rrJra�assertIsrf�type)r"rrCr7ryrU�towrite�urls�	localaddrrWr<r>r�rV�respurl�stats�modifiedrvrfr)r)r*�	test_file
s�
��



�
��	


�
��zHandlerTests.test_filecCs`tj��}t�}|_d}dD]q\}}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�}|�|�}
|dur�|�!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�q�dS)Nrh))�GETN)�POSTsblah�Foors�Spam�eggsr�r�rqrr,))�
Connectionr�)r�rs�r�r�T�badpostr�)�Nr�rkrj�0z!application/x-www-form-urlencoded�HostrrrY)#r/rrr�r�rr�rer�rr9r�r�r�r�r�rp�__contains__rr�r�r�r�r�r�r�r1rrJr.�do_request_r�r��assertNotIn�unredirected_hdrs)r"rCr7rWr�r�rfr�r>�hdrs�newreqr)r)r*�	test_httpisf
�


�
�zHandlerTests.test_httpc	Cstj��}t�}|_tjddd�}|j}|��|�	t
j|�t|d��&}t
d|i�}|�|�}|�d�}|�|d�|�|�d��Wd�n1sNwYt|d��)}t
d|d	d
i�}|�|�}|�t|�d��d
�|�|�d��Wd�dS1s�wYdS)Nzw+bF)�mode�delete�rbrh�Transfer-encoding�chunkedrk�Content-Length�)r/rrr�r��tempfile�NamedTemporaryFilerr�r.r�unlinkr�rr�rcrrar]r�)	r"rCr7�file_obj�	file_pathr<rfr��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)Nrhr�r�rkr�r�)r/rrr�r�r��BytesIOrr�rrcrar]r�r�)r"rCr7r�rfr�rVr)r)r*�test_http_body_fileobj�s


z#HandlerTests.test_http_body_fileobjc	Cs�tj��}t�}|_tjddg}iddifD]F}tj|tj	d��4}t
d|j|�}|�|�}|sC|�
|�d�d�|�
|�d�d	�n|�
t|�d��d�Wd�n1sXwYqdS)
Nz-c�passr�r�)�stdoutrhrkr�r�)r/rrr�r��sys�
executable�
subprocess�Popen�PIPErr�r�rrcr�)r"rCr7�cmdrV�procrfr�r)r)r*�test_http_body_pipe�s&

������z HandlerTests.test_http_body_pipecCs�tj��}t�}|_dd�}iddifD].}td|�|�}|�|�}|s8|�|�d�d�|�|�d�d�q|�t	|�d��d�qdS)	Ncss�dVdS)Nsoner)r)r)r)r*�
iterable_body�s�
z;HandlerTests.test_http_body_iterable.<locals>.iterable_bodyr��rhrkr�r�)
r/rrr�r�rr�rrcr�)r"rCr7r�rVrfr�r)r)r*�test_http_body_iterable�s

��z$HandlerTests.test_http_body_iterablecCsHtj��}t�|_|�tdd��}|�|�d�d�|�	|�
d��dS)Nrhr)r�r�rk)r/rrr�r�r�rrrcrar])r"rCrfr)r)r*�test_http_body_empty_seqs

z%HandlerTests.test_http_body_empty_seqcCshtj��}t�}|_t�dgd��}iddifD]}td||�}|�|�}|�t	|�
d��d�qdS)Nre)r�r���r��rhrk)r/rrr�r��arrayrr�rr�rc)r"rCr7�iterable_arrayrVrfr�r)r)r*�test_http_body_array
s

�z!HandlerTests.test_http_body_arraycCs6t�}tdd�}|�|�|�d�|�|jd�dS)Nr�rzhttps://www.example.com)rrr�r�r�_debuglevel)r"r7rCr)r)r*�test_http_handler_debuglevels



z)HandlerTests.test_http_handler_debuglevelcCsztj��}t�|_d}gd�}|D])}t||�}|�|�}|�|jdd�|�	dd�|�|�}|�|jdd�qdS)Nr�)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.htmlr�rqzsomeproxy:3128)
r/rrr�r�rr�rr��	set_proxy)r"rCr��ds_urls�ds_url�ds_req�	np_ds_req�p_ds_reqr)r)r*�test_http_doubleslash!s



�z"HandlerTests.test_http_doubleslashcCshgd�}td�}|D]'}||_t|�}|�|��|�|�|jp!d|j�|�t|���j|j�q
dS)N)zhttp://example.com?foo=bar#bazz)http://example.com?foo=bar&spam=eggs#bashrRrRr�)r�full_urlrrr�fragment�query)r"r�r>rW�parsedr)r)r*�test_full_url_setter<s�z!HandlerTests.test_full_url_settercCs6td�}|`|�|j�|�|j�|�|jd�dS)N�http://www.example.comr�)rr�rbr�rr�)r"r>r)r)r*�test_full_url_deleterSs
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/rrr�r�rr�rr�r�)r"rC�	weird_urlrfr��url_without_pathr)r)r*�test_fixpath_in_weirdurlsZs


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)
Nrhr�r�r�r����Accepted��zPartial contenti�zBad gatewayr�)r/r�HTTPErrorProcessorr�r�rr�rMr�rar�rbrr�r�)r"rCr7rWrfr>�newrr)r)r*�test_errorsms(
zHandlerTests.test_errorscCs�t�}tj�|�}t�|_td�}tddid�}|�|�}|�	|j
|�|�	|j
|�|�|jd�|�
|j�|�||�}|�	|j|�|�	|j|�|�	||�dS)Nrhr�r�r�rq)r�r/r�HTTPCookieProcessorr�r�rr�rLr�r�r�origin_req_hostra�unverifiablerMr�r�)r"�cjrCrfr>r�r�r)r)r*�test_cookies�s
zHandlerTests.test_cookiesc
CsTd}d}tj��}t�}|_dD]�}dD]�}t|d|�}t||�}tj|_	|�
dd�|dur;|�
dtt|���|�
d	d
�z||t�|dtd|i��Wntjjyf|�|d
�|�|�Ynw|�|j��|�z|�|j��d�Wnty�|�|jj�Ynwdd�|jjD�}	|�d|	�|�d|	�|�|jjdd�|�d	|jj�|�d	|jj�qqt|�}tj|_	|fdd�}
t|dd�}d}tj|_	z	|
||d�|d}q�tjjy�|�|tjjj�Ynwt|dd�}d}tj|_	z	|
||d|�|d}�qtjj�y)|�|tjjj�YdSw)N�http://example.com/a.htmlzhttp://example.com/b.html)i-rHi/�3)Nz
blah
blah
z
http_error_%s�Nonsensezviking=withholdr�r�r{�Blah�locationr�r�cSsg|]}|���qSr))�lower)�.0�xr)r)r*�
<listcomp>�sz.HandlerTests.test_redirect.<locals>.<listcomp>zcontent-lengthzcontent-typec	Ss |�|t�ddtd|i��dS)NrHr�r�)r;r�r�)rCrfrWr)r)r*r4�s
�z,HandlerTests.test_redirect.<locals>.redirectrq)r�rr�rhzhttp://example.com/%d)r/r�HTTPRedirectHandlerr�r��getattrrr�r�r�r_rLr�rer�r�r�	HTTPErrorr�assertIsNotNonerfr�
get_method�AttributeErrorrar�rVr�r��max_repeats�max_redirections)r"�from_url�to_urlrCr7r�r�r�rfrVr4r�r)r)r*�
test_redirect�s~


�����!���
��zHandlerTests.test_redirectcCs�d}gd�}gd�}d}tj��}t�}|_t|�}tj|_|D]}|d|}	|�	tj
j|j|t
�ddtd|	i��q!|D]}|d|}
|�|t
�dd	td|
i��|�|j��|
�q?dS)
Nr�)r��httpsrv)�file�imap�ldapzexample.com/b.htmlz://rHzSecurity Loopholer��That's fine)r/rr�r�r�rr�r�r�r1rr�r;r�r�rrfr)r"r��
valid_schemes�invalid_schemes�schemeless_urlrCr7rfr8�invalid_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.htmlrHr�r�)r/rr�r�r�rr�r�r�r�urljoinr;r�r�rrfr)r"r��relative_urlrCr7rfrr)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=eggsrHz%Location: http://www.cracker.com/

�Cookie)�http.cookiejarr�test.test_http_cookiejarrrr/r�HTTPDefaultErrorHandlerr�r�rr�rarfr])	r"rrr��hh�hdeh�hrh�cpr7r)r)r*�test_cookie_redirects


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

rHz
Location: r�)
rr/rr
r�rr�rr��strip)r"�redirected_urlrrr
r7r�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��fakedata)�connr�rW�pos�kw��
real_classr"r�r)r*r'sz3HandlerTests.test_redirect_no_path.<locals>.requestzhttp://python.org/pathzhttp://python.org/path?query)r.r/rr0r�rrr�fakehttpr��iterr3rr�)r"�	response1rr�r)rr*�test_redirect_no_paths
z"HandlerTests.test_redirect_no_pathc
	Cs�Gdd�dtjj�}|�}tj�|�}d}|D]>\}}|�t|���+t�d|d�|_|�	d�}d|d}|j
}	|�|	�|�t|	��Wd�n1sPwYqdS)	Nc@r�)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)r"rf�resultr)r)r*r4s
�z>HandlerTests.test_redirect_encoding.<locals>.Handler.http_openN)rOr rPrr)r)r)r*�Handler3r�r#))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

rhsGET � )
r/r�HTTPHandler�build_opener�subTest�reprrrrr�r!r\r�)
r"r#rArrEr�r"rr?rr)r)r*�test_redirect_encoding0s(���
���z#HandlerTests.test_redirect_encodingcCs�d}t|d�t|d�fD]A}t�}tj�|�}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	|�|�|ddfgd	d
�|jD��qdS)N�proxy.example.com:3128�r�)�HTTP)rr�zhttp://acme.example.com/zacme.example.comrrcS�g|]}|dd��qS�rr�r)�r��tupr)r)r*r�c�z+HandlerTests.test_proxy.<locals>.<listcomp>)�dictrr/r�ProxyHandlerr�rrrr�r�r�)r"r%rnr7�phrrrfr)r)r*�
test_proxySs 
�

��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/rr4r3r�rrr�r��r"r7r5rfr)r)r*�test_proxy_no_proxyes



z HandlerTests.test_proxy_no_proxycCsfdtjd<t�}tj�tdd��}|�|�td�}|�	|j
d�|�|�|�	|j
d�tjd=dS)N�*r7r8r,r�r�r:r<r)r)r*�test_proxy_no_proxy_allts


z$HandlerTests.test_proxy_no_proxy_allcCs�t�}tj�tdd��}|�|�dgg}t||�}td�}|�|j	d�|�
|�|�|j	d�|�|ddfgdd	�|jD��dS)
Nr+�r�)rr��https://www.example.com/�www.example.comrrcSr.r/r)r0r)r)r*r��r2z1HandlerTests.test_proxy_https.<locals>.<listcomp>)rr/rr4r3r�rrrr�r�r�)r"r7r5rrrfr)r)r*�test_proxy_httpss
�

�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@rA�Proxy-Authorization�FooBar�
User-Agent�GrailrB)rDrE)rFrG�Proxy-authorization)rr/rr4r3r�rrr_rr�rbr�r�r�rr�rKr�rc)r"r7r5�
https_handlerrfr)r)r*�$test_proxy_https_proxy_authorization�s(


��z1HandlerTests.test_proxy_https_proxy_authorization�darwinzonly relevant for OSXcCs�dgd�d�}dD]
}|�t||�d|�q	dD]
}|�t||�d|�qdgd�}|�td	|��dd
dgd�}d}|�t||�d|�d
}|�t||�d|�dS)NF)�foo.barz	*.bar.com�	127.0.0.1z10.10z10.0/16)�exclude_simple�
exceptions)rLzwww.bar.comrMz	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.1�notinbypassz!expected bypass of %s to be FalseT�testz10.0.0.0/40z172.19.10.0/24z172.19.10.5z10.0.1.5)r\rra)r"�bypassr�r)r)r*�test_osx_proxy_bypass�s0���
���z"HandlerTests.test_osx_proxy_bypasscCs�|j||d��7t�}t�}tj�|�}d�|�d}td|�}|�|�|�|�|�	||d|||dd�Wd�dS1sAwYdS)N)r%rVz
r�r#�!http://acme.example.com/protected)
r(rr$r/rr	�joinrr��_test_basic_auth)r"rVr%r�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}|�||�qGt�dtf��d
|��g}|�||�Wd�n1stwY||g||g||gfD]}	dd�|	D�}|�||�q�dS)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��	challenger)r)r*r��s�z0HandlerTests.test_basic_auth.<locals>.<listcomp>)r[r�check_warnings�UserWarning)
r"r%�realm2�basic�basic2�other_no_realm�digest�	realm_strrV�
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"

rHz&http://acme.example.com:3128/protected)
rr/rr4r3r�r$�ProxyBasicAuthHandlerrrW)r"rr5rXrYr%rZr)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@r�)zQHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirectorcSst�|�g|_dSr�)rr��recordedr�r)r)r*r�s

zZHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.__init__cSs|j�|�dSr�)rmr�)r"r�r)r)r*�record"r�zXHandlerTests.test_basic_and_digest_auth_handlers.<locals>.RecordingOpenerDirector.recordN)rOr rPr�rnr)r)r)r*�RecordingOpenerDirectorsroc@r�)zOHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandlerc_�,|j�d�tjjj|g|�Ri|��dS)Nrf)r�rnr/r�HTTPDigestAuthHandler�http_error_401�r"r�r�r)r)r*rr&��
�z^HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestDigestAuthHandler.http_error_401N�rOr rPrrr)r)r)r*�TestDigestAuthHandler%r�rvc@r�)zNHandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandlerc_rp)Nrc)r�rnr/rr	rrrsr)r)r*rr,rtz]HandlerTests.test_basic_and_digest_auth_handlers.<locals>.TestBasicAuthHandler.http_error_401Nrur)r)r)r*�TestBasicAuthHandler+r�rwrjrT�&WWW-Authenticate: Basic realm="%s"

r#rUrfrcr�)rr/rrqr	r$rr�rWrrm)
r"rorvrwrrX�digest_handler�
basic_handlerr%rZr)r)r*�#test_basic_and_digest_auth_handlerss(	�



�z0HandlerTests.test_basic_and_digest_auth_handlerscC�Dt�}tj�d�}tdd�}|�|�|�|�|�t|jd�dS)NrTzWWW-Authenticate: Kerberos

r�)	rr/rrqrr�r1r2r�)r"r�digest_auth_handlerrZr)r)r*�$test_unsupported_auth_digest_handlerFs�

z1HandlerTests.test_unsupported_auth_digest_handlercCr|)NrTzWWW-Authenticate: NTLM

r�)	rr/rr	rr�r1r2r�)r"r�basic_auth_handlerrZr)r)r*�#test_unsupported_auth_basic_handlerPs�

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��wile�coyoter�z%s:%s�asciizBasic r�)�base64rrr%rWr&rjr�r(r)r�rrar]�bytes�encodebytesr�decodercr�r	)r"rrY�auth_headerr%rZrX�request_url�
protected_urlr�r&rj�userpass�auth_hdr_valuer)r)r*rWZs6
���
zHandlerTests._test_basic_authcCs�d\}}d}td�}t�}t|�}|jd|||dd�|�|�|��|�|�|d��|�|�|d��t�}|�|�|�|�|�	|�|�|j
�dS)Nr�rUr�T)�is_authenticatedz/nested�plain)r r
r	rr\r�rarr�r�r")r"r&rjr�rZ�pwd_manager�auth_prior_handlerrr)r)r*�test_basic_prior_auth_auto_sends 
�


z,HandlerTests.test_basic_prior_auth_auto_sendc
Cs�d\}}d}d}t�}t|�}|�||||�|�|�}|�|�t�}|�|�tddd�}	|�|	�|�|�|�|�}|�	|�t
d�}	|�|	j�t�}|�|�|�|	�|�|�|�	|	j�dS)Nr�rU�ACMErTrxr�)r
r	rr�rarr�rr�r\r r")
r"r&rjr�r%r�r��is_authrrZr)r)r*�.test_basic_prior_auth_send_after_first_success�s0


�






z;HandlerTests.test_basic_prior_auth_send_after_first_successc	Cs�dD]C\}}d�|�}t�|��|�}tj��}td�}d|_|�	||��}|�
�Wd�n1s5wY|�|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: 4r�zHTTP/1.1 200 OK
{}

�
http://dummy/NzConnection not closed with {!r})�formatrrrQr/rrrr�rr9r\�fakesock�closed)r"�transferr��headerrrArf�respr)r)r*�test_http_closed�s


�
��zHandlerTests.test_http_closedcCspt�d�}tj��}td�}d|_|�tj	j
��|�||�Wd�n1s)wY|�|j
jd�dS)z;Test the connection is cleaned up after an invalid responser�r�NzConnection not closed)rrr/rrrr�r1r�r�
BadStatusLinerr\r�r�)r"rrArfr)r)r*�test_invalid_closed�s

�z HandlerTests.test_invalid_closedN)/rOr rPrsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr*r6r=r?rCrJrS�
skipUnlessr��platformrSr[rirlr{r~r�rWr�r�r�r�r)r)r)r*rW�sT@\B
J
	#
!-2

%(rWc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	MiscTestscs"|�t�fdd�|jD���dS)Nc3s�|]}|j�kVqdSr�)r�)r�rC��
handler_classr)r*�	<genexpr>�s��z/MiscTests.opener_has_handler.<locals>.<genexpr>)r\�anyr)r"rr�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@r�)z2MiscTests.test_build_opener.<locals>.MyHTTPHandlerNr�r)r)r)r*�
MyHTTPHandler�r�r�c@r�)z/MiscTests.test_build_opener.<locals>.FooHandlercSr�r�r)r�r)r)r*�foo_open�r�z8MiscTests.test_build_opener.<locals>.FooHandler.foo_openN)rOr rPr�r)r)r)r*�
FooHandler�r�r�c@r�)z/MiscTests.test_build_opener.<locals>.BarHandlercSr�r�r)r�r)r)r*�bar_open�r�z8MiscTests.test_build_opener.<locals>.BarHandler.bar_openN)rOr rPr�r)r)r)r*�
BarHandler�r�r�c@r�)z7MiscTests.test_build_opener.<locals>.MyOtherHTTPHandlerNr�r)r)r)r*�MyOtherHTTPHandler	r�r�)r/rr&�BaseHandlerr'r�)r"r�r�r�r'r7r�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: 42rIrVzHTTP Error %s: %sz<HTTPError %s: %r>)r/rr�r\r�rrIrVr�r�rLr))r"r�rWr�r�r�rM�expected_errmsgr)r)r*�test_HTTPError_interfacesz"MiscTests.test_HTTPError_interfacecCs>tj�ddddd�}|�t|dd�d�|�|j��t�dS)NrWi�zMETHOD NOT ALLOWED�	__notes__r))	r/rr�rr�rOr�r9r�)r"r�r)r)r*�
test_gh_98778"szMiscTests.test_gh_98778cCs:gd�}|D]\}}|�t|�|�q|�ttd�fdS)N)�r8)NNNr8�r+)NNNr+r�r�)zjoe:password@proxy.example.com)Nrirjr8)z#joe:password@proxy.example.com:3128)Nrirjr+)zhttp://proxy.example.com/)r�NNr8)zhttp://proxy.example.com:3128/)r�NNr+)z&http://joe:password@proxy.example.com/�r�rirjr8)z*http://joe:password@proxy.example.com:3128)r�rirjr+)z1ftp://joe:password@proxy.example.com/rubbish:3128)rvrirjr8)z%http://joe:password@proxy.example.comr�)z&http://user/name:password@localhost:22)r��	user/namerj�localhost:22)z&http://username:pass/word@localhost:22)r��username�	pass/wordr�)z'http://user/name:pass/word@localhost:22)r�r�r�r�zfile:/ftp.example.com)rrr1r2)r"�parse_proxy_test_cases�tcr?r)r)r*�test_parse_proxy's'zMiscTests.test_parse_proxycCsPt�}|�t��
}|�d�Wd�n1swY|�t|j�d�dS)N�invalidz5Unsupported digest authentication algorithm 'invalid')r
r1r2�get_algorithm_implsrrL�	exception)r"rA�excr)r)r*�test_unsupported_algorithmTs��z$MiscTests.test_unsupported_algorithmN)	rOr rPr�r�r�r�r�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)rOr rPr�r)r)r)r*�
PutRequest_sr�cCsLtd�|_tddddid�|_tddd�|_|�d�|_|jddd�|_dS)	N�http://www.python.org/~jeremy/r�zX-TestrQrU�HEAD)r�r�)rrp�post�headr��put�
force_postr�r)r)r*�setUpbs
��zRequestTests.setUpcCs^|�d|j���|�d|j���|�d|j���|�d|j���|�d|j���dS)Nr�r�r�r�)rr�r�rpr�r�r�r�r)r)r*�test_methodls
zRequestTests.test_methodcCsL|�|jj�|�d|j���d|j_|�|jj�|�d|j���dS)Nr�r{r�)rarpr�rr�r\r�r)r)r*�	test_datass
zRequestTests.test_datacCsN|�d|jj�|j�dd�|�d|jjd�d|j_|�d|jj�dS)Nrk�*r{)r�rpr�rerr�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)Nrkrrr�)r�rpr�r�rerr�r)r)r*�/test_deleting_data_should_remove_content_length�sz<RequestTests.test_deleting_data_should_remove_content_lengthcCs|�d|j���dS)Nr�)rrprr�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,)rrpr�rrr)r)r*�
test_selector�szRequestTests.test_selectorcC�|�d|jj�dS)Nr�)rrpr�r�r)r)r*�
test_get_type��zRequestTests.test_get_typecCr�)Nr�)rrpr�r�r)r)r*�
test_get_host�r�zRequestTests.test_get_hostcC�td�}|�d|j�dS)Nzhttp://www.%70ython.org/r��rrr�rr)r)r*�test_get_host_unquote��z"RequestTests.test_get_host_unquotecCsR|�|j���|j�dd�|�|j���|�d|jj�|�d|jj�dS)Nr9r�r�)rarp�	has_proxyr�r\rr�r�r�r)r)r*r6�s
zRequestTests.test_proxycCr�)Nz<URL:http://www.python.org>r�r�rr)r)r*�test_wrapped_url�r�zRequestTests.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)r"rfrWr)r)r*�test_url_fragment�szRequestTests.test_url_fragmentcCs0gd�}|D]}t|�}|�|��|j�qdS)N)zhttp://docs.python.orgr�r�)rrrr�)r"r�rWrfr)r)r*�test_url_fullurl_get_full_url�s
�z*RequestTests.test_url_fullurl_get_full_urlN)rOr rPrr�r�r�r�r�r�r�r�r�r�r�r6r�r�r�r)r)r)r*r�^s 

r��__main__)<rSrQr�test.supportrrrrrr�r�r�r�r�r��urllib.requestr/rrr	r
rrr
�urllib.parserr5�http.clientr��TestCaserrQr�r�r3r�r�r�r�r��IOBaser�r�r�rrrr�rrrr r$r+rVrWr�r�rO�mainr)r)r)r*�<module>sl$4<

-6"

a�

Youez - 2016 - github.com/yon3zu
LinuXploit