python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_urllib2_localnet.cpython-312.opt-2.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.pemceZdZ	dZdZy)LoopbackHttpServerctjjj||||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#ch	|jj\}}|jd||fS)Ng$@)racceptr)rrequestclient_addresss   rget_requestzLoopbackHttpServer.get_request.s7,"&++"4"4"6
	4 ((rN)__name__
__module____qualname__rrrrr	r	 s$
)rr	c eZdZ	dZdZdZy)LoopbackHttpServerThreadctjj|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**	rch	d|_|j|jjy)NT)r$joinr(server_closers rstopzLoopbackHttpServerThread.stopFs&< 		

!rc|jj|js(|jj	|js'yyN)r&setr$r(handle_requestr0s rrunzLoopbackHttpServerThread.runNs4

##JJ%%'##rN)rrrrr1r6rrrr r :s<+"(rr cDeZdZ	dZdZdZdZdZdZdZ	dZ
d	Zy
)DigestAuthHandlercJd|_g|_i|_d|_d|_y)Nrz
Test Realmauth)_request_num_nonces_users_realm_name_qopr0s rrzDigestAuthHandler.__init__Xs''	rc||_yr3)r?)rqops  rset_qopzDigestAuthHandler.set_qop_s		rc||_yr3)r=)ruserss  r	set_userszDigestAuthHandler.set_usersbs	rc||_yr3)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 rJ,=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)srKz%(method)s:%(uri)sHA1HA2z3%(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)sresponse)updaterLrMrOrP)rr`rfrgrh
final_dictHA1_strriHA2_strrjresponse_strrks            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?rSend_headerswfilewriter+s  r_return_auth_challengez(DigestAuthHandler._return_auth_challenges}%%c+JK##NK@## 

tyy$*>*>*@#B	C	##%##$EFrcZ	t|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)NrTzProxy-AuthorizationusernamerRF)lenr=headersrzrdgetr<removepath
short_pathrqcommand)rr,r`rfauth_validatedrs      rr5z DigestAuthHandler.handle_requests5	t{{q  (?(??..??..''(=>I$3;;	*(=?22?CC==)T\\922?CC##Ig$67"N)--/I/IJ
*&&y'/'6'>'>'+-&*N
*"22?CCrN)rrrrrBrErHrSrdrqrzr5rrrr8r8Us27!"1$
*rr8ceZdZ	dZdZdZedeZejejdjdZdZdZ
dZd	Zd
Zy)BasicAuthHandlertestUsertestPassTest:rKc^tjjj|g|i|yr3)rrBaseHTTPRequestHandlerr)rargskwargss   rrzBasicAuthHandler.__init__s$**33DJ4J6Jrcyr3rrformatrs   rlog_messagezBasicAuthHandler.log_messagesrcj|jd|jdd|jy)NContent-typert)rurvrwr0s rdo_HEADzBasicAuthHandler.do_HEADs,35rc|jd|jdd|jz|jdd|jy)NizWWW-AuthenticatezBasic realm="%s"rrt)rurvREALMrwr0s 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)r~rrrxryENCODED_AUTHrurwr0s rdo_GETzBasicAuthHandler.do_GETs||4JJ78
\\

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

rrc eZdZ	dZdZdZy)FakeProxyHandlercl||_tjjj|g|i|yr3)digest_auth_handlerrrrr)rrrrs    rrzFakeProxyHandler.__init__s.$7 **33DJ4J6Jrcyr3rrs   rrzFakeProxyHandler.log_messages	
rctjj|jd\}}}}}}||_|j
j
|r|jdd|jdd|j|jjtd|jzd|jjdyy)	NrrOKrsrtzYou've reached %s!<BR>rKsFOur apologies, but our server is down due to a sudden zombie invasion.)
urllibparseurlparserrrr5rurvrwrxrybytes)rscmnetlocrparamsqueryfragments       rrzFakeProxyHandler.do_GETs7=||7L7LIIv84fdFE8##2248sD)^[9JJU#;dii#G#*,
-JJ:
;
9rN)rrrrrrrrrrrsK
;rrcJeZdZdZdZdZdZfdZdZfdZ	dZ
d	ZxZS)
BasicAuthTestsrr	Incorrectrc>tt|d}t||_|j|jd|jjz|_|jj|jjjy)Nct|i|Sr3)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|_yr3rr1r0s rrzBasicAuthTests.stop_server,rc*tt|yr3)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
yr3)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[rrrM)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|yr3osenvironclearrlold_environs rrestore_environz-ProxyAuthTests.setUp.<locals>.restore_environN$JJJJk*rrNO_PROXYno_proxyc6tjg|i|Sr3)rr)rrrs  rcreate_fake_proxy_handlerz7ProxyAuthTests.setUp.<locals>.create_fake_proxy_handlerYs#D$<$<NtNvNNrzhttp://127.0.0.1:%dr)rrrrrrcopyr8rrErrrHrr 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|_yr3rr0s rrzProxyAuthTests.stop_serverfrrc^|jj|j|j|j|j
dz|jjd|jtjj|jj|jy)Nbadr:)rrrURLrrrrBrrrrropenr0s 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:)	rrBrrrrrrrr0s 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)rrrrrrrrBrrreadrresults  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)rrrrrrrrBrrrrrURLErrorrs  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")rrrrrrrrrrrrrrrs@rrrCs5
CD
FE06$$rrcVGfddtjjS)Nc<eZdZdZgZgZdZdZdZfdZ	dZ
y)1GetRequestHandler.<locals>.FakeHTTPRequestHandlerz	TestHTTP/Pcp|j}|r$|jj|}||d}|r#yyr3)	send_headrxry)rbodydones   rrz8GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_GETs5>>#Dzz''-DE{rc|jd}|jjt|}|j	|j
j
|y)NzContent-Length)r~rfilerintrrequestsrQ)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)
r~headers_receivedrrQrpoprurvr*rw)r
response_coder~r
headerrcFakeHTTPRequestHandler	responsess      rrz;GetRequestHandler.<locals>.FakeHTTPRequestHandler.send_heads6:ll"3MM  ++4==+;(M7D}-#*
E  &1C)CD
E  >  "rcyr3r)rrs  rrz=GetRequestHandler.<locals>.FakeHTTPRequestHandler.log_messagesrN)rrrserver_versionrrr*rrrr)rrsrrr	s,$	#	,
		rr)rrr)rrs`@rGetRequestHandlerrs"#!C!C#L"!rceZdZ	fdZddZdZddZddZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZxZS)TestUrlopenc*tt||jtj
jd}|j|tjjdtjd<dtjd<y)Nc~tjjtjj|yr3rrs 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	readlinesrQreadlinercloser.)rurldatarlfs      rrzTestUrlopen.urlopensNN""377	
HHQ[[%&
HHQZZ\"
HHQVVD\"
HHQVVX
GGIxx{
GGIsA>CCcF|jjd|_yr3rr0s rrzTestUrlopen.stop_serverrrc8|dgdfg}t|}t||_|j|j|jj|jjj|jj}||_|S)Nrs
we don't care)	rr 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_serversr4rr*)rrrr4rr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_elser1rr*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=)r1rr*r@)rrA
chunked_startrkrr,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)r1rr*rrrrrr*r@r)rrArr.r,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/bizarrer?rrArr,s    rtest_200zTestUrlopen.test_200&sd,##c2/@%A$BC||9GLLHI01))J<8rcd}|jdg|fg}|jd|jzd}|j|||j|jddgy)NrJrrKsget=with_feelingrLr?rMs    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/bizarrecontextr5)r:sslcreate_default_contextCERT_localhostrr*r@)rrrVr,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)NcertfilerrTrRr5)
r:rYrcheck_warningsDeprecationWarningrr*r@rrrrCERT_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\rrTT)	cadefault)r:rYrr^r_rrrrrr*)rrras   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
|yr3r)ssl_sockserver_nameinitial_contextsni_names   rcb_sniz*TestUrlopen.test_https_sni.<locals>.cb_sniZs"Hr)rVr]rRzhttps://localhost:%srU	localhost)rWr8HAS_SNI
SSLContextPROTOCOL_TLS_SERVERset_servername_callbackr:rYrXrr*r@)rrlrVrrks    @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~)r1rrRequestr*rr@rrrreqs   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-hEaderfoobarruz
X-Some-Header)
r1rrrvr*rassertInrkeysassertNotInrws   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)r1rrrr*rr7r)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)r1rrrr*rassertIsInstanceemailmessageMessager@get_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)r1rrrr*rr@)rrrr+s    rtest_geturlzTestUrlopen.test_geturlsl##%>>))*?',,*NO
	$//#C	$3gllBC	$	$sA88Bcd}|jdg|fg}tjjd|jz}|D]}|j||y)NrJrr)r1rrrr*r@)rrArr,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 rJ)	r.r1rrrr*	enumerater@r})rlinesrArr,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)r1rrrrvr*r@r,rrO
get_header)rrrrs    rtest_issue16464zTestUrlopen.test_issue16464s##
"f
"f%
,,...(()>)MNw||,GSZZ
34w||,g001ABCG\00<=5w112BCDrr3)rrrrrrr1r:rBrFrHrNrPrZrbrerrryrrrrrrrrrs@rr!r!s~%	E2
89N17"-0 KKF	BD6
0Err!cttj}tjtjg|yr3)rthreading_setupunittestaddModuleCleanupthreading_cleanup)thread_infos rsetUpModulers*"224K.@@O;Or__main__)-rrrurllib.parserurllib.requesthttp.serverrr"rrLtestrtest.supportrrrrWImportErrorrequires_working_socketrdirname__file__herer.rYr`rr
r	r#r r8rrrTestCaserrequires_hashdigestrrr!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#