ó {G_Tc@sêddlmZddlmZddlmZddlmZddlm Z m Z ddl m Z ddl mZddlmZmZmZdd lmZdd lmZdd lmZdd lZdd lZdd lZdd lmZdefd„ƒYZdefd„ƒYZd„Zedd„Zd„Z defd„ƒYZ!defd„ƒYZ"defd„ƒYZ#de fd„ƒYZ$de$fd„ƒYZ%d efd!„ƒYZ&d"„Z'e(d#kræe'ƒnd S($iÿÿÿÿ(t nested_scopes(tTestCase(tsetup_testing_defaults(tHeaders(t BaseHandlertBaseCGIHandler(tutil(t validator(t WSGIServertWSGIRequestHandlertdemo_app(t make_server(tStringIO(t BaseServerN(t test_supportt MockServercBs eZdZd„Zd„ZRS(sNon-socket HTTP servercCs!tj|||ƒ|jƒdS(N(R t__init__t server_bind(tselftserver_addresstRequestHandlerClass((s-/usr/local/lib/python2.7/test/test_wsgiref.pyRscCs/|j\}}||_||_|jƒdS(N(Rt server_namet server_portt setup_environ(Rthosttport((s-/usr/local/lib/python2.7/test/test_wsgiref.pyRs  (t__name__t __module__t__doc__RR(((s-/usr/local/lib/python2.7/test/test_wsgiref.pyRs t MockHandlercBs eZdZd„Zd„ZRS(sNon-socket HTTP handlercCs%|j|_|j\|_|_dS(N(trequestt connectiontrfiletwfile(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pytsetup"s cCsdS(N((R((s-/usr/local/lib/python2.7/test/test_wsgiref.pytfinish&s(RRRR"R#(((s-/usr/local/lib/python2.7/test/test_wsgiref.pyR s cCs|dddgƒdgS( Ns200 OKs Content-Types text/plaintDatesMon, 05 Jun 2006 18:49:54 GMTs Hello, world!(s Content-Types text/plain(R$sMon, 05 Jun 2006 18:49:54 GMT((tenvirontstart_response((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt hello_app*s sGET / HTTP/1.0 cCs‹tdd|ttƒ}t|ƒtƒtƒtjf\}}}}|t_z|j||fdƒWd|t_X|jƒ|jƒfS(NtiPs 127.0.0.1i¸"(s 127.0.0.1i¸"(R RRR tsyststderrtfinish_requesttgetvalue(tapptdatatservertinptoutterrtolderr((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt run_amock1s-  cCs|ƒ}d}x1|D])}|||ks5t‚n|d7}qWy ||Wntk rbnXtd|ƒ‚yttfWntk r“n‚X|ƒ}t|ƒ|k r¸t‚nx)|D]!}|jƒ|ks¿t‚q¿q¿Wy|jƒWntk rnXtd|ƒ‚dS(sUtility to compare a generic 2.1/2.2+ iterator with an iterable If running under Python 2.2+, this tests the iterator using iter()/next(), as well as __getitem__. 'make_it' must be a function returning a fresh iterator to be tested (since this may test the iterator twice).iisToo many items from __getitem__sToo many items from .next()N(tAssertionErrort IndexErrortitert StopIterationt NameErrortnext(tmake_ittmatchtittntitem((s-/usr/local/lib/python2.7/test/test_wsgiref.pytcompare_generic_iter>s4           tIntegrationTestscBs/eZed„Zd„Zd„Zd„ZRS(cCs=|j|dtjjƒdd|r-dp0ddƒdS(Ns/HTTP/1.0 200 OK Server: WSGIServer/0.1 Python/isA Content-Type: text/plain Date: Mon, 05 Jun 2006 18:49:54 GMT sContent-Length: 13 R(s Hello, world!(t assertEqualR)tversiontsplit(RR1t has_length((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt check_helloes (cCs tƒ\}}|j|ƒdS(N(R4RF(RR1R2((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttest_plain_hellopscCs/tttƒƒ\}}|j|dtƒdS(NRE(R4RR'RFtFalse(RR1R2((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttest_validated_hellotscCsUd„}tt|ƒƒ\}}|j|jdƒƒ|j|jƒddƒdS(NcSs|ddƒdgS(Ns200 OKs Content-Types text/plains Hello, world!(s Content-Types text/plain((R%R&((s-/usr/local/lib/python2.7/test/test_wsgiref.pytbad_appzs s;A server error occurred. Please contact the administrator.iþÿÿÿs]AssertionError: Headers (('Content-Type', 'text/plain')) must be of type list: (R4Rt assertTruetendswithRBt splitlines(RRJR1R2((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttest_simple_validation_errorys    (RRtTrueRFRGRIRN(((s-/usr/local/lib/python2.7/test/test_wsgiref.pyRAcs  t UtilityTestscBs•eZd„Zdd„Zd„Zd„Zdd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„ZRS(cCsfi|d6|d6}tj|ƒ|jtj|ƒ|ƒ|j|d|ƒ|j|d|ƒ|S(Nt SCRIPT_NAMEt PATH_INFO(RRRBtshift_path_info(Rtsn_intpi_intparttsn_outtpi_outtenv((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt checkShiftŠs  cCsi}tj|ƒt|tƒr9|j||tƒn|j|||ƒi||6}tj|ƒ|j|||ƒdS(N(RRt isinstanceR tassertIsInstanceRBtassertIs(RtkeytvaluetaltRY((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt checkDefault’s   cKs%tj|ƒ|j|||ƒdS(N(RRRB(RR^R_tkw((s-/usr/local/lib/python2.7/test/test_wsgiref.pytcheckCrossDefault s cKs*tj|ƒ|jtj|ƒ|ƒdS(N(RRRBtapplication_uri(RturiRb((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt checkAppURI¤s icKs-tj|ƒ|jtj||ƒ|ƒdS(N(RRRBt request_uri(RRetqueryRb((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt checkReqURI¨s cCs}||d„}t||ƒ|ƒ}|j|jjƒx|D]}q?W|j|jjƒ|jƒ|j|jjƒdS(NcSstjt|ƒ|ƒS(N(Rt FileWrapperR (ttexttsize((s-/usr/local/lib/python2.7/test/test_wsgiref.pyR;®s(R@t assertFalsetfileliketclosedtcloseRK(RRkRlR<R;R=R?((s-/usr/local/lib/python2.7/test/test_wsgiref.pytcheckFW¬s    cCs|jdddddƒ|jdddddƒ|jdddddƒ|jdddddƒ|jdd dddƒdS( NR(t/s/xtxs/as/x/ys/a/xs/ys/x/(RZtNone(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestSimpleShifts¾s cCs|jdddddƒ|jdddddƒ|jdddd dƒ|jdd dd d ƒ|jdd dd dƒ|jdd dd d ƒ|jdddddƒ|jdddddƒ|jdddddƒ|jddddd ƒ|jdddddƒdS(Ns/a/bs/../ys..s/as/yR(s//ytys/a/b/ys//y/Rrs/./ys/./y/s///./..//y/.//s/y/s///s/a/b/s/.//s/x//Rss/a/b/xs/.(RZRt(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestNormalizedShiftsÅscCspxidddddddddfd d!d"dtd ƒfdtƒfd#gD]\}}|j||ƒqLWdS($Nt SERVER_NAMEs 127.0.0.1t SERVER_PORTt80tSERVER_PROTOCOLsHTTP/1.0t HTTP_HOSTtREQUEST_METHODtGETRQR(RRRrs wsgi.versioniis wsgi.run_onceswsgi.multithreadswsgi.multiprocesss wsgi.inputs wsgi.errorsswsgi.url_schemethttp(s SERVER_NAMEs 127.0.0.1(s SERVER_PORTRz(sSERVER_PROTOCOLsHTTP/1.0(s HTTP_HOSTs 127.0.0.1(R}R~(s SCRIPT_NAMER((s PATH_INFORr(ii(s wsgi.run_oncei(swsgi.multithreadi(swsgi.multiprocessi(swsgi.url_schemeR(R Ra(RR^R_((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt testDefaultsÒs   cCsž|jddddƒ|jddddƒ|jddddƒ|jdddd ƒ|jdd dd ƒ|jd d dd ƒ|jd dddƒdS(NR|sfoo.barRxswsgi.url_schemethttpstHTTPStont1tyesRtfooRyRzt443(Rc(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestCrossDefaultsåscCs|jtjiƒdƒ|jtjidd6ƒdƒ|jtjidd6ƒdƒ|jtjidd6ƒdƒ|jtjidd6ƒdƒdS(NRR†R‚RƒRR…R„(RBRt guess_scheme(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestGuessSchemeîs    cCs¨|jdƒ|jdddƒ|jdddƒ|jddd d d ƒ|jd d dƒ|jdddd dƒ|jdddƒ|jdd dddƒdS(Nshttp://127.0.0.1/shttp://127.0.0.1/spamRQs/spamshttp://127.0.0.1/sp%E4ms/spämshttp://spam.example.com:2071/R|sspam.example.com:2071Ryt2071shttp://spam.example.com/Rxsspam.example.coms 127.0.0.1shttps://127.0.0.1/R‚Rƒshttp://127.0.0.1:8000/t8000(RfRt(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt testAppURIsõs      c Csû|jdƒ|jdddƒ|jdddƒ|jdddd dƒ|jd ddd dƒ|jd ddd d ƒ|jd ddd dƒ|jdddd dddƒ|jdddd dddƒ|jddddd dddƒdS(Nshttp://127.0.0.1/shttp://127.0.0.1/spamRQs/spamshttp://127.0.0.1/sp%E4ms/spämshttp://127.0.0.1/spammity/spams /spammityRRs http://127.0.0.1/spammity/sp%E4ms"http://127.0.0.1/spammity/spam;hams /spam;hams/http://127.0.0.1/spammity/spam;cookie=1234,5678s/spam;cookie=1234,5678s%http://127.0.0.1/spammity/spam?say=nit QUERY_STRINGssay=nis'http://127.0.0.1/spammity/spam?s%E4y=niss%E4y=nii(Ri(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt testReqURIss"           cCs)|jdddddddgƒdS(Ntxyzi2ixi(i (Rq(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestFileWrapperscCs¼xYdjƒD]K}xB||jƒ|jƒ|jƒfD]}|jtj|ƒƒq8Wq WxYdjƒD]K}xB||jƒ|jƒ|jƒfD]}|jtj|ƒƒq”WqiWdS(NsbConnection Keep-Alive Proxy-Authenticate Proxy-Authorization TE Trailers Transfer-Encoding Upgrades4Accept Cache-Control Date Pragma Trailer Via Warning(RDttitletuppertlowerRKRt is_hop_by_hopRm(RthopR`((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt testHopByHops++N(RRRZRtRaRcRfRiRqRuRwR€RˆRŠRRR‘R—(((s-/usr/local/lib/python2.7/test/test_wsgiref.pyRPˆs            t HeaderTestscBs#eZd„Zd„Zd„ZRS(cCs=d g}|jttgƒƒdƒ|jtt|ƒƒdƒ|jt|ƒjƒdgƒ|jt|ƒjƒdgƒ|jt|ƒjƒ|ƒ|jt|ƒjƒ|ƒtgƒ}|d=d|dStatus: %s Content-Type: text/plain Content-Length: %d %sR5iÿÿÿÿ( R¶RßRBRàR,R*t error_statusRŸt error_bodytassertNotEqualtfind(RRâRãR«((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestBasicErrorOutputÍs       csnd‰‡fd†}tƒ}|j|ƒ|j|jjƒdˆƒ|j|jjƒjdƒdƒdS(NsSome output has been sentcs#|dgƒˆƒtdƒ‚dS(Ns200 OKs This should be caught by handler(R5(RÙRÚ(tMSG(s-/usr/local/lib/python2.7/test/test_wsgiref.pyRãêssStatus: 200 OK R5iÿÿÿÿ(R¶RßRBRàR,RæR*Rç(RRãR«((Rés-/usr/local/lib/python2.7/test/test_wsgiref.pyttestErrorAfterOutputès  c CsYd„}d}d}x=d D]5}|r2d|p5d}xdD]}xdD]ý}td |ƒ}t|_||_||_|j|ƒ|j||jj ƒƒtd |ƒ}t |_||_||_|j|ƒ|d kr|j|jj ƒdƒqL|j t j |||f|jj ƒƒ|||f|jj ƒfƒqLWq?WqWdS(NcSs|dgƒgS(Ns200 OK((RÙRÚ((s-/usr/local/lib/python2.7/test/test_wsgiref.pyRâ÷s sfHTTP/%s 200 OK\r\nDate: \w{3}, [ 0123]\d \w{3} \d{4} \d\d:\d\d:\d\d GMT\r\n%sContent-Length: 0\r\n\r\ns%Status: 200 OK Content-Length: 0 s FooBar/1.0s Server: %s R(s1.0s1.1sHTTP/0.9sHTTP/1.0sHTTP/1.1R{(s FooBar/1.0N(s1.0s1.1(sHTTP/0.9sHTTP/1.0sHTTP/1.1(RtR¼RHt origin_servert http_versiontserver_softwareRßRBRàR,RORKtreR<( RRâtstdpattshortpattsswtswRCtprotoR«((s-/usr/local/lib/python2.7/test/test_wsgiref.pyttestHeaderFormatsõs.             "csSitd6‰d‰‡‡fd†}tƒ}|j|ƒ|jˆdtƒdS(Nt close_calledsSome output has been sentcs6|dgƒˆƒdtf‡fd†ƒY}|ƒS(Ns200 OKtCrashyIterablecs eZd„Z‡fd†ZRS(css"xtrdVtdƒ‚qWdS(Ntblahs This should be caught by handler(ROR5(R((s-/usr/local/lib/python2.7/test/test_wsgiref.pyt__iter__$s cstˆds8     %% 8¼