Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_urllib2_localnet.cpython-38.pyc
U

>��g�`�@sfddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZzddl
Z
Wnek
rxdZ
YnXej�e�Zej�ed�Zej�ed�ZGdd�dejj�ZGdd�dej�ZGd	d
�d
�ZGdd�dejj�ZGd
d�dejj�ZGdd�de	j�Z Gdd�de	j�Z!dd�Z"Gdd�de	j�Z#da$dd�Z%dd�Z&e'dk�rbe	�(�dS)�N)�supportzkeycert.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�9/opt/cppython/lib/python3.8/test/test_urllib2_localnet.pyr s

�zLoopbackHttpServer.__init__cCs |j��\}}|�d�||fS)zHTTPServer method, overridden.g$@)r�acceptr	)r
�requestZclient_addressrrr�get_request)s
zLoopbackHttpServer.get_requestN)�__name__�
__module__�__qualname__�__doc__rrrrrr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_handlerrrrr8s
�z!LoopbackHttpServerThread.__init__cCsd|_|��|j��dS)z.Stops the webserver if it's currently running.TN)r�joinrZserver_close�r
rrr�stopAszLoopbackHttpServerThread.stopcCs |j��|js|j��q
dS�N)r�setrr�handle_requestrrrr�runIs
zLoopbackHttpServerThread.runN)rrrrrr r$rrrrr5s	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�_qoprrrrrSs
zDigestAuthHandler.__init__cCs
||_dSr!)r+)r
Zqoprrr�set_qopZszDigestAuthHandler.set_qopcCst|t�st�||_dSr!)�
isinstance�dict�AssertionErrorr))r
Zusersrrr�	set_users]szDigestAuthHandler.set_userscCs
||_dSr!)r*)r
Zrealmrrr�	set_realmaszDigestAuthHandler.set_realmcCs8|jd7_t�t|j��d����}|j�|�|S)N��ascii)r'�hashlib�md5�str�encode�	hexdigestr(�append)r
�noncerrr�_generate_noncedsz!DigestAuthHandler._generate_noncecCs�|�d�}||dd�}|�d�}i}|D]P}|�d�\}}|��}|ddkrl|ddkrl|dd�}n|��}|||<q,|S)N� r2�,�=r�"���)�find�split�strip)r
Zauth_strZfirst_space_index�parts�	auth_dict�part�name�valuerrr�_create_auth_dictjs


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)r
rErJrKrLZ
final_dictZHA1_strrMZHA2_strrNZresponse_strrOrrr�_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�writerrrr�_return_auth_challenge�s��z(DigestAuthHandler._return_auth_challengecCs�t|j�dkrdSd|jkr&|�|�S|�|jd�}|d|jkrT|j|d}n
|�|�S|�d�|jkrx|�|�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-AuthorizationZusernamer:FN)�lenr)�headersrYrI�getr(�remove�path�
short_pathrQZcommand)r
rrErJZauth_validatedr^rrrr#�s0	

�

�
z DigestAuthHandler.handle_requestN)
rrrrrr,r0r1r;rIrQrYr#rrrrr%Psr%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:%sr3cOstjjj|f|�|�dSr!)rr�BaseHTTPRequestHandlerr)r
�args�kwargsrrrr�szBasicAuthHandler.__init__cGsdSr!r�r
�formatrerrr�log_message�szBasicAuthHandler.log_messagecCs"|�d�|�dd�|��dS)N���Content-typerS)rTrUrVrrrr�do_HEAD�s
zBasicAuthHandler.do_HEADcCs4|�d�|�dd|j�|�dd�|��dS)Ni�zWWW-AuthenticatezBasic realm="%s"rkrS)rTrU�REALMrVrrrr�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 rjsIt works)r[r\rnrWrX�ENCODED_AUTHrTrVrrrr�do_GET�s��
zBasicAuthHandler.do_GETN)rrrr�USER�PASSWDrmZUSER_PASSWD�base64Z	b64encoder7�decoderprrirlrnrqrrrrr`�sr`c@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|f|�|�dSr!)�digest_auth_handlerrrrdr)r
rwrerfrrrr�szFakeProxyHandler.__init__cGsdSr!rrgrrrriszFakeProxyHandler.log_messagecCsvtj�|jd�\}}}}}}||_|j�|�rr|�dd�|�dd�|�	�|j
�td|jd��|j
�d�dS)	NrrjZOKrRrSzYou've reached %s!<BR>r3sFOur apologies, but our server is down due to a sudden zombie invasion.)
�urllib�parse�urlparser^r_rwr#rTrUrVrWrX�bytes)r
ZscmZnetlocr^�paramsZqueryZfragmentrrrrqs��zFakeProxyHandler.do_GETN)rrrrrrirqrrrrrv�srvcsPeZdZdZdZdZdZ�fdd�Zdd�Z�fd	d
�Z	dd�Z
d
d�Z�ZS)�BasicAuthTestsrarbZ	IncorrectrccsTtt|���dd�}t|�|_|�|j�d|jj|_|j�	�|jj
��dS)Nc_s
t||�Sr!)r`�rerfrrr�#http_server_with_basic_auth_handlerszABasicAuthTests.setUp.<locals>.http_server_with_basic_auth_handlerzhttp://127.0.0.1:%s)�superr}�setUprr�
addCleanup�stop_serverr�
server_url�startr�wait)r
r��	__class__rrr�s

zBasicAuthTests.setUpcCs|j��d|_dSr!�rr rrrrr�'s
zBasicAuthTests.stop_servercstt|���dSr!)r�r}�tearDownrr�rrr�+szBasicAuthTests.tearDowncCs|tj��}|�|j|j|j|j�tj�tj�	|��z|�
tj�|j��Wn(tjj
k
rv|�d|j�YnXdS)Nz!Basic auth failed for the url: %s)rxr�HTTPBasicAuthHandler�add_passwordrmr�rrrs�install_opener�build_opener�
assertTrue�urlopen�error�	HTTPError�fail�r
Zahrrr�test_basic_auth_success.s
z&BasicAuthTests.test_basic_auth_successcCsRtj��}|�|j|j|j|j�tj�tj�	|��|�
tjjtjj
|j�dSr!)rxrr�r�rmr�rr�INCORRECT_PASSWDr�r��assertRaisesr�r�r�r�rrr�test_basic_auth_httperror7s
z(BasicAuthTests.test_basic_auth_httperror)
rrrrrrsr�rmr�r�r�r�r��
__classcell__rrr�rr}s	r}cs^eZdZdZdZdZdZe�d��fdd��Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Z�ZS)�ProxyAuthTestszhttp://localhostZtesterZtest123Z	TestRealmr5cs�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_environrrr�restore_environIs
z-ProxyAuthTests.setUp.<locals>.restore_environro�NO_PROXY�no_proxycst�jf|�|�Sr!)rvrwr~rrr�create_fake_proxy_handlerTsz7ProxyAuthTests.setUp.<locals>.create_fake_proxy_handlerzhttp://127.0.0.1:%dr)r�r�r�r�r�r��copyr%rwr0rrrsr1rmrrr�r�rr�rrxrZProxyHandlerZProxyDigestAuthHandler�proxy_digest_handlerr��opener)r
r�r�Z	proxy_url�handlerr�rrr�Es(



�zProxyAuthTests.setUpcCs|j��d|_dSr!r�rrrrr�as
zProxyAuthTests.stop_servercCsF|j�|j|j|j|jd�|j�d�|�t	j
j|jj
|j�dS)NZbadr&)r�r�rm�URLrrrsrwr,r�rxr�r�r��openrrrr�-test_proxy_with_bad_password_raises_httperrores�
�z<ProxyAuthTests.test_proxy_with_bad_password_raises_httperrorcCs(|j�d�|�tjj|jj|j�dS�Nr&)	rwr,r�rxr�r�r�r�r�rrrr�,test_proxy_with_no_password_raises_httperrorms

�z;ProxyAuthTests.test_proxy_with_no_password_raises_httperrorc	CsN|j�|j|j|j|j�|j�d�|j�	|j��}|�
�r@q6W5QRXdSr�)r�r�rmr�rrrsrwr,r�r��read�r
�resultrrr�test_proxy_qop_auth_worksss�z(ProxyAuthTests.test_proxy_qop_auth_worksc	Csp|j�|j|j|j|j�|j�d�z|j�	|j�}Wnt
jjk
rPYnX|�|�
�rbqXW5QRXdS)Nzauth-int)r�r�rmr�rrrsrwr,r�r�rxr��URLErrorr�r�rrr�0test_proxy_qop_auth_int_works_or_throws_urlerror{s�z?ProxyAuthTests.test_proxy_qop_auth_int_works_or_throws_urlerror)rrrr�rrrsrmrZrequires_hashdigestr�r�r�r�r�r�r�rrr�rr�>sr�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�donerrrrq�sz8GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_GETcSs2|jd}|j�t|��}|��|j�|�dS)NzContent-Length)r[Zrfiler��intrq�requestsr9)r
Zcontent_lengthZ	post_datarrr�do_POST�s
z9GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_POSTcs||j�_|j�|j���d�\}}}|�|�|D]\}}|�||d|ji�q4|rp|�dd�|�	�|S|�	�dS)Nrrrkz
text/plain)
r[�headers_receivedr�r9r^�poprTrUrrV)r
Z
response_coder[r��headerrH��FakeHTTPRequestHandler�	responsesrrr��s
z;GetRequestHandler.<locals>.FakeHTTPRequestHandler.send_headcWsdSr!r)r
rerrrri�sz=GetRequestHandler.<locals>.FakeHTTPRequestHandler.log_messageN)rrrZserver_versionr�r�rrqr�r�rirr�rrr��sr�)rrrd)r�rr�r�GetRequestHandler�s&r�cs�eZdZdZ�fdd�Zd+dd�Zdd�Zd,d	d
�Zd-dd�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*�Z�ZS).�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.
    cs@tt|���dd�}|�|tj���dtjd<dtjd<dS)NcSstj��tj�|�dSr!r�r�rrrr��s
z*TestUrlopen.setUp.<locals>.restore_environ�*r�r�)r�r�r�r�r�r�r�)r
r�r�rrr��s

zTestUrlopen.setUpNcKslg}tjj||f|�}z@|�|�d��|�|���|�|�d��|�|���W5|��Xd�	|�S)Nrji�)
rxrr��close�extend�	readlinesr9�readliner�r)r
�url�datarf�l�frrrr��s
zTestUrlopen.urlopencCs|j��d|_dSr!r�rrrrr��s
zTestUrlopen.stop_servercCsZ|dkrdgdfg}t|�}t|�|_|�|j�|j��|jj��|jj}||_|S)Nrjs
we don't care)	r�rrr�r�r�rr�r)r
r�r�rrrr�start_server�s

zTestUrlopen.start_servercKs^ttjd�s|�d�ddlm}|dkr6dgdfg}t|�}||fd|i|��}|j|_|S)NZHTTPSHandlerzssl support requiredr)�make_https_serverrj�
we care a bitZ
handler_class)�hasattrrxr�skipTestZtest.ssl_serversr�r�r)r
r�rfr�r�rrrr�start_https_server�s
zTestUrlopen.start_https_servercCsVd}ddgdfdg|fg}|�|�}|�d|j�}|�||�|�|jddg�dS)	NsWe got here...i.)ZLocationz(http://localhost:%(port)s/somewhere_elserorj�http://localhost:%s/�/z/somewhere_else�r�r�r�assertEqualr�)r
�expected_responser�r�r�rrr�test_redirection�s��
zTestUrlopen.test_redirectioncCs@d}d}ddg|fg}|�|�}|�d|j�}|�||�dS)Nshello worldsa
hello worl
1
d
0
rj)zTransfer-EncodingZchunkedr�)r�r�rr�)r
r�Z
chunked_startrOr�r�rrr�test_chunkeds�
zTestUrlopen.test_chunkedc
Cs�d}|�dg|fg�}z|�d|j�Wn6tjjk
r`}z|��}|��W5d}~XYnX|�d�|�	||�|�	|j
dg�dS)NsBad bad bad...i�zhttp://localhost:%s/weeblez404 should raise URLErrorz/weeble)r�r�rrxr�r�r�r�r�r�r�)r
r�r�r�r�rrr�test_404s
zTestUrlopen.test_404cCsFd}|�dg|fg�}|�d|j�}|�||�|�|jdg�dS)N�
pycon 2008...rj�http://localhost:%s/bizarre�/bizarrer��r
r�r�r�rrr�test_200s
zTestUrlopen.test_200cCsJd}|�dg|fg�}|�d|jd�}|�||�|�|jddg�dS)Nr�rjr�sget=with_feelingr�r�r�rrr�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�)r
r�r�r�rrr�
test_https-szTestUrlopen.test_httpsc
Cs�|jtd�}t�dtf���|jd|jtd�}|�|d�|�t	j
j��}|jd|jtd�W5QRX|jtd�}|�t	j
j��}|jd|jtd�W5QRXW5QRXdS)N��certfileror�r�r�)
r�r�r�check_warnings�DeprecationWarningr�rr�r�rxr�r��CERT_fakehostname)r
r�r��cmrrr�test_https_with_cafile3s���z"TestUrlopen.test_https_with_cafilec
CsX|jtd�}t�dtf��4|�tjj��}|j	d|j
dd�W5QRXW5QRXdS)Nr�ror�T)Z	cadefault)r�r�rr�r�r�rxr�r�r�r)r
r�r�rrr�test_https_with_cadefaultDs�z%TestUrlopen.test_https_with_cadefaultcs�tdkr|�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_namerr�cb_sniRsz*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�)r
r�r�r�rr�r�test_https_sniLs


zTestUrlopen.test_https_snic	CsP|��}tjjd|jddid�}tj�|��W5QRX|�|jdd�dS)Nr�ZRangezbytes=20-39)r[)r�rxrZRequestrr�r�r�)r
r�Zreqrrr�test_sending_headers\s�
z TestUrlopen.test_sending_headersc	CsZ|��}tj�d|j��6}dD]}|�t||�d|�q |�|��d�W5QRXdS)N�http://localhost:%s)r�r��info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r�rxrr�rr�r�r�)r
r��open_url�attrrrr�
test_basicds�zTestUrlopen.test_basicc	CsX|��}tj�d|j�}|�|��}W5QRX|�|tjj	d�|�
|��d�dS)Nr�zEobject returned by 'info' is not an instance of email.message.MessageZplain)r�rxrr�rr�ZassertIsInstance�email�messageZMessager�Zget_content_subtype)r
r�r�Zinfo_objrrr�	test_infols��zTestUrlopen.test_infoc	CsH|��}tj�d|j�}|�|��}W5QRX|�|d|j�dS)Nr�)r�rxrr�rr�r�)r
r�r�r�rrr�test_geturlws
zTestUrlopen.test_geturlcCsBd}|�dg|fg�}tj�d|j�}|D]}|�||�q,dS)Nr�rjr�)r�rxrr�rr�)r
r�r�r��linerrr�test_iterations
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�rjr�zQFetched line number %s doesn't match expected:
    Expected length was %s, got %sr2)	rr�rxrr�r�	enumerater�rZ)r
�linesr�r�r��indexr�rrr�test_line_iteration�s
��zTestUrlopen.test_line_iteration)N)N)N)rrrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�rrr�rr��s*




r�cCst��adSr!)rZthreading_setup�threads_keyrrrr�setUpModule�srcCstrtjt�dSr!)rrZthreading_cleanuprrrr�tearDownModule�sr�__main__))rtr�r�Zurllib.parserxZurllib.requestZhttp.serverrrZunittestr4�testrr��ImportErrorr^�dirname�__file__�hererr�r�rrrrrr%rdr`rvZTestCaser}r�r�r�rrrr�mainrrrr�<module>s>
y,!(N+]


F1le Man4ger