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_localnet.cpython-39.pyc

a

��g�e�@srddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZzddlZWney�dZYn0ej�e�Zej�ed�Zej�ed�ZGdd�dejj�ZGdd	�d	ej�ZGd
d�d�ZGdd
�d
ejj�ZGdd�dejj�Z Gdd�de	j!�Z"ej#ddd�Gdd�de	j!��Z$dd�Z%Gdd�de	j!�Z&dd�Z'e(dk�rne	�)�dS)�N)�support)�hashlib_helperzkeycert.pemzkeycert2.pemc@s eZdZdZdd�Zdd�ZdS)�LoopbackHttpServerz^HTTP server w/ a few modifications that make it useful for
    loopback testing purposes.
    cCs"tjj�|||�|j�d�dS)Ng�������?)�http�server�
HTTPServer�__init__�socket�
settimeout)�selfZserver_addressZRequestHandlerClass�r�6/usr/local/lib/python3.9/test/test_urllib2_localnet.pyr!s

�zLoopbackHttpServer.__init__cCs |j��\}}|�d�||fS)zHTTPServer method, overridden.g$@)r	�acceptr
)r�requestZclient_addressrrr
�get_request*s
zLoopbackHttpServer.get_requestN)�__name__�
__module__�__qualname__�__doc__rrrrrr
rs	rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�LoopbackHttpServerThreadz2Stoppable thread that runs a loopback http server.cCs<tj�|�d|_t��|_d|_td|�|_|jj	|_
dS)NFzHTTP/1.0)z	127.0.0.1r)�	threading�Threadr�_stop_server�Event�readyZprotocol_versionr�httpdZserver_port�port�r�request_handlerrrr
r9s
�z!LoopbackHttpServerThread.__init__cCsd|_|��|j��dS)z.Stops the webserver if it's currently running.TN)r�joinrZserver_close�rrrr
�stopBszLoopbackHttpServerThread.stopcCs |j��|js|j��q
dS�N)r�setrr�handle_requestr rrr
�runJs
zLoopbackHttpServerThread.runN)rrrrrr!r%rrrr
r6s	rc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�DigestAuthHandlerz-Handler for performing digest authentication.cCs"d|_g|_i|_d|_d|_dS)Nrz
Test Realm�auth)�_request_num�_nonces�_users�_realm_name�_qopr rrr
rTs
zDigestAuthHandler.__init__cCs
||_dSr")r,)rZqoprrr
�set_qop[szDigestAuthHandler.set_qopcCst|t�sJ�||_dSr")�
isinstance�dictr*)rZusersrrr
�	set_users^szDigestAuthHandler.set_userscCs
||_dSr")r+)rZrealmrrr
�	set_realmbszDigestAuthHandler.set_realmcCs8|jd7_t�t|j��d����}|j�|�|S)N��ascii)r(�hashlib�md5�str�encode�	hexdigestr)�append)r�noncerrr
�_generate_nonceesz!DigestAuthHandler._generate_noncecCs�|�d�}||dd�}|�d�}i}|D]P}|�d�\}}|��}|ddkrl|ddkrl|dd�}n|��}|||<q,|S)N� r2�,�=r�"���)�find�split�strip)rZauth_strZfirst_space_index�parts�	auth_dict�part�name�valuerrr
�_create_auth_dictks


z#DigestAuthHandler._create_auth_dictcCs�i}|�|�||d<||d<||d<d|}t�|�d����}d|}t�|�d����}	||d<|	|d<d	|}
t�|
�d����}||d
kS)N�password�method�uriz#%(username)s:%(realm)s:%(password)sr3z%(method)s:%(uri)s�HA1�HA2z3%(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)s�response)�updater4r5r7r8)rrErJrKrLZ
final_dictZHA1_strrMZHA2_strrNZresponse_strrOrrr
�_validate_auth|s 
�z DigestAuthHandler._validate_authcCsN|�dd�|�dd�|�dd|j|j|��f�|��|j�d�dS)	Ni�zProxy Authentication Required�Content-Type�	text/htmlzProxy-Authenticatez(Digest realm="%s", qop="%s",nonce="%s", sProxy Authentication Required.F)�
send_response�send_headerr+r,r;�end_headers�wfile�writerrrr
�_return_auth_challenge�s��z(DigestAuthHandler._return_auth_challengecCs�t|j�dkrdSd|jvr&|�|�S|�|jd�}|d|jvrT|j|d}n
|�|�S|�d�|jvrx|�|�S|j�|d�d}|j|j	fD]}|�
|||j|�r�d}q�|s�|�|�SdSdS)aPerforms digest authentication on the given HTTP request
        handler.  Returns True if authentication was successful, False
        otherwise.

        If no users have been set, then digest auth is effectively
        disabled and this method will always return True.
        rTzProxy-Authorization�usernamer:FN)�lenr*�headersrYrI�getr)�remove�path�
short_pathrQZcommand)rrrErJZauth_validatedr_rrr
r$�s0	

�

�
z DigestAuthHandler.handle_requestN)
rrrrrr-r0r1r;rIrQrYr$rrrr
r&Qsr&c@sfeZdZdZdZdZdZdeefZe�	e�
d���d�Zdd�Z
d	d
�Zdd�Zd
d�Zdd�ZdS)�BasicAuthHandlerz,Handler for performing basic authentication.�testUser�testPass�Testz%s:%sr3cOs tjjj|g|�Ri|��dSr")rr�BaseHTTPRequestHandlerr)r�args�kwargsrrr
r�szBasicAuthHandler.__init__cGsdSr"r�r�formatrfrrr
�log_message�szBasicAuthHandler.log_messagecCs"|�d�|�dd�|��dS)N���Content-typerS)rTrUrVr rrr
�do_HEAD�s
zBasicAuthHandler.do_HEADcCs4|�d�|�dd|j�|�dd�|��dS)Ni�zWWW-AuthenticatezBasic realm="%s"rlrS)rTrU�REALMrVr rrr
�do_AUTHHEAD�s
zBasicAuthHandler.do_AUTHHEADcCsh|j�dd�s$|��|j�d�n@|j�dd�d|jkr\|�d�|��|j�d�n|��dS)NZ
Authorization�sNo Auth header receivedzBasic rksIt works)r\r]rorWrX�ENCODED_AUTHrTrVr rrr
�do_GET�s��
zBasicAuthHandler.do_GETN)rrrr�USER�PASSWDrnZUSER_PASSWD�base64Z	b64encoder7�decoderqrrjrmrorrrrrr
ra�srac@s(eZdZdZdd�Zdd�Zdd�ZdS)	�FakeProxyHandlerz�This is a 'fake proxy' that makes it look like the entire
    internet has gone down due to a sudden zombie invasion.  It main
    utility is in providing us with authentication support for
    testing.
    cOs&||_tjjj|g|�Ri|��dSr")�digest_auth_handlerrrrer)rrxrfrgrrr
r�szFakeProxyHandler.__init__cGsdSr"rrhrrr
rjszFakeProxyHandler.log_messagecCsvtj�|jd�\}}}}}}||_|j�|�rr|�dd�|�dd�|�	�|j
�td|jd��|j
�d�dS)	NrrkZOKrRrSzYou've reached %s!<BR>r3sFOur apologies, but our server is down due to a sudden zombie invasion.)
�urllib�parse�urlparser_r`rxr$rTrUrVrWrX�bytes)rZscm�netlocr_�params�query�fragmentrrr
rrs��zFakeProxyHandler.do_GETN)rrrrrrjrrrrrr
rw�srwcsPeZdZdZdZdZdZ�fdd�Zdd�Z�fd	d
�Z	dd�Z
d
d�Z�ZS)�BasicAuthTestsrbrcZ	IncorrectrdcsTtt|���dd�}t|�|_|�|j�d|jj|_|j�	�|jj
��dS)Nc_st|i|��Sr")ra�rfrgrrr
�#http_server_with_basic_auth_handler szABasicAuthTests.setUp.<locals>.http_server_with_basic_auth_handlerzhttp://127.0.0.1:%s)�superr��setUprr�
addCleanup�stop_serverr�
server_url�startr�wait)rr���	__class__rr
r�s

zBasicAuthTests.setUpcCs|j��d|_dSr"�rr!r rrr
r�(s
zBasicAuthTests.stop_servercstt|���dSr")r�r��tearDownr r�rr
r�,szBasicAuthTests.tearDowncCsztj��}|�|j|j|j|j�tj�tj�	|��z|�
tj�|j��Wn&tjj
yt|�d|j�Yn0dS)Nz!Basic auth failed for the url: %s)ryr�HTTPBasicAuthHandler�add_passwordrnr�rsrt�install_opener�build_opener�
assertTrue�urlopen�error�	HTTPError�fail�rZahrrr
�test_basic_auth_success/s
z&BasicAuthTests.test_basic_auth_successcCsRtj��}|�|j|j|j|j�tj�tj�	|��|�
tjjtjj
|j�dSr")ryrr�r�rnr�rs�INCORRECT_PASSWDr�r��assertRaisesr�r�r�r�rrr
�test_basic_auth_httperror8s
z(BasicAuthTests.test_basic_auth_httperror)
rrrrsrtr�rnr�r�r�r�r��
__classcell__rrr�r
r�s	r�r5T)ZopensslcsTeZdZdZdZdZdZ�fdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Z�Z
S)�ProxyAuthTestszhttp://localhostZtesterZtest123Z	TestRealmcs�tt����dd�}��|tj���dtjd<dtjd<t��_�j�	�j
�ji��j��j
��fdd�}t|��_���j��j���jj��d�jj}tj�d	|i�}tj���_tj�|�j��_dS)
NcSstj��tj�|�dSr"��os�environ�clearrP�Zold_environrrr
�restore_environJs
z-ProxyAuthTests.setUp.<locals>.restore_environrp�NO_PROXY�no_proxycst�jg|�Ri|��Sr")rwrxr�r rr
�create_fake_proxy_handlerUsz7ProxyAuthTests.setUp.<locals>.create_fake_proxy_handlerzhttp://127.0.0.1:%dr)r�r�r�r�r�r��copyr&rxr0rsrtr1rnrrr�r�rr�rryrZProxyHandlerZProxyDigestAuthHandler�proxy_digest_handlerr��opener)rr�r�Z	proxy_url�handlerr�r r
r�Gs&



�zProxyAuthTests.setUpcCs|j��d|_dSr"r�r rrr
r�bs
zProxyAuthTests.stop_servercCsF|j�|j|j|j|jd�|j�d�|�t	j
j|jj
|j�dS)NZbadr')r�r�rn�URLrsrtrxr-r�ryr�r�r��openr rrr
�-test_proxy_with_bad_password_raises_httperrorfs�
�z<ProxyAuthTests.test_proxy_with_bad_password_raises_httperrorcCs(|j�d�|�tjj|jj|j�dS�Nr')	rxr-r�ryr�r�r�r�r�r rrr
�,test_proxy_with_no_password_raises_httperrorns

�z;ProxyAuthTests.test_proxy_with_no_password_raises_httperrorcCsb|j�|j|j|j|j�|j�d�|j�	|j��}|�
�r@q6Wd�n1sT0YdSr�)r�r�rnr�rsrtrxr-r�r��read�r�resultrrr
�test_proxy_qop_auth_worksts�z(ProxyAuthTests.test_proxy_qop_auth_workscCs�|j�|j|j|j|j�|j�d�z|j�	|j�}Wnt
jjyNYn00|�|�
�r`qVWd�n1st0YdS)Nzauth-int)r�r�rnr�rsrtrxr-r�r�ryr��URLErrorr�r�rrr
�0test_proxy_qop_auth_int_works_or_throws_urlerror|s�z?ProxyAuthTests.test_proxy_qop_auth_int_works_or_throws_urlerror)rrrr�rsrtrnr�r�r�r�r�r�r�rrr�r
r�?sr�csG��fdd�dtjj���S)NcsBeZdZdZgZgZdZdd�Zdd�Z��fdd�Z	d	d
�Z
dS)z1GetRequestHandler.<locals>.FakeHTTPRequestHandlerz	TestHTTP/�PcSs*|��}|r&|j�|�}||d�}qdSr")�	send_headrWrX)r�body�donerrr
rr�sz8GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_GETcSs2|jd}|j�t|��}|��|j�|�dS)NzContent-Length)r\Zrfiler��intrr�requestsr9)rZcontent_lengthZ	post_datarrr
�do_POST�s
z9GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_POSTcs||j�_|j�|j���d�\}}}|�|�|D]\}}|�||d|ji�q4|rp|�dd�|�	�|S|�	�dS)Nrrrlz
text/plain)
r\�headers_receivedr�r9r_�poprTrUrrV)rZ
response_coder\r��headerrH��FakeHTTPRequestHandler�	responsesrr
r��s
z;GetRequestHandler.<locals>.FakeHTTPRequestHandler.send_headcWsdSr"r)rrfrrr
rj�sz=GetRequestHandler.<locals>.FakeHTTPRequestHandler.log_messageN)rrrZserver_versionr�r�rrrr�r�rjrr�rr
r��sr�)rrre)r�rr�r
�GetRequestHandler�s&r�cs�eZdZdZ�fdd�Zd/dd�Zdd�Zd0d	d
�Zd1dd�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.�Z�ZS)2�TestUrlopenaNTests urllib.request.urlopen using the network.

    These tests are not exhaustive.  Assuming that testing using files does a
    good job overall of some of the basic interface features.  There are no
    tests exercising the optional 'data' and 'proxies' arguments.  No tests
    for transparent redirection have been written.
    csNtt|���|�tjj�dd�}|�|tj�	��dtjd<dtjd<dS)NcSstj��tj�|�dSr"r�r�rrr
r��s
z*TestUrlopen.setUp.<locals>.restore_environ�*r�r�)
r�r�r�r�ryr�
urlcleanupr�r�r�)rr�r�rr
r��s
zTestUrlopen.setUpNcKsxg}tjj||fi|��}zH|�|�d��|�|���|�|�d��|�|���W|��n
|��0d�	|�S)Nrki�)
ryrr��extend�	readlinesr9�readliner��closer)r�url�datarg�l�frrr
r��szTestUrlopen.urlopencCs|j��d|_dSr"r�r rrr
r��s
zTestUrlopen.stop_servercCsZ|durdgdfg}t|�}t|�|_|�|j�|j��|jj��|jj}||_|S)Nrks
we don't care)	r�rrr�r�r�rr�r)rr�r�rrrr
�start_server�s

zTestUrlopen.start_servercKs^ttjd�s|�d�ddlm}|dur6dgdfg}t|�}||fd|i|��}|j|_|S)NZHTTPSHandlerzssl support requiredr)�make_https_serverrk�
we care a bitZ
handler_class)�hasattrryr�skipTestZtest.ssl_serversr�r�r)rr�rgr�r�rrrr
�start_https_server�s
zTestUrlopen.start_https_servercCsVd}ddgdfdg|fg}|�|�}|�d|j�}|�||�|�|jddg�dS)	NsWe got here...i.)ZLocationz(http://localhost:%(port)s/somewhere_elserprk�http://localhost:%s/�/z/somewhere_else�r�r�r�assertEqualr�)r�expected_responser�r�r�rrr
�test_redirection�s��
zTestUrlopen.test_redirectioncCs@d}d}ddg|fg}|�|�}|�d|j�}|�||�dS)Nshello worldsa
hello worl
1
d
0
rk)zTransfer-EncodingZchunkedr�)r�r�rr�)rr�Z
chunked_startrOr�r�rrr
�test_chunkeds�
zTestUrlopen.test_chunkedc
Cs�d}|�dg|fg�}z|�d|j�Wn8tjjyb}z|��}|��WYd}~nd}~00|�d�|�	||�|�	|j
dg�dS)NsBad bad bad...i�zhttp://localhost:%s/weeblez404 should raise URLErrorz/weeble)r�r�rryr�r�r�r�r�r�r�)rr�r�r�r�rrr
�test_404s
zTestUrlopen.test_404cCsFd}|�dg|fg�}|�d|j�}|�||�|�|jdg�dS)N�
pycon 2008...rk�http://localhost:%s/bizarre�/bizarrer��rr�r�r�rrr
�test_200"s
zTestUrlopen.test_200cCsJd}|�dg|fg�}|�d|jd�}|�||�|�|jddg�dS)Nr�rkr�sget=with_feelingr�r�r�rrr
�test_200_with_parameters)s�z$TestUrlopen.test_200_with_parameterscCs8|��}tjtd�}|jd|j|d�}|�|d�dS)N�Zcafile�https://localhost:%s/bizarre��contextr�)r��ssl�create_default_context�CERT_localhostr�rr�)rr�r�r�rrr
�
test_https1szTestUrlopen.test_httpsc	Cs�|jtd�}t�dtf���|jd|jtd�}|�|d�|�t	j
j��$}|jd|jtd�Wd�n1st0Y|jtd�}|�t	j
j��$}|jd|jtd�Wd�n1s�0YWd�n1s�0YdS)N��certfilerpr�r�r�)
r�r�r�check_warnings�DeprecationWarningr�rr�r�ryr�r��CERT_fakehostname)rr�r��cmrrr
�test_https_with_cafile7s��$�z"TestUrlopen.test_https_with_cafilec	Cs�|jtd�}t�dtf��R|�tjj��$}|j	d|j
dd�Wd�n1sT0YWd�n1sr0YdS)Nr�rpr�T)Z	cadefault)r�r�rr�r�r�ryr�r�r�r)rr�r�rrr
�test_https_with_cadefaultHs�z%TestUrlopen.test_https_with_cadefaultcs�tdur|�d�tjs"|�d�d��fdd�}t�tj�}|�|�|j|td�}tjtd�}|j	d|j
|d�|��d	�dS)
Nzssl module requiredzSNI support required in OpenSSLcs|�dSr"r)Zssl_sockZserver_nameZinitial_context�Zsni_namerr
�cb_sniVsz*TestUrlopen.test_https_sni.<locals>.cb_sni)r�r�r�zhttps://localhost:%sr��	localhost)r�r�ZHAS_SNIZ
SSLContextZPROTOCOL_TLS_SERVERZset_servername_callbackr�r�r�r�rr�)rr�r�r�rr�r
�test_https_sniPs


zTestUrlopen.test_https_snicCsd|��}tjjd|jddid�}tj�|��Wd�n1sD0Y|�|jdd�dS)Nr�ZRangezbytes=20-39�r\)r�ryr�Requestrr�r�r��rr�Zreqrrr
�test_sending_headers`s�z TestUrlopen.test_sending_headerscCsv|��}tjjd|jddid�}tj�|��Wd�n1sD0Y|�d|j���|�	d|j���dS)Nr�z
X-SoMe-hEaderZfoobarr�z
X-Some-Header)
r�ryrr�rr�ZassertInr��keysZassertNotInr�rrr
�test_sending_headers_camelhs�z&TestUrlopen.test_sending_headers_camelcCsn|��}tj�d|j��@}dD]}|�t||�d|�q |�|��d�Wd�n1s`0YdS)N�http://localhost:%s)r�r��info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r�ryrr�rr�r�r�)rr��open_url�attrrrr
�
test_basicqs�zTestUrlopen.test_basiccCsl|��}tj�d|j�}|�|��}Wd�n1s<0Y|�|tjj	d�|�
|��d�dS)Nr�zEobject returned by 'info' is not an instance of email.message.MessageZplain)r�ryrr�rrZassertIsInstance�email�messageZMessager�Zget_content_subtype)rr�rZinfo_objrrr
�	test_infoys�&�zTestUrlopen.test_infocCs\|��}tj�d|j�}|�|��}Wd�n1s<0Y|�|d|j�dS)Nr�)r�ryrr�rrr�)rr�rr�rrr
�test_geturl�s
&zTestUrlopen.test_geturlcCsBd}|�dg|fg�}tj�d|j�}|D]}|�||�q,dS)Nr�rkr�)r�ryrr�rr�)rr�r�r��linerrr
�test_iteration�s
zTestUrlopen.test_iterationc
Cs�ddddddg}d�|�}|�dg|fg�}tj�d	|j�}t|�D]0\}}|�|||d
|t||�t|�f�qJ|�|dt|��dS)NsWe
sgot
shere
s	verylong i �
r�rkr�zQFetched line number %s doesn't match expected:
    Expected length was %s, got %sr2)	rr�ryrr�r�	enumerater�r[)r�linesr�r�r��indexr	rrr
�test_line_iteration�s
��zTestUrlopen.test_line_iterationcCs�|�dgdfdgdfg�}tj��}tj�d|j�}|�d|j�|�|d�	d��|�d|j�|�d|�
d��|�|d�	d��|�d	|j�|�d
|�
d��dS)Nrksanyr��1zus-ascii�1zContent-lengthZ
1234567890s
1234567890Z10)r�ryrr�r�rr�r�r�r7Z
get_header)rr�r�rrrr
�test_issue16464�s�
zTestUrlopen.test_issue16464)N)N)N)rrrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
rrr�rrr�r
r��s.




	r�cCs t��}tjtjg|�R�dSr")rZthreading_setup�unittestZaddModuleCleanupZthreading_cleanup)�thread_inforrr
�setUpModule�sr�__main__)*rur�r�urllib.parseryZurllib.requestZhttp.serverrrrr4�testrZtest.supportrr��ImportErrorr_�dirname�__file__�hererr�r�rrrrrr&rerarwZTestCaser�Zrequires_hashdigestr�r�r�rr�mainrrrr
�<module>s>
y,!(M+{


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