ó {G_Tc@sxddlZddlZddlZddlZddlZddlZddlZejZddlmZej Z dfd„ƒYZ de fd„ƒYZ dejfd„ƒYZ d efd „ƒYZ d efd „ƒYZd efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZed„ZedkrteƒndS(iÿÿÿÿN(t test_supportt FakeSocketcBs;eZejddd„Zd„Zdd„Zd„ZRS(cCs1||_||_d|_||_||_dS(Nt(ttextt fileclasstdatathosttport(tselfRRRR((s-/usr/local/lib/python2.7/test/test_httplib.pyt__init__s     cCs|jdj|ƒ7_dS(NR(Rtjoin(RR((s-/usr/local/lib/python2.7/test/test_httplib.pytsendallscCs7|dkr'|dkr'tjƒ‚n|j|jƒS(Ntrtrb(thttplibtUnimplementedFileModeRR(Rtmodetbufsize((s-/usr/local/lib/python2.7/test/test_httplib.pytmakefilescCsdS(N((R((s-/usr/local/lib/python2.7/test/test_httplib.pytclosesN(t__name__t __module__tStringIOtNoneR R RR(((s-/usr/local/lib/python2.7/test/test_httplib.pyRs  t EPipeSocketcBs#eZd„Zd„Zd„ZRS(cCstj||ƒ||_dS(N(RR t pipe_trigger(RRR((s-/usr/local/lib/python2.7/test/test_httplib.pyR $scCs:|j|kr'tjtjdƒ‚n|j|7_dS(Ntgotcha(RtsocketterrorterrnotEPIPER(RR((s-/usr/local/lib/python2.7/test/test_httplib.pyR )scCsdS(N((R((s-/usr/local/lib/python2.7/test/test_httplib.pyR.s(RRR R R(((s-/usr/local/lib/python2.7/test/test_httplib.pyR"s  t NoEOFStringIOcBs&eZdZdd„Zdd„ZRS(s¨Like StringIO, but raises AssertionError on EOF. This is used below to test that httplib doesn't try to read more from the underlying file than it should. iÿÿÿÿcCs4tjj||ƒ}|dkr0tdƒ‚n|S(NRscaller tried to read past EOF(RtreadtAssertionError(RtnR((s-/usr/local/lib/python2.7/test/test_httplib.pyR 7s cCs4tjj||ƒ}|dkr0tdƒ‚n|S(NRscaller tried to read past EOF(RtreadlineR!(RtlengthR((s-/usr/local/lib/python2.7/test/test_httplib.pyR#=s N(RRt__doc__R RR#(((s-/usr/local/lib/python2.7/test/test_httplib.pyR1s t HeaderTestscBs,eZd„Zd„Zd„Zd„ZRS(cCsÍdtfd„ƒY}x°ttfD]¢}x™d D]‘}tjdƒ}tdƒ|_|ƒ|_d}i}|r‹tt |ƒƒ||R?RG(RRFRB((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_content_length_0bs   cCsUtjdƒ}tdƒ|_|jddƒ|jddƒ|jd|jƒdS(Ns example.comtGETR7sContent-lengthi*sContent-length: 42( RR:RRR;t putrequestt putheadertassertInR<(RRB((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_putheader~s cCsªd}tjdƒ}tdƒ}||_|jddƒ|j|jj|ƒƒd}tjdƒ}tdƒ}||_|jddƒ|j|jj|ƒƒdS(NsCGET /foo HTTP/1.1 Host: [2001::]:81 Accept-Encoding: identity s [2001::]:81RRLs/foosEGET /foo HTTP/1.1 Host: [2001:102A::] Accept-Encoding: identity s [2001:102A::](RR:RR;R>t assertTrueRt startswith(RtexpectedRBR;((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_ipv6host_header…s    (RRRERKRPRT(((s-/usr/local/lib/python2.7/test/test_httplib.pyR&Ds   t BasicTestcBs¼eZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs»d}t|ƒ}tj|ƒ}|jƒ|j|jdƒdƒ|j|jƒƒ|j|jƒdƒ|j|jƒƒd}t|ƒ}tj|ƒ}|j tj |jƒdS(NsHTTP/1.1 200 Ok TextiRtTextsHTTP/1.1 400.100 Not Ok Text( RRt HTTPResponsetbeginR?R t assertFalsetisclosedRQt assertRaisest BadStatusLine(RRCR;tresp((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_status_linesšs   cCs)tjdƒ}|jt|ƒdƒdS(NRsBadStatusLine("''",)(RR\R?trepr(Rtexc((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_bad_status_repr«scCs‡d}t|ƒ}tj|ƒ}|jƒ|j|jdƒdƒ|j|jƒƒ|j|jdƒdƒ|j|jƒƒdS(Ns*HTTP/1.1 200 Ok Content-Length: 4 TextitTetxt( RRRWRXR?R RYRZRQ(RRCR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_partial_reads¯s  cCs d}t|ƒ}tj|ƒ}|jƒ|j|jdƒdƒ|j|jƒƒ|j|jdƒdƒ|j|jdƒdƒ|j|jƒƒdS(NsHTTP/1.1 200 Ok TextiRbRciR( RRRWRXR?R RYRZRQ(RRCR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyt$test_partial_reads_no_content_length»s  cCs d}t|ƒ}tj|ƒ}|jƒ|j|jdƒdƒ|j|jƒƒ|j|jdƒdƒ|j|jdƒdƒ|j|jƒƒdS(Ns+HTTP/1.1 200 Ok Content-Length: 10 TextiRbRciR( RRRWRXR?R RYRZRQ(RRCR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyt"test_partial_reads_incomplete_bodyÈs  cCsÇx'd D]}|jtjtj|ƒqWx–dddddfD]\}}}tj|ƒ}|j}||jkr“|jd ||jfƒn||jkr@|jd ||jfƒq@q@WdS(Nswww.python.org:abcsuser:password@www.python.orgs[fe80::207:e9ff:fe9b]:8000sfe80::207:e9ff:fe9bi@swww.python.org:80swww.python.orgiPswww.python.org:s[fe80::207:e9ff:fe9b]s!Host incorrectly parsed: %s != %ss!Port incorrectly parsed: %s != %s(swww.python.org:abcsuser:password@www.python.org(s[fe80::207:e9ff:fe9b]:8000sfe80::207:e9ff:fe9bi@(swww.python.org:80swww.python.orgiP(swww.python.orgswww.python.orgiP(swww.python.org:swww.python.orgiP(s[fe80::207:e9ff:fe9b]sfe80::207:e9ff:fe9biP(R[Rt InvalidURLtHTTPt_connRtfailR(Rthpthtpthttptc((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_host_portÕs  cCs`d}d}t|ƒ}tj|ƒ}|jƒ|jdƒ}||kr\|jdƒndS(Ns¨HTTP/1.1 200 OK Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme" Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme" No body srCustomer="WILE_E_COYOTE"; Version="1"; Path="/acme", Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"s Set-Cookies&multiple headers not combined properly(RRRWRXt getheaderRj(RRthdrtsR tcookies((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_response_headersés   cCsTtdtƒ}tj|ddƒ}|jƒ|jƒdkrP|jdƒndS(Ns*HTTP/1.1 200 OK Content-Length: 14432 tmethodtHEADRs)Did not expect response from HEAD request(RRRRWRXR Rj(RR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_read_headüs  cCsid}ttdƒ}tjdƒ}t|ƒ}||_|jdd|ƒ|j|jj |ƒƒdS(NsPGET /foo HTTP/1.1 Host: example.com Accept-Encoding: identity Content-Length:R s example.comRLs/foo( topent__file__RR:RR;R>RQRRR(RRSRCRBR;((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_send_file s  cCsµd}tjdƒ}tdƒ}||_|j|ƒ|j||jƒd|_|jtjd|ƒƒ|j||jƒd|_|jt j |ƒƒ|j||jƒdS(Ns"this is a test this is only a tests example.comRRo( RR:RRR;tsendR?RtarrayR(RRSRBR;((s-/usr/local/lib/python2.7/test/test_httplib.pyt test_sends     cCsd}t|dƒ}tj|ddƒ}|jƒ|j|jƒdƒ|jƒxÂd D]º}t||ƒ}tj|ddƒ}|jƒzwy|jƒWnUtjk rù}|j|jdƒ|jt |ƒdƒ|jt |ƒdƒnX|j d ƒWd|jƒXq\WdS( NsDHTTP/1.1 200 OK Transfer-Encoding: chunked a hello worl 1 d s0 RvRLs hello worldRsfoo sIncompleteRead(11 bytes read)sIncompleteRead expected(Rsfoo ( RRRWRXR?R RtIncompleteReadtpartialR_R=Rj(Rt chunked_startR;R]txti((s-/usr/local/lib/python2.7/test/test_httplib.pyt test_chunked"s&    cCsˆd}t|dƒ}tj|ddƒ}|jƒ|j|jƒdƒ|j|jdƒ|j|jdƒ|j|j ƒƒdS(NsEHTTP/1.1 200 OK Transfer-Encoding: chunked a hello world 1 d s0 RvRwRiÈtOK( RRRWRXR?R tstatustreasonRQRZ(RRR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_chunked_head@s cCsXtdƒ}tj|ddƒ}|jƒ|j|jƒdƒ|j|jƒƒdS(Ns.HTTP/1.1 200 OK Content-Length: -1 Hello RvRLsHello (RRRWRXR?R RQRZ(RR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_negative_content_lengthQs   cCsµtdƒ}tj|ddƒ}|jƒy|jƒWnhtjk r£}|j|jdƒ|jt|ƒdƒ|jt |ƒdƒ|j |j ƒƒnX|j dƒdS(Ns.HTTP/1.1 200 OK Content-Length: 10 Hello RvRLsHello s-IncompleteRead(7 bytes read, 3 more expected)sIncompleteRead expected( RRRWRXR RR?R€R_R=RQRZRj(RR;R]Rƒ((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_incomplete_readYs  cstddƒ}tjdƒ‰|ˆ_|jtj‡fd†ƒˆjƒ}|jd|j ƒ|jd|j dƒƒdS(NsgHTTP/1.0 401 Authorization Required Content-type: text/html WWW-Authenticate: Basic realm="example" sContent-Lengths example.comcsˆjdddƒS(NRJs/urlRC(R>((RB(s-/usr/local/lib/python2.7/test/test_httplib.pytrsi‘sBasic realm="example"swww-authenticate( RRR:R;R[RRt getresponseR?R†Rq(RR;R]((RBs-/usr/local/lib/python2.7/test/test_httplib.pyt test_epipeis     cCs>d}t|ƒ}tj|ƒ}|jt|dƒdƒdS(NsHTTP/1.1 200 Ok Texttfilenos-HTTPResponse should expose a fileno attribute(RRRWRQthasattr(RRCR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_filenoattrxs  cCsW|jdƒdddd}tjt|ƒƒ}|jtjtjf|jƒdS(Nsdisabled for HTTP 0.9 supportsHTTP/1.1 200 Oktkis (tskipTestRRWRR[t LineTooLongR\RX(RRCR]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_overflowing_status_line‚s cCsAdddd}tjt|ƒƒ}|jtj|jƒdS(NsHTTP/1.1 200 OK X-Foo: barR is (RRWRR[R“RX(RRCR]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_overflowing_header_lineˆscCsKdddd}tjt|ƒƒ}|jƒ|jtj|jƒdS(Ns/HTTP/1.1 200 OK Transfer-Encoding: chunked RIisa hello world 0 (RRWRRXR[R“R (RRCR]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_overflowing_chunked_lines cCsXd}t|ƒ}tj|ƒ}|jƒ|j|jƒdƒ|j|jƒƒdS(NsHTTP/1.1 200 OkR(RRRWRXR?R RQRZ(RRCR;R]((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_early_eofœs   (RRR^RaRdReRfRpRuRxR{R~R„RˆR‰RŠRRR”R•R–R—(((s-/usr/local/lib/python2.7/test/test_httplib.pyRU™s(             t OfflineTestcBseZd„ZRS(cCs|jtjtjdƒdS(Ns Not Found(R?Rt responsest NOT_FOUND(R((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_responses¦s(RRR›(((s-/usr/local/lib/python2.7/test/test_httplib.pyR˜¥stSourceAddressTestcBsHeZd„Zd„Zd„Zejeedƒ dƒd„ƒZ RS(cCs\tjtjtjƒ|_tj|jƒ|_tjƒ|_|jj dƒd|_ dS(Ni( RtAF_INETt SOCK_STREAMtservRt bind_portRtfind_unused_portt source_porttlistenRRB(R((s-/usr/local/lib/python2.7/test/test_httplib.pytsetUp«s cCs<|jr"|jjƒd|_n|jjƒd|_dS(N(RBRRRŸ(R((s-/usr/local/lib/python2.7/test/test_httplib.pyttearDown²s     cCs[tjt|jdd|jfƒ|_|jjƒ|j|jjj ƒd|jƒdS(Ntsource_addressRi( RR:tHOSTRR¢RBtconnectR?R;t getsockname(R((s-/usr/local/lib/python2.7/test/test_httplib.pyttestHTTPConnectionSourceAddress¹s tHTTPSConnections#httplib.HTTPSConnection not definedcCs+tjt|jdd|jfƒ|_dS(NR¦R(RR«R§RR¢RB(R((s-/usr/local/lib/python2.7/test/test_httplib.pyt testHTTPSConnectionSourceAddress¿s( RRR¤R¥RªtunittesttskipIfRRR¬(((s-/usr/local/lib/python2.7/test/test_httplib.pyRœªs    t TimeoutTestcBs)eZdZd„Zd„Zd„ZRS(cCsDtjtjtjƒ|_tj|jƒt_|jjdƒdS(Ni( RRRžRŸRR R¯tPORTR£(R((s-/usr/local/lib/python2.7/test/test_httplib.pyR¤ÌscCs|jjƒd|_dS(N(RŸRR(R((s-/usr/local/lib/python2.7/test/test_httplib.pyR¥Ñs cCs@|jtjƒƒtjdƒz#tjttjƒ}|j ƒWdtjdƒX|j |j j ƒdƒ|jƒ|jtjƒƒtjdƒz)tjttjddƒ}|j ƒWdtjdƒX|j |j j ƒdƒ|jƒtjttjddƒ}|j ƒ|j |j j ƒdƒ|jƒdS(sbThis will prove that the timeout gets through HTTPConnection and into the socket. iNttimeout(t assertIsNoneRtgetdefaulttimeouttsetdefaulttimeoutRR:R§R¯R°R¨RR?R;t gettimeoutR(RthttpConn((s-/usr/local/lib/python2.7/test/test_httplib.pyttestTimeoutAttributeÕs*      N(RRRR°R¤R¥R·(((s-/usr/local/lib/python2.7/test/test_httplib.pyR¯És  tHTTPSTimeoutTestcBs6eZd„Zejeedƒ dƒd„ƒZRS(cCsDttdƒr@tjttjddƒ}|j|jdƒndS(NR«R±i(RRR«R§R¯R°R?R±(RRl((s-/usr/local/lib/python2.7/test/test_httplib.pyttest_attributesústHTTPSshttplib.HTTPS not availablecCsÇx'd D]}|jtjtj|ƒqWx–dddddfD]\}}}tj|ƒ}|j}||jkr“|jd ||jfƒn||jkr@|jd ||jfƒq@q@WdS(Nswww.python.org:abcsuser:password@www.python.orgs[fe80::207:e9ff:fe9b]:8000sfe80::207:e9ff:fe9bi@spypi.python.org:443spypi.python.orgi»spypi.python.org:s[fe80::207:e9ff:fe9b]s!Host incorrectly parsed: %s != %ss!Port incorrectly parsed: %s != %s(swww.python.org:abcsuser:password@www.python.org(s[fe80::207:e9ff:fe9b]:8000sfe80::207:e9ff:fe9bi@(spypi.python.org:443spypi.python.orgi»(spypi.python.orgspypi.python.orgi»(spypi.python.org:spypi.python.orgi»(s[fe80::207:e9ff:fe9b]sfe80::207:e9ff:fe9bi»( R[RRgRhRºRiRRjR(RRkRlRmRnRo((s-/usr/local/lib/python2.7/test/test_httplib.pyRps  (RRR¹R­R®RRRp(((s-/usr/local/lib/python2.7/test/test_httplib.pyR¸÷s t TunnelTestscBseZd„ZRS(cssd‰dd‡fd†}tjdƒ}||_|jƒ|jt|jdƒ|jƒ|jdƒ|j dddƒ|j |j j dƒ|j |j j dƒ|jd |j jkƒ|jd |j jkƒ|jd |j jkƒ|jƒ|j d ddƒ|j |j j dƒ|j |j j dƒ|jd |j jkƒ|jd |j jkƒdS( Ns:HTTP/1.0 200 OK HTTP/1.1 200 OK Content-Length: 42 cstˆd|dd|dƒS(NRiRi(R(taddressR±R¦(t response_text(s-/usr/local/lib/python2.7/test/test_httplib.pytcreate_connectionss proxy.comsdestination.comRwR7RiPsCONNECT destination.comsHost: destination.comsHost: proxy.comRJ(RRR:t_create_connectionR¨R[t RuntimeErrort set_tunnelRR>R?R;RRRQR(RR¾RB((R½s-/usr/local/lib/python2.7/test/test_httplib.pyt test_connects(     (RRRÂ(((s-/usr/local/lib/python2.7/test/test_httplib.pyR»scCs#tjtttttttƒdS(N( Rt run_unittestR&R˜RUR¯R¸RœR»(tverbose((s-/usr/local/lib/python2.7/test/test_httplib.pyt test_main=st__main__(RR}RRRR­tTestCasettestRR§RRRR&RUR˜RœR¯R¸R»RRÅR(((s-/usr/local/lib/python2.7/test/test_httplib.pyts.         Uÿ .'