tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
R\¬Qc@s?ddlZddlZddlZddlZddlZddlmZejddeƒZ    ejdƒZ
dej fd„ƒYZ de
j fd    „ƒYZd
dd „ƒYZd ejfd „ƒYZdejfd„ƒYZdefd„ƒYZd„Zdefd„ƒYZd„Zedkr;eƒndS(iÿÿÿÿN(t test_supportt    mimetoolst
deprecatedt    threadingtLoopbackHttpServercBs eZdZd„Zd„ZRS(s^HTTP server w/ a few modifications that make it useful for
    loopback testing purposes.
    cCs*tjj|||ƒ|jjdƒdS(Ngð?(tBaseHTTPServert
HTTPServert__init__tsockett
settimeout(tselftserver_addresstRequestHandlerClass((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRs cCs,|jjƒ\}}|jdƒ||fS(s"BaseHTTPServer method, overridden.g$@(RtacceptR    (R
trequesttclient_address((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt get_requests (t__name__t
__module__t__doc__RR(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRs        tLoopbackHttpServerThreadcBs)eZdZd„Zd„Zd„ZRS(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_versionRthttpdt server_porttport(R
trequest_handler((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR-s         cCst|_|jƒdS(s.Stops the webserver if it's currently running.N(tTrueRtjoin(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytstop8s    cCs.|jjƒx|js)|jjƒqWdS(N(RtsetRRthandle_request(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytrun@s  (RRRRR!R$(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR*s        tDigestAuthHandlercBs_eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z    d„Z
d    „Z RS(
s-Handler for performing digest authentication.cCs1d|_g|_i|_d|_d|_dS(Nis
Test Realmtauth(t _request_numt_noncest_userst _realm_namet_qop(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRJs
                cCs ||_dS(N(R+(R
tqop((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytset_qopQscCs"t|tƒst‚||_dS(N(t
isinstancetdicttAssertionErrorR)(R
tusers((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt    set_usersTscCs ||_dS(N(R*(R
trealm((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt    set_realmXscCsA|jd7_tjt|jƒƒjƒ}|jj|ƒ|S(Ni(R'thashlibtmd5tstrt    hexdigestR(tappend(R
tnonce((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt_generate_nonce[scCs®|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((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt_create_auth_dictas    c Cs°i}|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(tupdateR5R6R8( R
RFRKRLRMt
final_dicttHA1_strRNtHA2_strROt response_strRP((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt_validate_authrs 
 
 
 
 
 
 
cCsg|jddƒ|jddƒ|jdd|j|j|jƒfƒ|jƒ|jjdƒtS(Ni—sProxy Authentication Requireds Content-Types    text/htmlsProxy-Authenticates(Digest realm="%s", qop="%s",nonce="%s", sProxy Authentication Required.(    t send_responset send_headerR*R+R;t end_headerstwfiletwriteR(R
R((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt_return_auth_challenge„s
cCst|jƒdkrtSd|jkr5|j|ƒS|j|jdƒ}|d|jkrr|j|d}n |j|ƒS|jdƒ|jkr¤|j|ƒS|jj|dƒt    }x>|j
|j gD]*}|j |||j |ƒrÑt}qÑqÑW|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-AuthorizationtusernameR:N(tlenR)RtheadersR\RJtgetR(tremoveRtpatht
short_pathRVtcommand(R
RRFRKtauth_validatedRb((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR#“s,                 ( RRRRR-R2R4R;RJRVR\R#(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR%Gs                                tFakeProxyHandlercBs)eZdZd„Zd„Zd„ZRS(sÏ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#||_tjj|||ŽdS(N(tdigest_auth_handlerRtBaseHTTPRequestHandlerR(R
Rgtargstkwargs((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRÈs    cGsdS(N((R
tformatRi((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt log_messageÎscCsštj|jdƒ\}}}}}}||_|jj|ƒr–|jddƒ|jddƒ|jƒ|jj    d|jƒ|jj    dƒndS(NthttpiÈtOKs Content-Types    text/htmlsYou've reached %s!<BR>sFOur apologies, but our server is down due to a sudden zombie invasion.(
turlparseRbRcRgR#RWRXRYRZR[(R
tscmtnetlocRbtparamstquerytfragment((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytdo_GETÓs!    
(RRRRRlRu(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRfÁs        t BaseTestCasecBseZd„Zd„ZRS(cCstjƒ|_dS(N(Rtthreading_setupt_threads(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytsetUpâscCstj|jŒdS(N(Rtthreading_cleanupRx(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttearDownås(RRRyR{(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRvás    tProxyAuthTestscBsVeZdZdZdZdZd„Zd„Zd„Zd„Z    d„Z
d    „Z RS(
shttp://localhostttesterttest123t    TestRealmcsÛttˆƒjƒtƒˆ_ˆjjiˆjˆj6ƒˆjjˆj    ƒ‡fd†}t
|ƒˆ_ ˆj j ƒˆj j jƒdˆj j}tji|d6ƒ}tjƒˆ_tj|ˆjƒˆ_dS(Ncstˆj||ŽS(N(RfRg(RiRj(R
(sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytcreate_fake_proxy_handlerõsshttp://127.0.0.1:%dRm(tsuperR|RyR%RgR2tPASSWDtUSERR4tREALMRtservertstartRtwaitRturllib2t ProxyHandlertProxyDigestAuthHandlertproxy_digest_handlert build_openertopener(R
R€t    proxy_urlthandler((R
sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRyðs  cCs$|jjƒtt|ƒjƒdS(N(R…R!RR|R{(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR{s cCs\|jj|j|j|j|jdƒ|jjdƒ|jt    j
|j j |jƒdS(NtbadR&( R‹t add_passwordR„tURLRƒR‚RgR-t assertRaisesRˆt    HTTPErrorRtopen(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt-test_proxy_with_bad_password_raises_httperrors      cCs3|jjdƒ|jtj|jj|jƒdS(NR&(RgR-R“RˆR”RR•R’(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt,test_proxy_with_no_password_raises_httperror s     cCsk|jj|j|j|j|jƒ|jjdƒ|jj    |jƒ}x|j
ƒr\qMW|j ƒdS(NR&( R‹R‘R„R’RƒR‚RgR-RR•treadtclose(R
tresult((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_proxy_qop_auth_worksscCs•|jj|j|j|j|jƒ|jjdƒy|jj    |jƒ}Wnt
j k
rjd}nX|r‘x|j ƒrƒqtW|jƒndS(Nsauth-int(R‹R‘R„R’RƒR‚RgR-RR•RˆtURLErrortNoneR˜R™(R
Rš((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt0test_proxy_qop_auth_int_works_or_throws_urlerrors
( RRR’RƒR‚R„RyR{R–R—R›Rž(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR|és                        cs&dtjf‡‡fd†ƒY‰ˆS(NtFakeHTTPRequestHandlercsMeZdZgZgZdZd„Zd„Z‡‡fd†Zd„Z    RS(s    TestHTTP/iPcSs)|jƒ}|r%|jj|ƒndS(N(t    send_headRZR[(R
tbody((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRu5s cSsC|jd}|jjt|ƒƒ}|jƒ|jj|ƒdS(NsContent-Length(R_trfileR˜tintRutrequestsR9(R
tcontent_lengtht    post_data((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytdo_POST:s 
cs¤|jˆ_|jj|jƒˆjdƒ\}}}|j|ƒx+|D]#\}}|j|||jƒqKW|r–|jddƒ|j    ƒ|S|j    ƒdS(Nis Content-types
text/plain(
R_theaders_receivedR¤R9RbtpopRWRXRRY(R
t response_codeR_R¡theaderRI(RŸt    responses(sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR @s  
cWsdS(N((R
Ri((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRlOs(
RRtserver_versionR¤R¨RRuR§R Rl((RŸR¬(sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRŸ.s        (RRh(R¬((RŸR¬sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytGetRequestHandler,s"%t TestUrlopencBsƒeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z    d„Z
d    „Z d
„Z d „Z d „Zd „ZRS(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|ƒjƒdS(N(RˆR‰RŒtinstall_openerRR¯Ry(R
t proxy_handlerR((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyRy_s cCsQt|ƒ}t|ƒ|_|jjƒ|jjjƒ|jj}||_|S(N(R®RR…R†RR‡R(R
R¬RR((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt start_serveres       cCs¤d}dd
gdfdg|fg}|j|ƒ}zYtjd|jƒ}|jƒ}|jƒ|j||ƒ|j|jdd    gƒWd|jj    ƒXdS( NsWe got here...i.tLocations"http://localhost:%s/somewhere_elsetiÈshttp://localhost:%s/t/s/somewhere_else(R³s"http://localhost:%s/somewhere_else(
R²RˆturlopenRR˜R™t assertEqualR¤R…R!(R
texpected_responseR¬Rtftdata((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_redirectionps 
cCs´d}|jdg|fgƒ}z~ytjd|jƒWntjk
rT}nX|jdƒ|jƒ}|jƒ|j||ƒ|j|j    dgƒWd|j
j ƒXdS(NsBad bad bad...i”shttp://localhost:%s/weebles404 should raise URLErrors/weeble( R²RˆR¶RRœtfailR˜R™R·R¤R…R!(R
R¸RR¹Rº((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_404„s  
cCsŒd}|jdg|fgƒ}zVtjd|jƒ}|jƒ}|jƒ|j||ƒ|j|jdgƒWd|jj    ƒXdS(Ns pycon 2008...iÈshttp://localhost:%s/bizarres/bizarre(
R²RˆR¶RR˜R™R·R¤R…R!(R
R¸RR¹Rº((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_200™s 
cCs’d}|jdg|fgƒ}z\tjd|jdƒ}|jƒ}|jƒ|j||ƒ|j|jddgƒWd|jj    ƒXdS(Ns pycon 2008...iÈshttp://localhost:%s/bizarresget=with_feelings/bizarre(
R²RˆR¶RR˜R™R·R¤R…R!(R
R¸RR¹Rº((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_200_with_parameters§s 
cCs{|jdgdfgƒ}zKtjd|jdidd6ƒ}tj|ƒ|j|jddƒWd|jjƒXdS(NiÈs we don't careshttp://localhost:%s/R_s bytes=20-39tRange(    R²RˆtRequestRR¶R·R¨R…R!(R
Rtreq((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_sending_headers¶s cCs |jdgdfgƒ}zptjd|jƒ}x+d
D]#}|jt||ƒd|ƒq;Wz|j|jƒd    ƒWd|jƒXWd|jj    ƒXdS( NiÈs we don't careshttp://localhost:%sR˜R™tinfotgeturls3object returned from urlopen lacks the %s attributescalling 'read' failed(sreadsclosesinfosgeturl(
R²RˆR¶Rt
assertTruethasattrR˜R™R…R!(R
Rtopen_urltattr((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt
test_basicÁs  cCs‚|jdgdfgƒ}zRtjd|jƒ}|jƒ}|j|tjdƒ|j|j    ƒdƒWd|j
j ƒXdS(NiÈs we don't careshttp://localhost:%ssAobject returned by 'info' is not an instance of mimetools.Messagetplain( R²RˆR¶RRÄtassertIsInstanceRtMessageR·t
getsubtypeR…R!(R
RRÈtinfo_obj((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt    test_infoÐs cCsm|jdgdfgƒ}z=tjd|jƒ}|jƒ}|j|d|jƒWd|jjƒXdS(NiÈs we don't careshttp://localhost:%s(R²RˆR¶RRÅR·R…R!(R
RRÈturl((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt test_geturlÝs  cCs'tjdƒ|jttjdƒdS(Ntnetworkshttp://sadflkjsasf.i.nvali.d./(RtrequiresR“tIOErrorRˆR¶(R
((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_bad_addressés     cCsqd}|jdg|fgƒ}z;tjd|jƒ}x|D]}|j||ƒqAWWd|jjƒXdS(Ns pycon 2008...iÈshttp://localhost:%s(R²RˆR¶RR·R…R!(R
R¸RRºtline((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyttest_iterations c    CsÞddddddg}dj|ƒ}|jdg|fgƒ}zktjd    |jƒ}xNt|ƒD]@\}}|j|||d
|t||ƒt|ƒfƒqjWWd|jj    ƒX|j|d t|ƒƒdS( NsWe
sgot
shere
s    verylong i s
R´iÈshttp://localhost:%ssQFetched line number %s doesn't match expected:
    Expected length was %s, got %si(
R R²RˆR¶Rt    enumerateR·R^R…R!(R
tlinesR¸RRºtindexR×((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pytztest_line_iterations)(RRRRyR²R»R½R¾R¿RÃRÊRÐRÒRÖRØRÜ(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyR¯Vs                                                
cCstjttƒdS(N(Rt run_unittestR|R¯(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt    test_mainst__main__((RoRˆRtunittestR5ttestRt import_moduleRRRRRRRR%RhRftTestCaseRvR|R®R¯RÞR(((sb/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/test/test_urllib2_localnet.pyt<module>s$     z C    *È