%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python2.7/test/
Upload File :
Create Path :
Current File : //usr/local/lib/python2.7/test/test_urllib2_localnet.pyc


Nac@sddlZddlZddlZddlZddlZddlZddlZddlmZej	dde
Zej	dZyddl
Z
Wnek
rdZ
nXejjeZejjedZejjedZdejfd	YZd
ejfdYZdejfd
YZdddYZdejfdYZdejfdYZ de fdYZ!de fdYZ"dZ#de fdYZ$dZ%e&dkre%ndS(iN(ttest_supportt	mimetoolst
deprecatedt	threadingskeycert.pemskeycert2.pemtLoopbackHttpServercBs eZdZdZdZRS(s^HTTP server w/ a few modifications that make it useful for
    loopback testing purposes.
    cCs*tjj||||jjddS(Ng?(tBaseHTTPServert
HTTPServert__init__tsockett
settimeout(tselftserver_addresstRequestHandlerClass((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR scCs,|jj\}}|jd||fS(s"BaseHTTPServer method, overridden.g$@(RtacceptR	(R
trequesttclient_address((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytget_request)s
(t__name__t
__module__t__doc__RR(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs		tLoopbackHttpServerThreadcBs)eZdZdZdZdZRS(s2Stoppable thread that runs a loopback http server.cCsVtjj|t|_tj|_d|_td||_	|j	j
|_dS(NsHTTP/1.0s	127.0.0.1i(s	127.0.0.1i(RtThreadRtFalset_stoptEventtreadytprotocol_versionRthttpdtserver_porttport(R
trequest_handler((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR8s		cCst|_|jdS(s.Stops the webserver if it's currently running.N(tTrueRtjoin(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytstopCs	cCs.|jjx|js)|jjqWdS(N(RtsetRRthandle_request(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytrunKs
(RRRRR!R$(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR5s		tBasicAuthHandlercBsleZdZdZdZdZdeefZejeZ	dZ
dZdZdZ
d	ZRS(
s,Handler for performing Basic Authentication.ttestUserttestPasstTests%s:%scOstjj|||dS(N(RtBaseHTTPRequestHandlerR(R
targstkwargs((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR\scGsdS(N((R
tformatR*((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytlog_message_scCs+|jd|jdd|jdS(NisContent-types	text/html(t
send_responsetsend_headertend_headers(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytdo_HEADcs
cCsB|jd|jdd|j|jdd|jdS(NisWWW-AuthenticatesBasic realm="%s"sContent-types	text/html(R.R/tREALMR0(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytdo_AUTHHEADhs
cCsu|jjddkr5|j|jjdn<|jjdd|jkrg|jjdn
|jdS(Nt
AuthorizationsNo Auth Header ReceivedsBasic s	It works!(theaderst	getheadertNoneR3twfiletwritetENCODED_AUTH(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytdo_GETns
	(RRRtUSERtPASSWDR2tUSER_PASSWDtbase64t	b64encodeR:RR-R1R3R;(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR%Ss				tDigestAuthHandlercBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s-Handler for performing digest authentication.cCs1d|_g|_i|_d|_d|_dS(Nis
Test Realmtauth(t_request_numt_noncest_userst_realm_namet_qop(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR}s
				cCs
||_dS(N(RG(R
tqop((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytset_qopscCs"t|tst||_dS(N(t
isinstancetdicttAssertionErrorRE(R
tusers((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt	set_usersscCs
||_dS(N(RF(R
trealm((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt	set_realmscCsA|jd7_tjt|jj}|jj||S(Ni(RCthashlibtmd5tstrt	hexdigestRDtappend(R
tnonce((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt_generate_noncescCs|jd}||d}|jd}i}xu|D]m}|jd\}}|j}|ddkr|ddkr|dd!}n|j}|||<q9W|S(Nt it,t=it"i(tfindtsplittstrip(R
tauth_strtfirst_space_indextpartst	auth_dicttparttnametvalue((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt_create_auth_dicts
 cCsi}|j|||d<||d<||d<d|}tj|j}d|}tj|j}	||d<|	|d<d|}
tj|
j}||d	kS(
Ntpasswordtmethodturis#%(username)s:%(realm)s:%(password)ss%(method)s:%(uri)stHA1tHA2s3%(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)stresponse(tupdateRQRRRT(R
RbRgRhRit
final_dicttHA1_strRjtHA2_strRktresponse_strRl((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt_validate_auths







cCsg|jdd|jdd|jdd|j|j|jf|j|jjdtS(NisProxy Authentication RequiredsContent-Types	text/htmlsProxy-Authenticates(Digest realm="%s", qop="%s",nonce="%s", sProxy Authentication Required.(	R.R/RFRGRWR0R8R9R(R
R((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt_return_auth_challenges
cCst|jdkrtSd|jkr5|j|S|j|jd}|d|jkrr|j|d}n
|j|S|jd|jkr|j|S|jj|dt	}x>|j
|jgD]*}|j|||j
|rt}qqW|s|j|StSdS(sPerforms 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.
        isProxy-AuthorizationtusernameRVN(tlenRERR5RsRftgetRDtremoveRtpatht
short_pathRrtcommand(R
RRbRgtauth_validatedRx((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR#s,	


		

(RRRRRIRNRPRWRfRrRsR#(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRAzs								tFakeProxyHandlercBs)eZdZdZdZdZRS(sThis 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#||_tjj|||dS(N(tdigest_auth_handlerRR)R(R
R}R*R+((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs	cGsdS(N((R
R,R*((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR-scCstj|jd\}}}}}}||_|jj|r|jdd|jdd|j|jj	d|j|jj	dndS(NthttpitOKsContent-Types	text/htmlsYou've reached %s!<BR>sFOur apologies, but our server is down due to a sudden zombie invasion.(
turlparseRxRyR}R#R.R/R0R8R9(R
tscmtnetlocRxtparamstquerytfragment((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR;s!	
(RRRRR-R;(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR|s		tBaseTestCasecBseZdZdZRS(cCstj|_dS(N(Rtthreading_setupt_threads(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytsetUpscCs|jtj|jdS(N(t
doCleanupsRtthreading_cleanupR(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttearDowns
(RRRR(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs	tBasicAuthTestscBs;eZdZdZdZdZdZdZdZRS(R&R't	IncorrectR(cCsrtt|jd}t||_d|jj|_|jj|jjj	|j
|jjdS(Nc_s
t||S(N(R%(R*R+((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt#http_server_with_basic_auth_handler&sshttp://127.0.0.1:%s(tsuperRRRtserverRt
server_urltstartRtwaitt
addCleanupR!(R
R((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR#s	
cCstj}|j|j|j|j|jtjtj|y|j	tj
|jWn@tjk
r|jd|jnt
k
r}|nXdS(NsBasic Auth Failed for url: %s(turllib2tHTTPBasicAuthHandlertadd_passwordR2RR<R=tinstall_openertbuild_openert
assertTrueturlopent	HTTPErrortfailt	Exception(R
tahte((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_basic_auth_success.s"cCsdtj}|j|j|j|j|jtjtj||j	tj
tj|jdS(N(RRRR2RR<tINCORRECT_PASSWDRRtassertRaisesRR(R
R((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_basic_auth_httperror9s

(	RRR<R=RR2RRR(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs		tProxyAuthTestscBsMeZdZdZdZdZdZdZdZdZ	dZ
RS(	shttp://localhostttesterttest123t	TestRealmcs*ttjd}j|tjjdtjd<dtjd<t_jj	ij
j6jjj
fd}t|_jjjjjjjjdjj}tji|d6}tj_tj|j_dS(NcSs!tjjtjj|dS(N(tostenvirontclearRm(told_environ((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytrestore_environKs
ttNO_PROXYtno_proxycstj||S(N(R|R}(R*R+(R
(s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytcreate_fake_proxy_handlerVsshttp://127.0.0.1:%dR~(RRRRRRtcopyRAR}RNR=R<RPR2RRRRRR!RRtProxyHandlertProxyDigestAuthHandlertproxy_digest_handlerRtopener(R
RRt	proxy_urlthandler((R
s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRHs"	


cCs\|jj|j|j|j|jd|jjd|jt	j
|jj|jdS(NtbadRB(
RRR2tURLR<R=R}RIRRRRtopen(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt-test_proxy_with_bad_password_raises_httperrorbs	cCs3|jjd|jtj|jj|jdS(NRB(R}RIRRRRRR(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt,test_proxy_with_no_password_raises_httperrorjs	cCsk|jj|j|j|j|j|jjd|jj	|j}x|j
r\qMW|jdS(NRB(RRR2RR<R=R}RIRRtreadtclose(R
tresult((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_proxy_qop_auth_workspscCs|jj|j|j|j|j|jjdy|jj	|j}Wnt
jk
rjd}nX|rx|j
rqtW|jndS(Nsauth-int(RRR2RR<R=R}RIRRRtURLErrorR7RR(R
R((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt0test_proxy_qop_auth_int_works_or_throws_urlerrorys
(RRRR<R=R2RRRRR(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRAs					cs&dtjffdYS(NtFakeHTTPRequestHandlercsMeZdZgZgZdZdZdZfdZdZ	RS(s	TestHTTP/iPcSs)|j}|r%|jj|ndS(N(t	send_headR8R9(R
tbody((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR;scSsC|jd}|jjt|}|j|jj|dS(NsContent-Length(R5trfileRtintR;trequestsRU(R
tcontent_lengtht	post_data((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytdo_POSTs

cs|j_|jj|jjd\}}}|j|x+|D]#\}}|j|||jqKW|r|jdd|j	|S|j	dS(NisContent-types
text/plain(
R5theaders_receivedRRURxtpopR.R/RR0(R
t
response_codeR5RtheaderRe(Rt	responses(s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs

cWsdS(N((R
R*((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyR-s(
RRtserver_versionRRRR;RRR-((RR(s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs		(RR)(R((RRs6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytGetRequestHandlers"%tTestUrlopencBseZdZdZddZdZddZdZdZ	dZ
dZd	Zd
Z
dZdZd
ZdZdZdZdZdZdZRS(sGTests urllib2.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.
    cCsBtji}tj|}tj|tt|jdS(N(RRRRRRR(R
t
proxy_handlerR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs
cKsg}tj|||}zV|j|jd|j|j|j|jd|j|jWd|jXdj|S(NiiR(	RRtextendt	readlinesRUtreadlineRRR (R
turltdataR+tltf((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRscCsdt|}t||_|jj|jjj|j|jj|jj}||_|S(N(	RRRRRRRR!R(R
RRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytstart_servers
	cKsttds|jdnddlm}|dkrPdgdfg}nt|}||d||}|j|_|S(NtHTTPSHandlersssl support requiredi(tmake_https_serveris
we care a bitt
handler_class(thasattrRtskipTestttest.ssl_serversRR7RR(R
RR+RRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytstart_https_serverscCsd}dd
gdfdg|fg}|j|}tjd|j}|j}|j|j|||j|jdd	gdS(NsWe got here...i.tLocations"http://localhost:%s/somewhere_elseRishttp://localhost:%s/t/s/somewhere_else(Rs"http://localhost:%s/somewhere_else(RRRRRRtassertEqualR(R
texpected_responseRRRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_redirections
cCsd}|jdg|fg}ytjd|jWntjk
rQ}nX|jd|j}|j|j|||j|j	dgdS(NsBad bad bad...ishttp://localhost:%s/weebles404 should raise URLErrors/weeble(
RRRRRRRRRR(R
RRRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_404s

cCswd}|jdg|fg}tjd|j}|j}|j|j|||j|jdgdS(Ns
pycon 2008...ishttp://localhost:%s/bizarres/bizarre(RRRRRRRR(R
RRRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_200	s
cCs}d}|jdg|fg}tjd|jd}|j}|j|j|||j|jddgdS(Ns
pycon 2008...ishttp://localhost:%s/bizarresget=with_feelings/bizarre(RRRRRRRR(R
RRRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_200_with_parameterss
cCsN|j}tjdt}|jd|jd|}|j|ddS(Ntcafileshttps://localhost:%s/bizarretcontexts
we care a bit(Rtssltcreate_default_contexttCERT_localhostRRR(R
RRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt
test_httpssc	Cs|jdt}|jd|jdt}|j|d|jtj|jd|jdtWdQX|jdt}|jt	j
|jd|jdtWdQXdS(Ntcertfileshttps://localhost:%s/bizarreRs
we care a bit(RRRRRRRRtCERT_fakehostnameRtCertificateError(R
RR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_https_with_cafile%s	
cCsI|jdt}|jtj|jd|jdtWdQXdS(NRshttps://localhost:%s/bizarret	cadefault(RRRRRRRR(R
R((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_https_with_cadefault5scstdkr|jdntjs5|jdndgfd}tjtj}|j||jd|dt}tj	dt}|j
d|jd||jdd	dS(
Nsssl module requiredsSNI support required in OpenSSLcs|d<dS(Ni((tssl_socktserver_nametinitial_context(tsni_name(s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytcb_sniBsRRRshttps://localhost:%sit	localhost(
RR7RtHAS_SNIt
SSLContexttPROTOCOL_TLStset_servername_callbackRRRRRR(R
RRR((Rs6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_https_sni<s		
cCsf|jdgdfg}tjd|jdidd6}tj||j|jdddS(Nis
we don't careshttp://localhost:%s/R5sbytes=20-39tRange(RRtRequestRRRR(R
Rtreq((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_sending_headersKs

cCs|jdgdfg}tjd|j}x+d
D]#}|jt||d|q8Wz|j|jd	Wd|jXdS(Nis
we don't careshttp://localhost:%sRRtinfotgeturls3object returned from urlopen lacks the %s attributescalling 'read' failed(RRR	R
(RRRRRRRR(R
Rtopen_urltattr((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt
test_basicSs
cCsm|jdgdfg}tjd|j}|j}|j|tjd|j|j	ddS(Nis
we don't careshttp://localhost:%ssAobject returned by 'info' is not an instance of mimetools.Messagetplain(
RRRRR	tassertIsInstanceRtMessageRt
getsubtype(R
RRtinfo_obj((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt	test_info_scCsX|jdgdfg}tjd|j}|j}|j|d|jdS(Nis
we don't careshttp://localhost:%s(RRRRR
R(R
RRR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_geturliscCs'tjd|jttjddS(Ntnetworkshttp://sadflkjsasf.i.nvali.d./(RtrequiresRtIOErrorRR(R
((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_bad_addressrs
	cCs\d}|jdg|fg}tjd|j}x|D]}|j||q>WdS(Ns
pycon 2008...ishttp://localhost:%s(RRRRR(R
RRRtline((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyttest_iterations

c	Csddddddg}dj|}|jdg|fg}tjd	|j}xNt|D]@\}}|j|||d
|t||t|fqgW|j|dt|dS(NsWe
sgot
shere
s	verylong i s
Rishttp://localhost:%ssQFetched line number %s doesn't match expected:
    Expected length was %s, got %si(R RRRRt	enumerateRRu(R
tlinesRRRtindexR((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pytztest_line_iterations%N(RRRRR7RRRRRRRRRRRRR
RRRRR(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyRs(	
												
				cCstjtttdS(N(Rtrun_unittestRRR(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt	test_mainst__main__(('RR?RRRtunittestRQttestRt
import_moduleRRRRtImportErrorR7Rxtdirnamet__file__thereR RRRRRRR)R%RAR|tTestCaseRRRRRR R(((s6/usr/local/lib/python2.7/test/test_urllib2_localnet.pyt<module>s:

'z 	$I	*		

Zerion Mini Shell 1.0