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

�9j�e�@s�ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
ddlmZzddlZWneyGdZYnwej�e�Zej�ed�Zej�ed�ZGdd�dejj�ZGd	d
�d
ej�ZGdd�d�ZGd
d�dejj�ZGdd�dejj�Z Gdd�de	j!�Z"ej#ddd�Gdd�de	j!��Z$dd�Z%Gdd�de	j!�Z&dd�Z'e(dkr�e	�)�dSdS)�N)�hashlib_helper)�threading_helper)�warnings_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)�self�server_address�RequestHandlerClass�r�1/usr/lib/python3.10/test/test_urllib2_localnet.pyr	"s

�zLoopbackHttpServer.__init__cCs |j��\}}|�d�||fS)zHTTPServer method, overridden.g$@)r
�acceptr)r�request�client_addressrrr�get_request+s
zLoopbackHttpServer.get_requestN)�__name__�
__module__�__qualname__�__doc__r	rrrrrrs	rc@�(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�ready�protocol_versionr�httpd�server_port�port�r�request_handlerrrrr	:s
�z!LoopbackHttpServerThread.__init__cCsd|_|��|j��dS)z.Stops the webserver if it's currently running.TN)r�joinr!�server_close�rrrr�stopCszLoopbackHttpServerThread.stopcCs(|j��|js|j��|jrdSdS�N)r�setrr!�handle_requestr(rrr�runKs

�zLoopbackHttpServerThread.runN)rrrrr	r)r-rrrrr7s
	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(rrrr	Us

zDigestAuthHandler.__init__cC�
||_dSr*)r4)r�qoprrr�set_qop\�
zDigestAuthHandler.set_qopcCst|t�sJ�||_dSr*)�
isinstance�dictr2)r�usersrrr�	set_users_s
zDigestAuthHandler.set_userscCr5r*)r3)r�realmrrr�	set_realmcr8zDigestAuthHandler.set_realmcCs8|jd7_t�t|j��d����}|j�|�|S)N��ascii)r0�hashlib�md5�str�encode�	hexdigestr1�append)r�noncerrr�_generate_noncefsz!DigestAuthHandler._generate_noncecCs�|�d�}||dd�}|�d�}i}|D](}|�d�\}}|��}|ddkr6|ddkr6|dd�}n|��}|||<q|S)N� r?�,�=r�"���)�find�split�strip)r�auth_str�first_space_index�parts�	auth_dict�part�name�valuerrr�_create_auth_dictls


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)sr@z%(method)s:%(uri)s�HA1�HA2z3%(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)s�response)�updaterArBrDrE)rrTrYrZr[�
final_dict�HA1_strr\�HA2_strr]�response_strr^rrr�_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_headerr3r4rH�end_headers�wfile�writer$rrr�_return_auth_challenge�s��z(DigestAuthHandler._return_auth_challengecCs�t|j�dkr	dSd|jvr|�|�S|�|jd�}|d|jvr*|j|d}n|�|�S|�d�|jvr<|�|�S|j�|d�d}|j|j	fD]
}|�
|||j|�rYd}qL|sa|�|�SdS)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�usernamerGF)�lenr2�headersrlrX�getr1�remove�path�
short_pathrd�command)rr%rTrY�auth_validatedrrrrrr,�s2	

�

��
z DigestAuthHandler.handle_requestN)
rrrrr	r7r<r>rHrXrdrlr,rrrrr.Rsr.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:%sr@cOs tjjj|g|�Ri|��dSr*)rr�BaseHTTPRequestHandlerr	)r�args�kwargsrrrr	�s zBasicAuthHandler.__init__cG�dSr*r�r�formatr{rrr�log_message�szBasicAuthHandler.log_messagecCs"|�d�|�dd�|��dS)N���Content-typerf)rgrhrir(rrr�do_HEAD�s
zBasicAuthHandler.do_HEADcCs4|�d�|�dd|j�|�dd�|��dS)Ni�zWWW-AuthenticatezBasic realm="%s"r�rf)rgrh�REALMrir(rrr�do_AUTHHEAD�s
zBasicAuthHandler.do_AUTHHEADcCsl|j�dd�s|��|j�d�dS|j�dd�d|jkr0|�d�|��|j�d�dS|��dS)N�
Authorization�sNo Auth header receivedzBasic r�sIt works)rorpr�rjrk�ENCODED_AUTHrgrir(rrr�do_GET�s��
zBasicAuthHandler.do_GETN)rrrr�USER�PASSWDr��USER_PASSWD�base64�	b64encoderD�decoder�r	r�r�r�r�rrrrrv�srvc@r)	�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_handlerrrrzr	)rr�r{r|rrrr	�s zFakeProxyHandler.__init__cGr}r*rr~rrrr�szFakeProxyHandler.log_messagecCsztj�|jd�\}}}}}}||_|j�|�r;|�dd�|�dd�|�	�|j
�td|jd��|j
�d�dSdS)	Nrr��OKrerfzYou've reached %s!<BR>r@sFOur apologies, but our server is down due to a sudden zombie invasion.)
�urllib�parse�urlparserrrsr�r,rgrhrirjrk�bytes)r�scm�netlocrr�params�query�fragmentrrrr�	s���zFakeProxyHandler.do_GETN)rrrrr	r�r�rrrrr��s
r�csPeZdZdZdZdZdZ�fdd�Zdd�Z�fd	d
�Z	dd�Z
d
d�Z�ZS)�BasicAuthTestsrwrx�	IncorrectrycsTtt|���dd�}t|�|_|�|j�d|jj|_|j�	�|jj
��dS)Nc_st|i|��Sr*)rv�r{r|rrr�#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)rr���	__class__rrr�s

zBasicAuthTests.setUpcC�|j��d|_dSr*�rr)r(rrrr�)�

zBasicAuthTests.stop_servercstt|���dSr*)r�r��tearDownr(r�rrr�-szBasicAuthTests.tearDowncCsztj��}|�|j|j|j|j�tj�tj�	|��z
|�
tj�|j��WdStjj
y<|�d|j�YdSw)Nz!Basic auth failed for the url: %s)r�r�HTTPBasicAuthHandler�add_passwordr�r�r�r��install_opener�build_opener�
assertTrue�urlopen�error�	HTTPError�fail�r�ahrrr�test_basic_auth_success0s
�z&BasicAuthTests.test_basic_auth_successcCsRtj��}|�|j|j|j|j�tj�tj�	|��|�
tjjtjj
|j�dSr*)r�rr�r�r�r�r��INCORRECT_PASSWDr�r��assertRaisesr�r�r�r�rrr�test_basic_auth_httperror9s
z(BasicAuthTests.test_basic_auth_httperror)
rrrr�r�r�r�r�r�r�r�r��
__classcell__rrr�rr�s	r�rBT)�opensslcsTeZdZdZdZdZdZ�fdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Z�Z
S)�ProxyAuthTestszhttp://localhost�tester�test123�	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)
NcS�tj��tj�|�dSr*��os�environ�clearr_��old_environrrr�restore_environK�
z-ProxyAuthTests.setUp.<locals>.restore_environr��NO_PROXY�no_proxycst�jg|�Ri|��Sr*)r�r�r�r(rr�create_fake_proxy_handlerVsz7ProxyAuthTests.setUp.<locals>.create_fake_proxy_handlerzhttp://127.0.0.1:%dr)r�r�r�r�r�r��copyr.r�r<r�r�r>r�rrr�r�rr�r#r�r�ProxyHandler�ProxyDigestAuthHandler�proxy_digest_handlerr��opener)rr�r��	proxy_url�handlerr�r(rr�Hs&




�zProxyAuthTests.setUpcCr�r*r�r(rrrr�cr�zProxyAuthTests.stop_servercCsF|j�|j|j|j|jd�|j�d�|�t	j
j|jj
|j�dS)N�badr/)r�r�r��URLr�r�r�r7r�r�r�r�r��openr(rrr�-test_proxy_with_bad_password_raises_httperrorgs�
�z<ProxyAuthTests.test_proxy_with_bad_password_raises_httperrorcCs(|j�d�|�tjj|jj|j�dS�Nr/)	r�r7r�r�r�r�r�r�r�r(rrr�,test_proxy_with_no_password_raises_httperroros

�z;ProxyAuthTests.test_proxy_with_no_password_raises_httperrorcCs||j�|j|j|j|j�|j�d�|j�	|j��}|�
�r,	|�
�sWd�dSWd�dS1s7wYdSr�)r�r�r�r�r�r�r�r7r�r��read�r�resultrrr�test_proxy_qop_auth_worksus�
��"�z(ProxyAuthTests.test_proxy_qop_auth_workscCs�|j�|j|j|j|j�|j�d�z	|j�	|j�}Wnt
jjy(YdSw|�|�
�r=	|�
�s0Wd�dSWd�dS1sHwYdS)Nzauth-int)r�r�r�r�r�r�r�r7r�r�r�r��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�r�r�r�r�r�r�r�r�r�r�rrr�rr�@sr�csG��fdd�dtjj���S)NcsBeZdZdZgZgZdZdd�Zdd�Z��fdd�Z	d	d
�Z
dS)z1GetRequestHandler.<locals>.FakeHTTPRequestHandlerz	TestHTTP/�PcSs0|��}|r|j�|�}||d�}|sdSdSr*)�	send_headrjrk)r�body�donerrrr��s
�z8GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_GETcSs2|jd}|j�t|��}|��|j�|�dS)NzContent-Length)ro�rfiler��intr��requestsrF)r�content_length�	post_datarrr�do_POST�s
z9GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_POSTcs||j�_|j�|j���d�\}}}|�|�|D]\}}|�||d|ji�q|r8|�dd�|�	�|S|�	�dS)Nrr#r�z
text/plain)
ro�headers_receivedr�rFrr�poprgrhr#ri)r�
response_coderor��headerrW��FakeHTTPRequestHandler�	responsesrrr��s
z;GetRequestHandler.<locals>.FakeHTTPRequestHandler.send_headcWr}r*r)rr{rrrr��sz=GetRequestHandler.<locals>.FakeHTTPRequestHandler.log_messageN)rrr�server_versionr�r�r#r�r�r�r�rr�rrr��sr�)rrrz)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*�Zd+d,�Zd-d.�Z�ZS)0�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)NcSr�r*r�r�rrrr��r�z*TestUrlopen.setUp.<locals>.restore_environ�*r�r�)
r�r�r�r�r�r�
urlcleanupr�r�r�)rr�r�rrr��s
zTestUrlopen.setUpNcKsxg}tjj||fi|��}z$|�|�d��|�|���|�|�d��|�|���W|��n|��wd�	|�S)Nr�i�)
r�rr��extend�	readlinesrF�readliner��closer&)r�url�datar|�l�frrrr��s
zTestUrlopen.urlopencCr�r*r�r(rrrr��r�zTestUrlopen.stop_servercCsZ|dur
dgdfg}t|�}t|�|_|�|j�|j��|jj��|jj}||_|S)Nr�s
we don't care)	r�rrr�r�r�rr�r#)rr�r�r#rrr�start_server�s

zTestUrlopen.start_servercKs^ttjd�s|�d�ddlm}|durdgdfg}t|�}||fd|i|��}|j|_|S)N�HTTPSHandlerzssl support requiredr)�make_https_serverr��
we care a bit�
handler_class)�hasattrr�r�skipTest�test.ssl_serversrr�r#)rr�r|rr�rrrr�start_https_server�s
zTestUrlopen.start_https_servercCsVd}ddgdfdg|fg}|�|�}|�d|j�}|�||�|�|jddg�dS)	NsWe got here...i.)�Locationz(http://localhost:%(port)s/somewhere_elser�r��http://localhost:%s/�/z/somewhere_else�rr�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
r�)zTransfer-Encoding�chunkedr
)rr�r#r
)rr�
chunked_startr^r�r�rrr�test_chunkeds�
zTestUrlopen.test_chunkedc
Cs�d}|�dg|fg�}z
|�d|j�Wntjjy1}z|��}|��WYd}~n
d}~ww|�d�|�	||�|�	|j
dg�dS)NsBad bad bad...i�zhttp://localhost:%s/weeblez404 should raise URLErrorz/weeble)rr�r#r�r�r�r�r�r�r
r�)rrr�r�r�rrr�test_404s��
zTestUrlopen.test_404cCsFd}|�dg|fg�}|�d|j�}|�||�|�|jdg�dS)N�
pycon 2008...r��http://localhost:%s/bizarre�/bizarrer�rrr�r�rrr�test_200#s
zTestUrlopen.test_200cCsJd}|�dg|fg�}|�d|jd�}|�||�|�|jddg�dS)Nrr�rsget=with_feelingrrrrrr�test_200_with_parameters*s�z$TestUrlopen.test_200_with_parameterscCs8|��}tjtd�}|jd|j|d�}|�|d�dS)N��cafile�https://localhost:%s/bizarre��contextr)r�ssl�create_default_context�CERT_localhostr�r#r
)rr�rr�rrr�
test_https2szTestUrlopen.test_httpsc	Cs|jtd�}t�dtf��i|jd|jtd�}|�|d�|�t	j
j��}|jd|jtd�Wd�n1s:wY|jtd�}|�t	j
j��}|jd|jtd�Wd�n1sawYWd�dSWd�dS1sywYdS)N��certfiler�rrr)
rr!r�check_warnings�DeprecationWarningr�r#r
r�r�r�r��CERT_fakehostname)rr�r��cmrrr�test_https_with_cafile8s(������"�z"TestUrlopen.test_https_with_cafilec	Cs�|jtd�}t�dtf��2|�tjj��}|j	d|j
dd�Wd�n1s*wYWd�dSWd�dS1sBwYdS)Nr#r�rT)�	cadefault)rr!rr%r&r�r�r�r�r�r#)rr�r(rrr�test_https_with_cadefaultIs���"�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)�ssl_sock�server_name�initial_context��sni_namerr�cb_sniWsz*TestUrlopen.test_https_sni.<locals>.cb_sni)rr$rzhttps://localhost:%sr�	localhost)rr�HAS_SNI�
SSLContext�PROTOCOL_TLS_SERVER�set_servername_callbackrr!r r�r#r
)rr1rr�rr/r�test_https_sniQs


zTestUrlopen.test_https_snicCsd|��}tjjd|jddid�}tj�|��Wd�n1s"wY|�|jdd�dS)Nr
�Rangezbytes=20-39�ro)rr�r�Requestr#r�r
r��rr��reqrrr�test_sending_headersas��z TestUrlopen.test_sending_headerscCsv|��}tjjd|jddid�}tj�|��Wd�n1s"wY|�d|j���|�	d|j���dS)Nr
z
X-SoMe-hEader�foobarr9z
X-Some-Header)
rr�rr:r#r��assertInr��keys�assertNotInr;rrr�test_sending_headers_camelis��z&TestUrlopen.test_sending_headers_camelcCsp|��}tj�d|j��!}dD]
}|�t||�d|�q|�|��d�Wd�dS1s1wYdS)N�http://localhost:%s)r�r��info�geturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)rr�rr�r#r�rr�)rr��open_url�attrrrr�
test_basicrs�"�zTestUrlopen.test_basiccCsl|��}tj�d|j�}|�|��}Wd�n1swY|�|tjj	d�|�
|��d�dS)NrCzEobject returned by 'info' is not an instance of email.message.Message�plain)rr�rr�r#rD�assertIsInstance�email�message�Messager
�get_content_subtype)rr�rF�info_objrrr�	test_infozs�
��zTestUrlopen.test_infocCs\|��}tj�d|j�}|�|��}Wd�n1swY|�|d|j�dS)NrC)rr�rr�r#rEr
)rr�rFr�rrr�test_geturl�s
�zTestUrlopen.test_geturlcCsBd}|�dg|fg�}tj�d|j�}|D]}|�||�qdS)Nrr�rC)rr�rr�r#r
)rrr�r��linerrr�test_iteration�s�zTestUrlopen.test_iterationc
Cs�ddddddg}d�|�}|�dg|fg�}tj�d	|j�}t|�D]\}}|�|||d
|t||�t|�f�q%|�|dt|��dS)NsWe
sgot
shere
s	verylong i �
r�r�rCzQFetched line number %s doesn't match expected:
    Expected length was %s, got %sr?)	r&rr�rr�r#�	enumerater
rn)r�linesrr�r��indexrRrrr�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)Nr�sanyrC�1zus-ascii�1zContent-length�
1234567890s
1234567890�10)rr�rr�r:r#r
r�r�rD�
get_header)rr�r�rrrr�test_issue16464�s�
zTestUrlopen.test_issue16464r*)rrrrr�r�r�rrrrrrrr"r)r+r7r=rBrHrPrQrSrXr^r�rrr�rr��s0




	r�cCs t��}tjtjg|�R�dSr*)r�threading_setup�unittest�addModuleCleanup�threading_cleanup)�thread_inforrr�setUpModule�srd�__main__)*r�r�rK�urllib.parser��urllib.request�http.serverrrr`rA�test.supportrrrr�ImportErrorrr�dirname�__file__�herer&r!r'rrrrrr.rzrvr��TestCaser��requires_hashdigestr�r�r�rdr�mainrrrr�<module>sF�y,!(M+{�

Youez - 2016 - github.com/yon3zu
LinuXploit