python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_urllib2_localnet.cpython-312.pyc

ΑeCfLddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddl
mZddl
mZ	ddlZej&dej(j+eZej(j1edZej(j1ed	ZGd
dej6j8ZGdd
ej<ZGddZ Gddej6jBZ"Gddej6jBZ#Gdde	jHZ%ejLddGdde	jHZ'dZ(Gdde	jHZ)dZ*e+dk(re	jXyy#e$rdZY`wxYw)N)support)hashlib_helper)threading_helper)warnings_helperT)modulezkeycert.pemzkeycert2.pemceZdZdZdZdZy)LoopbackHttpServerz^HTTP server w/ a few modifications that make it useful for
    loopback testing purposes.
    ctjjj||||jjdy)Ng?)httpserver
HTTPServer__init__socket
settimeout)selfserver_addressRequestHandlerClasss   N/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_urllib2_localnet.pyrzLoopbackHttpServer.__init__%s6''(6(;	=	
s#cf|jj\}}|jd||fS)zHTTPServer method, overridden.g$@)racceptr)rrequestclient_addresss   rget_requestzLoopbackHttpServer.get_request.s6#'++"4"4"6
	4 ((rN)__name__
__module____qualname____doc__rrrrr	r	 s$
)rr	c"eZdZdZdZdZdZy)LoopbackHttpServerThreadz2Stoppable thread that runs a loopback http server.ctjj|d|_tj|_d|_td||_|jj|_
y)NFzHTTP/1.0)z	127.0.0.1r)	threadingThreadr_stop_serverEventreadyprotocol_versionr	httpdserver_portportrrequest_handlers  rrz!LoopbackHttpServerThread.__init__=sW!!$'!__&
+5('(8(79
JJ**	rcfd|_|j|jjy)z.Stops the webserver if it's currently running.TN)r%joinr)server_closers rstopzLoopbackHttpServerThread.stopFs%!		

!rc|jj|js(|jj	|js'yyN)r'setr%r)handle_requestr1s rrunzLoopbackHttpServerThread.runNs4

##JJ%%'##rN)rrrrrr2r7rrrr!r!:s<+"(rr!cFeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)DigestAuthHandlerz-Handler for performing digest authentication.cJd|_g|_i|_d|_d|_y)Nrz
Test Realmauth)_request_num_nonces_users_realm_name_qopr1s rrzDigestAuthHandler.__init__Xs''	rc||_yr4)r@)rqops  rset_qopzDigestAuthHandler.set_qop_s		rc6t|tsJ||_yr4)
isinstancedictr>)ruserss  r	set_userszDigestAuthHandler.set_usersbs%&&rc||_yr4)r?)rrealms  r	set_realmzDigestAuthHandler.set_realmfs
 rc|xjdz
c_tjt|jj	dj}|jj||S)Nascii)r<hashlibmd5strencode	hexdigestr=append)rnonces  r_generate_noncez!DigestAuthHandler._generate_nonceisWQC 1 1299'BCMMOE"rc
|jd}||dzd}|jd}i}|D]Q}|jd\}}|j}|ddk(r|ddk(r|dd}n|j}|||<S|S)N rM,=r")findsplitstrip)rauth_strfirst_space_indexparts	auth_dictpartnamevalues        r_create_auth_dictz#DigestAuthHandler._create_auth_dictos$MM#.-a/01s#		$D**S/KD%::<DQx359#3a
#IdO	$rci}|j|||d<||d<||d<d|z}tj|jdj	}d|z}tj|jdj	}	||d<|	|d<d	|z}
tj|
jdj	}||d
k(S)Npasswordmethoduriz#%(username)s:%(realm)s:%(password)srNz%(method)s:%(uri)sHA1HA2z3%(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)sresponse)updaterOrPrRrS)rrcrirjrk
final_dictHA1_strrlHA2_strrmresponse_strrns            r_validate_authz DigestAuthHandler._validate_auths
)$!)
:%
8
57*Dkk'..12<<>&3kk'..12<<>
5
546@A;;|227;<FFH9Z000rc
|jdd|jdd|jdd|jd|jd|j	d	|j|jjd
y)NizProxy Authentication RequiredContent-Type	text/htmlzProxy-AuthenticatezDigest realm="z", qop="z	",nonce="z", sProxy Authentication Required.F)
send_responsesend_headerr?r@rVend_headerswfilewriter,s  r_return_auth_challengez(DigestAuthHandler._return_auth_challenges}%%c+JK##NK@## 

tyy$*>*>*@#B	C	##%##$EFrcXt|jdk(ryd|jvr|j|S|j	|jd}|d|jvr|j|d}n|j|S|jd|jvr|j|S|jj|dd}|j|jfD]#}|j|||j|s"d}%|s|j|Sy)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-AuthorizationusernamerUF)lenr>headersr}rggetr=removepath
short_pathrtcommand)rr-rcriauth_validatedrs      rr6z DigestAuthHandler.handle_requests0t{{q  (?(??..??..''(=>I$3;;	*(=?22?CC==)T\\922?CC##Ig$67"N)--/I/IJ
*&&y'/'6'>'>'+-&*N
*"22?CCrN)
rrrrrrCrHrKrVrgrtr}r6rrrr9r9Us27!"1$
*rr9ceZdZdZdZdZdZedeZejejdjdZdZ
dZd	Zd
ZdZy)
BasicAuthHandlerz,Handler for performing basic authentication.testUsertestPassTest:rNc^tjjj|g|i|yr4)rrBaseHTTPRequestHandlerr)rargskwargss   rrzBasicAuthHandler.__init__s$**33DJ4J6Jrcyr4rrformatrs   rlog_messagezBasicAuthHandler.log_messagesrcj|jd|jdd|jy)NContent-typerw)rxryrzr1s rdo_HEADzBasicAuthHandler.do_HEADs,35rc|jd|jdd|jz|jdd|jy)NizWWW-AuthenticatezBasic realm="%s"rrw)rxryREALMrzr1s rdo_AUTHHEADzBasicAuthHandler.do_AUTHHEADsG3+-ADJJ-NO5rc|jjdds,|j|jj	dy|jjddd|j
zk(r=|j
d|j|jj	dy|jy)N
AuthorizationsNo Auth header receivedzBasic rsIt works)rrrr{r|ENCODED_AUTHrxrzr1s rdo_GETzBasicAuthHandler.do_GETs||4JJ78
\\

%(043D3D(DEs#JJ[)
rN)rrrrUSERPASSWDrUSER_PASSWDbase64	b64encoderRdecoderrrrrrrrrrrs`6D
FE!6*K#6##K$6$6w$?@GGPLK

rrc"eZdZdZdZdZdZy)FakeProxyHandlerzThis 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.
    cl||_tjjj|g|i|yr4)digest_auth_handlerrrrr)rrrrs    rrzFakeProxyHandler.__init__s.$7 **33DJ4J6Jrcyr4rrs   rrzFakeProxyHandler.log_messages	
rctjj|jd\}}}}}}||_|j
j
|r|jdd|jdd|j|jjtd|jzd|jjdyy)	NrrOKrvrwzYou've reached %s!<BR>rNsFOur apologies, but our server is down due to a sudden zombie invasion.)
urllibparseurlparserrrr6rxryrzr{r|bytes)rscmnetlocrparamsqueryfragments       rrzFakeProxyHandler.do_GETs7=||7L7LIIv84fdFE8##2248sD)^[9JJU#;dii#G#*,
-JJ:
;
9rN)rrrrrrrrrrrrsK
;rrcJeZdZdZdZdZdZfdZdZfdZ	dZ
d	ZxZS)
BasicAuthTestsrr	Incorrectrc>tt|d}t||_|j|jd|jjz|_|jj|jjjy)Nct|i|Sr4)r)rrs  r#http_server_with_basic_auth_handlerzABasicAuthTests.setUp.<locals>.http_server_with_basic_auth_handler$s#T4V44rzhttp://127.0.0.1:%s)superrsetUpr!r
addCleanupstop_serverr+
server_urlstartr'wait)rr	__class__s  rrzBasicAuthTests.setUp!sp
nd)+	5./RS(()/$++2B2BB rcF|jjd|_yr4rr2r1s rrzBasicAuthTests.stop_server,rc*tt|yr4)rrtearDown)rrs rrzBasicAuthTests.tearDown0s
nd,.rc$tjj}|j|j|j
|j|jtjjtjj|	|jtjj|j
y#tjj$r!|jd|j
zYywxYw)Nz!Basic auth failed for the url: %s)rrHTTPBasicAuthHandleradd_passwordrrrrinstall_openerbuild_opener
assertTrueurlopenerror	HTTPErrorfailrahs  rtest_basic_auth_successz&BasicAuthTests.test_basic_auth_success3s
^^
0
0
2


DOOTYYL%%fnn&A&A"&EF	MOOFNN224??CD||%%	MII9DOOKL	Ms8C;DDctjj}|j|j|j
|j|jtjjtjj||jtjjtjj|j
yr4)rrrrrrrINCORRECT_PASSWDrrassertRaisesrrrrs  rtest_basic_auth_httperrorz(BasicAuthTests.test_basic_auth_httperror<s
^^
0
0
2


DOOTYY@U@UV%%fnn&A&A"&EF&,,00&..2H2H$//Zr)
rrrrrrrrrrrr
__classcell__rs@rrrs3D
F"E	!/M[rrrP)opensslcLeZdZdZdZdZdZfdZdZdZ	dZ
d	Zd
ZxZ
S)ProxyAuthTestszhttp://localhosttestertest123	TestRealmcttd}j|tj
j
dtj
d<dtj
d<t_jjjjijjjfd}t|_jj jj#jj$j'djj(z}t*j,j/d|i}t*j,j1_t*j,j5|j2_y)Nc~tjjtjj|yr4osenvironclearroold_environs rrestore_environz-ProxyAuthTests.setUp.<locals>.restore_environN$JJJJk*rrNO_PROXYno_proxyc6tjg|i|Sr4)rr)rrrs  rcreate_fake_proxy_handlerz7ProxyAuthTests.setUp.<locals>.create_fake_proxy_handlerYs#D$<$<NtNvNNrzhttp://127.0.0.1:%dr)rrrrrrcopyr9rrHrrrKrr!rrrr'rr+rrProxyHandlerProxyDigestAuthHandlerproxy_digest_handlerropener)rrr	proxy_urlhandlerrs`    rrzProxyAuthTests.setUpKs@
nd)+	+	
):;!#

:!#

:#4#6   **DIIt{{+CD  **4::6	O//HI(() )DKK,<,<<	..--v	.BC$*NN$I$I$K!nn11T..0rcF|jjd|_yr4rr1s rrzProxyAuthTests.stop_serverfrrc^|jj|j|j|j|j
dz|jjd|jtjj|jj|jy)Nbadr;)rrrURLrrrrCrrrrropenr1s r-test_proxy_with_bad_password_raises_httperrorz<ProxyAuthTests.test_proxy_with_bad_password_raises_httperrorjsw!!..tzz488/3yy$++e:K	M  ((0&,,00++**((	$rc|jjd|jtjj
|jj|jyNr;)	rrCrrrrrrrr1s r,test_proxy_with_no_password_raises_httperrorz;ProxyAuthTests.test_proxy_with_no_password_raises_httperrorrsD  ((0&,,00++**((	$rc~|jj|j|j|j|j
|jjd|jj|j5}|jr	|jrdddy#1swYyxYwr)rrrrrrrrCrrreadrresults  rtest_proxy_qop_auth_worksz(ProxyAuthTests.test_proxy_qop_auth_worksxs!!..tzz488/3yy$++	G  ((0
[[

dhh
'	6++-++-			s"B33B<c|jj|j|j|j|j
|jjd	|jj|j}|5|jr	|jrdddy#1swYyxYw#tjj$rYywxYw)Nzauth-int)rrrrrrrrCrrrrrURLErrorrs  r0test_proxy_qop_auth_int_works_or_throws_urlerrorz?ProxyAuthTests.test_proxy_qop_auth_int_works_or_throws_urlerrors!!..tzz488/3yy$++	G  ((4
	[[%%dhh/F
kkmkkm



||$$	
		s#%C
"B66B?C"!C")rrrrrrrrrrrrr	rrs@rrrCs5
CD
FE06$$rrcVGfddtjjS)Nc<eZdZdZgZgZdZdZdZfdZ	dZ
y)1GetRequestHandler.<locals>.FakeHTTPRequestHandlerz	TestHTTP/Pcp|j}|r$|jj|}||d}|r#yyr4)	send_headr{r|)rbodydones   rrz8GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_GETs5>>#Dzz''-DE{rc|jd}|jjt|}|j	|j
j
|y)NzContent-Length)rrfilerintrrequestsrT)rcontent_length	post_datas   rdo_POSTz9GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_POSTsC!\\*:;N

N(;<IKKMMM  +rc|j_|jj|jjd\}}}|j
||D]&\}}|j||d|jiz(|r$|jdd|j|S|jy)Nrr+rz
text/plain)
rheaders_receivedrrTrpoprxryr+rz)r
response_coderrheaderrfFakeHTTPRequestHandler	responsess      rrz;GetRequestHandler.<locals>.FakeHTTPRequestHandler.send_heads6:ll"3MM  ++4==+;(M7D}-#*
E  &1C)CD
E  >  "rcyr4r)rrs  rrz=GetRequestHandler.<locals>.FakeHTTPRequestHandler.log_messagesrN)rrrserver_versionrrr+rrrr)rrsrrrs,$	#	,
		rr)rrr)rrs`@rGetRequestHandlerr"s"#!C!C#L"!rceZdZdZfdZddZdZddZddZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZxZS)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.
    c*tt||jtj
jd}|j|tjjdtjd<dtjd<y)Nc~tjjtjj|yr4rrs rrz*TestUrlopen.setUp.<locals>.restore_environrr*rr)
rr$rrrr
urlcleanuprrr)rrrs  rrzTestUrlopen.setUpsd
k4&(	
112	+	
):;!$

:!$

:rcg}tjj||fi|}	|j|j	d|j|j
|j|jd|j|j|jdj|S#|jwxYw)Nrir)
rrrextend	readlinesrTreadlinercloser/)rurldatarlfs      rrzTestUrlopen.urlopensNN""377	
HHQ[[%&
HHQZZ\"
HHQVVD\"
HHQVVX
GGIxx{
GGIsA>CCcF|jjd|_yr4rr1s rrzTestUrlopen.stop_serverrrc8|dgdfg}t|}t||_|j|j|jj|jjj|jj}||_|S)Nrs
we don't care)	r"r!rrrrr'rr+)rrrr+s    rstart_serverzTestUrlopen.start_serversr#345I#I..w7(() {{rcttjds|jdddlm}|dgdfg}t
|}||fd|i|}|j|_|S)NHTTPSHandlerzssl support requiredr)make_https_serverr
we care a bit
handler_class)hasattrrrskipTesttest.ssl_serversr7r"r+)rrrr7rrs      rstart_https_serverzTestUrlopen.start_https_serversdv~~~6MM016r#345I#I."4IwI&I{{rcd}ddgdfdg|fg}|j|}|jd|jz}|j|||j|jddgy)	NsWe got here...i.)Locationz(http://localhost:%(port)s/somewhere_elserrhttp://localhost:%s//z/somewhere_elser4rr+assertEqualr)rexpected_responserrr/s     rtest_redirectionzTestUrlopen.test_redirections-
KL


"'(
	##I.||2W\\AB01))C1B+CDrcd}d}ddg|fg}|j|}|jd|jz}|j||y)Nshello worldsa
hello worl
1
d
0
r)zTransfer-Encodingchunkedr@)r4rr+rC)rrD
chunked_startrnrr/s      rtest_chunkedzTestUrlopen.test_chunked	s`*!	;<mLM##H-||2W\\AB01rcd}|jdg|fg}	|jd|jz|jd|j||j|jdgy#tj
j$r*}|j}|jYd}~rd}~wwxYw)NsBad bad bad...izhttp://localhost:%s/weeblez404 should raise URLErrorz/weeble)r4rr+rrrrrr-rCr)rrDrr1r/s     rtest_404zTestUrlopen.test_404s-##c2/@%A$BC	3LL5DE

II1201))I;7||$$	668D
GGII	sA88B? B::B?cd}|jdg|fg}|jd|jz}|j|||j|jdgy)N
pycon 2008...rhttp://localhost:%s/bizarre/bizarrerBrrDrr/s    rtest_200zTestUrlopen.test_200&sd,##c2/@%A$BC||9GLLHI01))J<8rcd}|jdg|fg}|jd|jzd}|j|||j|jddgy)NrMrrNsget=with_feelingrOrBrPs    rtest_200_with_parametersz$TestUrlopen.test_200_with_parameters-sm,##c2/@%A$BC||9GLLH0201))J8K+LMrc|j}tjt}|j	d|j
z|}|j
|dy)Ncafilehttps://localhost:%s/bizarrecontextr8)r=sslcreate_default_contextCERT_localhostrr+rC)rrrYr/s    r
test_httpszTestUrlopen.test_https5sN))+,,NC||:W\\ISZ|[/0rc|jt}tjdtf5|jd|jzt}|j|d|jtjj5}|jd|jztddd|jt}|jtjj5}|jd|jztddddddy#1swY~xYw#1swYxYw#1swYyxYw)NcertfilerrWrUr8)
r=r\rcheck_warningsDeprecationWarningrr+rCrrrrCERT_fakehostname)rrr/cms    rtest_https_with_cafilez"TestUrlopen.test_https_with_cafile;s*))>)B

+
+R1C,D
E
	7<< > M'5 7DT#34""6<<#8#89
7R;gllJ$57
7--7H-IG""6<<#8#89
7R;gllJ$57
7
	7
	7
7
7

7
7
	7
	7s=A E%D47AE>%E#E4D=	9EE		EEcL|jt}tjdtf5|jtjj5}|jd|jzdddddddy#1swYxYw#1swYyxYw)Nr_rrWT)	cadefault)r=r\rrarbrrrrrr+)rrrds   rtest_https_with_cadefaultz%TestUrlopen.test_https_with_cadefaultLs))>)B

+
+R1C,D
E	-""6<<#8#89
-R;gllJ'+-
-	-	-
-
-	-	-s#*B!B=BB	BB#ct|jdtjs|jddfd}tjtj}|j||j
|t}tjt}|jd|jz||jdy)	Nzssl module requiredzSNI support required in OpenSSLc
|yr4r)ssl_sockserver_nameinitial_contextsni_names   rcb_sniz*TestUrlopen.test_https_sni.<locals>.cb_sniZs"Hr)rYr`rUzhttps://localhost:%srX	localhost)rZr;HAS_SNI
SSLContextPROTOCOL_TLS_SERVERset_servername_callbackr=r\r[rr+rC)rrorYrrns    @rtest_https_snizTestUrlopen.test_https_sniTs;MM/0{{MM;<	#..!8!89''/))'N)S,,NC+gll:GL;/rc,|j}tjjd|jzddi}tjj|5	ddd|j
|jddy#1swY)xYw)Nr@Rangezbytes=20-39r)r4rrRequestr+rrCrrrreqs   rtest_sending_headersz TestUrlopen.test_sending_headersds##%nn$$%;gll%J.5}-E%G
^^
#
#C
(		11':MJ		s B

Bc|j}tjjd|jzddi}tjj|5	ddd|j
d|jj|jd|jjy#1swY^xYw)Nr@z
X-SoMe-hEaderfoobarrxz
X-Some-Header)
r4rrryr+rassertInrkeysassertNotInrzs   rtest_sending_headers_camelz&TestUrlopen.test_sending_headers_camells##%nn$$%;gll%J.=x-H%J
^^
#
#C
(		

ow'?'?'D'D'FG'*B*B*G*G*IJ		s B??Cc2|j}tjjd|jz5}dD]!}|jt
||d|z#|j|jddddy#1swYyxYw)Nhttp://localhost:%s)rr-infogeturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r4rrrr+rr:r)rropen_urlattrs    r
test_basiczTestUrlopen.test_basicus##%
^^
#
#$9GLL$H
I	FX;
F$ 7:>@D:EF
F
OOHMMO-DE		F	F	FsAB

Bc`|j}tjjd|jz}|5|j}ddd|j
tjjd|j|jdy#1swYUxYw)NrzEobject returned by 'info' is not an instance of email.message.Messageplain)r4rrrr+rassertIsInstanceemailmessageMessagerCget_content_subtype)rrrinfo_objs    r	test_infozTestUrlopen.test_info}s##%>>))!GLL02
	'}}H	'h

(=(=B	C	
557A	'	'sB$$B-c|j}tjjd|jz}|5|j}ddd|j
d|jzy#1swY)xYw)Nr)r4rrrr+rrC)rrrr.s    rtest_geturlzTestUrlopen.test_geturlsl##%>>))*?',,*NO
	$//#C	$3gllBC	$	$sA88Bcd}|jdg|fg}tjjd|jz}|D]}|j||y)NrMrr)r4rrrr+rC)rrDrr/lines     rtest_iterationzTestUrlopen.test_iterationsa,##c2/@%A$BC~~%%&;gll&JK	6DT#45	6rc
dddddzdzg}dj|}|jdg|fg}tjj	d	|j
z}t
|D]9\}}|j|||d
|dt||dt|;|jd
zt|y)NsWe
sgot
shere
s	verylong i 
rrrzFetched line number z1 doesn't match expected:
    Expected length was z, got rM)	r/r4rrrr+	enumeraterCr)rlinesrDrr/indexrs       rtest_line_iterationzTestUrlopen.test_line_iterations(I|d/BU/JKHHUO##c2/@%A$BC~~%%&;gll&JK$T?	DKE4T5<$Su%6D	C
D	D
	
CJ/rcz|jdgdfdgdfg}tjj}tjj	d|j
z}|j
d|j|j|djd|j
d|j|j
d|jd|j|djd|j
d	|j|j
d
|jdy)Nrsanyr1zus-ascii1zContent-length
1234567890s
123456789010)r4rrrryr+rCr/rrR
get_header)rrrrs    rtest_issue16464zTestUrlopen.test_issue16464s##
"f
"f%
,,...(()>)MNw||,GSZZ
34w||,g001ABCG\00<=5w112BCDrr4)rrrrrrrr4r=rErIrKrQrSr]rerhrur|rrrrrrrrrs@rr$r$s~%	E2
89N17"-0 KKF	BD6
0Err$cttj}tjtjg|yr4)rthreading_setupunittestaddModuleCleanupthreading_cleanup)thread_infos rsetUpModulers*"224K.@@O;Or__main__)-rrrurllib.parserurllib.requesthttp.serverrr#rrOtestrtest.supportrrrrZImportErrorrequires_working_socketrdirname__file__herer/r\rcrr
r	r$r!r9rrrTestCaserrequires_hashdigestrr"r$rrmainrrr<module>rs
	')( t,	wwx dM2GGLL~6
)//)4(y//(6vvr&t{{99&X;t{{99;B%[X&&%[P$##E48JX&&J9JZ("VxE(##xEtP
zHMMOS
CsFF#"F#