lJc@sdZddkZddkZddkZddklZyddklZWn#ej oddklZnXddddd d d d d dddddddddgZ dZ dZ dZ dZ dZdZdZdZdZd Zd!Zd"Zd#Zd$Zd%Zd&Zd'Zd(Zd)Zd*Zd+Zd,Zd-Z d.Z!d/Z"d0Z#d1Z$d2Z%d3Z&d4Z'd5Z(d6Z)d7Z*d8Z+d9Z,d:Z-d;Z.d<Z/d=Z0d>Z1d?Z2d@Z3dAZ4dBZ5dCZ6dDZ7dEZ8dFZ9dGZ:dHZ;dIZ<dJZ=dKZ>dLZ?dMZ@hdNd<dOd<dPd <dQd!<dRd"<dSd#<dTd$<dUd%<dVd&<dWd)<dXd*<dYd+<dZd,<d[d-<d\d.<d]d^<d_d/<d`d0<dad1<dbd2<dcd3<ddd4<ded5<dfd6<dgd7<dhd8<did9<djd:<dkd;<dld<<dmd=<dnd><dod?<dpd@<dqdA<drdF<dsdG<dtdH<dudI<dvdJ<dwdK HTTPConnection goes through a number of "states", which define when a client may legally make another request or fetch the response for a particular request. This diagram details these state transitions: (null) | | HTTPConnection() v Idle | | putrequest() v Request-started | | ( putheader() )* endheaders() v Request-sent | | response = getresponse() v Unread-response [Response-headers-read] |\____________________ | | | response.read() | putrequest() v v Idle Req-started-unread-response ______/| / | response.read() | | ( putheader() )* endheaders() v v Request-started Req-sent-unread-response | | response.read() v Request-sent This diagram presents the following rules: -- a second request may not be started until {response-headers-read} -- a response [object] cannot be retrieved until {request-sent} -- there is no differentiation between an unread response body and a partially read response body Note: this enforcement is applied by the HTTPConnection class. The HTTPResponse class does not enforce this state machine, which implies sophisticated clients may accelerate the request/response pipeline. Caution should be taken, though: accelerating the states beyond the above pattern may imply knowledge of the server's connection-close behavior for certain requests. For example, it is impossible to tell whether the server will close the connection UNTIL the response headers have been read; this means that further requests cannot be placed into the pipeline until it is known that the server will NOT be closing the connection. Logical State __state __response ------------- ------- ---------- Idle _CS_IDLE None Request-started _CS_REQ_STARTED None Request-sent _CS_REQ_SENT None Unread-response _CS_IDLE Req-started-unread-response _CS_REQ_STARTED Req-sent-unread-response _CS_REQ_SENT iN(turlsplit(tStringIOtHTTPt HTTPResponsetHTTPConnectiontHTTPSConnectiont HTTPExceptiont NotConnectedtUnknownProtocoltUnknownTransferEncodingtUnimplementedFileModetIncompleteReadt InvalidURLtImproperConnectionStatetCannotSendRequesttCannotSendHeadertResponseNotReadyt BadStatusLineterrort responsesiPitUNKNOWNtIdlesRequest-starteds Request-sentidieifiiiiiiiiii,i-i.i/i0i1i3iiiiiiiiiiiiiiiiiiiiiiiiiiiiiitContinuesSwitching ProtocolstOKtCreatedtAcceptedsNon-Authoritative Informations No Contents Reset ContentsPartial ContentsMultiple ChoicessMoved PermanentlytFounds See Others Not Modifieds Use Proxys(Unused)i2sTemporary Redirects Bad Requestt UnauthorizedsPayment Requiredt Forbiddens Not FoundsMethod Not AllowedsNot AcceptablesProxy Authentication RequiredsRequest TimeouttConflicttGonesLength RequiredsPrecondition FailedsRequest Entity Too LargesRequest-URI Too LongsUnsupported Media TypesRequested Range Not SatisfiablesExpectation FailedsInternal Server ErrorsNot Implementeds Bad GatewaysService UnavailablesGateway TimeoutsHTTP Version Not Supportedit HTTPMessagecBs#eZdZdZdZRS(cCsV|ii|}|djo||i|(R$tamtts((s/sys/lib/python/httplib.pyRps$    cCs|itjpt|i}d}x>to6|djo^|ii}|id}|djo|| }nt |d}|djoPqn|djo||i |7}n||jo(||i |7}|||_|Sn\||jo1||i |7}|i dd|_|Sn||i |7}||8}|i dd}q)Wx-to%|ii}|djoPqjqjW|i |S(NR,t;iiis ( RQRNtAssertionErrorRRR5R"R2R7tfindR]RqR[(R$RrRRR&RDti((s/sys/lib/python/httplib.pyRosB                   cCswg}xa|djoS|iit|t}|pt|n|i||t|8}q Wdi|S(sVRead the number of bytes requested, compensating for partial reads. Normally, we have a blocking socket, but a read() can be interrupted by a signal (resulting in a partial read). Note that we cannot distinguish between EOF and an interrupt when zero bytes have been read. IncompleteRead() will be raised in this situation. This function should be used when bytes "should" be present for reading. If the bytes are truly not available (due to EOF), then the IncompleteRead exception can be used to detect the problem. iR,(R2Rptmint MAXAMOUNTR R9R>R#(R$RrRstchunk((s/sys/lib/python/httplib.pyRqFs cCs0|idjo tn|ii||S(N(RMR"RRa(R$tnametdefault((s/sys/lib/python/httplib.pyRa]s cCs*|idjo tn|iiS(s&Return list of (header, value) tuples.N(RMR"Rtitems(R$((s/sys/lib/python/httplib.pyt getheadersbs N(RFRGR"RWR^RiRcR[RnRpRoRqRaR~(((s/sys/lib/python/httplib.pyR9s  % P    /  cBseZdZdZeZeZdZdZ dZ dddZ dZ dZdZdZd Zd Zd Zddd Zd ZdZdhdZdZdZRS(i sHTTP/1.1iicCs[d|_g|_d|_t|_d|_|i|||dj o ||_ndS(N( R"RUt_buffert_HTTPConnection__responset_CS_IDLEt_HTTPConnection__stateRLt _set_hostportRK(R$thosttportRK((s/sys/lib/python/httplib.pyRWts      cCs|djo|id}|id}||joTyt||d}Wn+tj otd||dnX|| }n |i}|o3|ddjo"|ddjo|dd!}qn||_||_dS(Nt:t]isnonnumeric port: '%s'it[i(R"trfindR]RZR t default_portRR(R$RRRwtj((s/sys/lib/python/httplib.pyRs   ) cCs ||_dS(N(RJ(R$tlevel((s/sys/lib/python/httplib.pytset_debuglevelscCs&d}xti|i|idtiD]}|\}}}}}yUti||||_|idjod|i|ifGHn|ii|Wnhtij oY}|idjodG|i|ifGHn|io|ii nd|_q(nXPq(W|ipti|ndS(s3Connect to the host and port specified in __init__.s!getaddrinfo returns an empty listisconnect: (%s, %s)s connect fail:N( tsockett getaddrinfoRRt SOCK_STREAMRURJtconnectRR[R"(R$RMtrestaftsocktypetprotot canonnametsa((s/sys/lib/python/httplib.pyRs(    cCsU|io|iid|_n|io|iid|_nt|_dS(s(Close the connection to the HTTP server.N(RUR[R"RRR(R$((s/sys/lib/python/httplib.pyR[s      cCs|idjo%|io|iq5tn|idjodGt|GHny|ii|Wn:ti j o+}|ddjo|i nnXdS(sSend `str' to the server.issend:i N( RUR"t auto_openRRRJRXtsendallRRR[(R$tstrtv((s/sys/lib/python/httplib.pytsends  cCs|ii|dS(suAdd a line of output to the current request buffer. Assumes that the line does *not* end with \r\n. N(RR9(R$Rs((s/sys/lib/python/httplib.pyt_outputscCs:|iiddi|i}|i2|i|dS(spSend the currently buffered request and clear the buffer. Appends an extra \r\n to the buffer. R,s N(R,R,(RtextendR#R(R$RM((s/sys/lib/python/httplib.pyt _send_outputsc Cs|io|iio d |_n|itjo t|_n t||_|p d}nd|||if}|i ||i djo1|p d}|i dot |\}}}}}n|oLy|i d}Wn"tj o|i d}nX|id|qy|ii d} Wn%tj o|ii d} nX|itjo|id| q|idd | |ifn|p|id d qnd S( s`Send a request to the server. `method' specifies an HTTP request method, e.g. 'GET'. `url' specifies the object being requested, e.g. '/index.html'. `skip_host' if True does not add automatically a 'Host:' header `skip_accept_encoding' if True does not add automatically an 'Accept-Encoding:' header t/s%s %s %si R,thttptasciitidnatHosts%s:%ssAccept-EncodingtidentityN(RRnR"RRt_CS_REQ_STARTEDRRLt _http_vsn_strRt _http_vsnR8RtencodetUnicodeEncodeErrort putheaderRRt HTTP_PORT( R$RVturlt skip_hosttskip_accept_encodingRtnetloctnilt netloc_encthost_enc((s/sys/lib/python/httplib.pyt putrequests>       !  cCs>|itjo tnd||f}|i|dS(skSend a request header line to the server. For example: h.putheader('Accept', 'text/html') s%s: %sN(RRRR(R$theaderR&R((s/sys/lib/python/httplib.pyREs cCs4|itjo t|_n t|idS(s?Indicate that the last header line has been sent to the server.N(RRt _CS_REQ_SENTRR(R$((s/sys/lib/python/httplib.pyt endheadersPs  cCsry|i||||WnQtij oB}|ddjp |i on|i||||nXdS(s&Send a complete request to the server.ii N(t _send_requestRRR(R$RVRtbodyR/R((s/sys/lib/python/httplib.pytrequestZs c Cstig}|D]}||iq~}h}d|jod|dt iteritemsRR( R$RVRRR/t_[1]tkt header_namestskipsRgR&((s/sys/lib/python/httplib.pyRfs0     cCs|io|iio d|_n|itjp |io tn|idjo.|i|i|id|i d|i }n%|i|id|i d|i }|i |i t jptt|_|i o|in ||_|S(s!Get the response from the server.iRKRVN(RRnR"RRRRJtresponse_classRURKRLRiRTRNRuRR[(R$tresponse((s/sys/lib/python/httplib.pyt getresponsezs"        N(RFRGRRRRRRRRJRKR"RWRRRR[RRRRRRRRR(((s/sys/lib/python/httplib.pyRis*      k  t SharedSocketcBs,eZdZdZdZdZRS(cCs||_d|_dS(Ni(RUt_refcnt(R$RU((s/sys/lib/python/httplib.pyRWs cCs|id7_dS(Ni(R(R$((s/sys/lib/python/httplib.pytincrefscCsK|id8_|idjpt|idjo|iindS(Nii(RRuRUR[(R$((s/sys/lib/python/httplib.pytdecrefscCs|iidS(N(RUR[(R$((s/sys/lib/python/httplib.pyt__del__s(RFRGRWRRR(((s/sys/lib/python/httplib.pyRs   tSharedSocketClientcBseZdZdZRS(cCs/d|_||_|ii|i|_dS(Ni(t_closedt_sharedRRUt_sock(R$tshared((s/sys/lib/python/httplib.pyRWs   cCs1|ip#|iid|_d|_ndS(Ni(RRRR"(R$((s/sys/lib/python/httplib.pyR[s   (RFRGRWR[(((s/sys/lib/python/httplib.pyRs tSSLFilecBseeZdZdZd dZdZd dZdZddZ dZ d Z d Z RS( s(File-like object wrapping an SSL socket.i cCs<ti||||_d|_|p |ii|_dS(NR,(RRWt_sslt_buft __class__tBUFSIZEt_bufsize(R$RUtssltbufsize((s/sys/lib/python/httplib.pyRWs  cCsd}xtoy|ii|i}Wntij oh}|dtijp|dtijoq n|dtijp|dti joPnq ti j o@}|dt i joq n|dt i joPnq XPq W|S(NR,i(R5RRpRRtsslerrortSSL_ERROR_WANT_READtSSL_ERROR_WANT_WRITEtSSL_ERROR_ZERO_RETURNt SSL_ERROR_EOFRterrnotEINTRtEBADF(R$tbufterr((s/sys/lib/python/httplib.pyt_reads( cCs|ig}t|i}xZ|djp ||jo?|i}|djoPn|i||t|7}qWdi|}|djod|_|Sn|||_|| SdS(NR,(RR>R"RR9R#(R$tsizetLtavailRstall((s/sys/lib/python/httplib.pyRps       cCs|ig}d|_xS|did}|djoPn|i}|djoPn|i|q|djodi|Sn>di|}|idd}|| }|||_|SdS(NR,is ii(RRvRR9R#(R$RRwRsRRD((s/sys/lib/python/httplib.pyR7 s"        icCsmd}g}xZtoR|i}|pPn|i||t|7}|o||joPqqW|S(Ni(R5R7R9R>(R$tsizehintttotaltlistRD((s/sys/lib/python/httplib.pyt readlines"s    cCs |iiS(N(Rtfileno(R$((s/sys/lib/python/httplib.pyR/scCs|S(N((R$((s/sys/lib/python/httplib.pyt__iter__2scCs!|i}|p tn|S(N(R7t StopIteration(R$RD((s/sys/lib/python/httplib.pytnext5s  N( RFRGt__doc__RR"RWRRpR7RRRR(((s/sys/lib/python/httplib.pyRs      t FakeSocketcBsceZdd dYZdZdZd dZddZeZdddZ d Z RS( t _closedsocketcBseZdZRS(cCstdddS(Ni sBad file descriptor(R(R$R{((s/sys/lib/python/httplib.pyt __getattr__>s(RFRGR(((s/sys/lib/python/httplib.pyR=scCs)t|}ti||||_dS(N(RRRWR(R$RUR((s/sys/lib/python/httplib.pyRWAs cCs#ti||ii|_dS(N(RR[RRR(R$((s/sys/lib/python/httplib.pyR[Fs cCs=|djo|djo tnt|i|i|S(NtrRH(R RRR(R$tmodeR((s/sys/lib/python/httplib.pyRIJs icCs|ii|S(N(Rtwrite(R$tstufftflags((s/sys/lib/python/httplib.pyROsicCs|ii|S(N(RRp(R$R>R((s/sys/lib/python/httplib.pytrecvTscCst|i|S(N(tgetattrR(R$tattr((s/sys/lib/python/httplib.pyRWs(N( RFRGRRWR[R"RIRRRR(((s/sys/lib/python/httplib.pyR;s    cBs2eZdZeZdddddZdZRS(s(This class allows communication via SSL.cCs,ti||||||_||_dS(N(RRWtkey_filet cert_file(R$RRRRRK((s/sys/lib/python/httplib.pyRW`s cCsbtititi}|i|i|ifti||i|i}t |||_ dS(s(Connect to a host on a given (SSL) port.N( RtAF_INETRRRRRRRRRU(R$RUR((s/sys/lib/python/httplib.pyRfsN(RFRGRt HTTPS_PORTRR"RWR(((s/sys/lib/python/httplib.pyR[s   cBsteZdZdZdZdZeZdd d dZ dZ d d dZ dZ d Z d Zd ZRS( s-Compatibility class with httplib.py from 1.5.i sHTTP/1.0iR,cCs7|djo d}n|i|i|||dS(s:Provide a default host, since the superclass requires one.iN(R"t_setupt_connection_class(R$RRRK((s/sys/lib/python/httplib.pyRWys  cCs^||_|i|_|i|_|i|_|i|_|i|_|i|_d|_dS(N( t_connRRRRRRR"tfile(R$Rl((s/sys/lib/python/httplib.pyRs       cCs5|dj o|ii||n|iidS(sDAccept arguments to set the host/port, since the superclass doesn't.N(R"RRR(R$RR((s/sys/lib/python/httplib.pyRs cCs|iS(sCProvide a getfile, since the superclass' does not use this concept.(R(R$((s/sys/lib/python/httplib.pytgetfilescGs |ii|di|dS(s.The superclass allows only one value argument.s N(RRR#(R$Rtvalues((s/sys/lib/python/httplib.pyRscCsy|ii}WnStj oG}|iiidd|_|id|_d|i dfSnX|i |_|i |_|i |i |i fS(sCompat definition since superclass does not define it. Returns a tuple consisting of: - server status code (e.g. '200' if all goes well) - server "reason" corresponding to status code - any RFC822 headers in the response from the server RHiiN(RRRRURIRR[R"R/RDRMR2R0RP(R$Rte((s/sys/lib/python/httplib.pytgetreplys    cCs|iid|_dS(N(RR[R"R(R$((s/sys/lib/python/httplib.pyR[s N(RFRGRRRRJRRR"RWRRRRRR[(((s/sys/lib/python/httplib.pyRos    RtHTTPScBs,eZdZeZddddddZRS(sCompatibility with 1.5 httplib interface Python 1.5.2 did not have an HTTPS class, but it defined an interface for sending http requests that is also useful for https. R,cCsO|djo d}n|i|i|||||||_||_dS(Ni(R"RRRR(R$RRRRRK((s/sys/lib/python/httplib.pyRWs     N(RFRGRRRR"RW(((s/sys/lib/python/httplib.pyRs cBseZRS((RFRG(((s/sys/lib/python/httplib.pyRscBseZRS((RFRG(((s/sys/lib/python/httplib.pyRscBseZRS((RFRG(((s/sys/lib/python/httplib.pyR scBseZdZRS(cCs|f|_||_dS(N(targsRO(R$RO((s/sys/lib/python/httplib.pyRWs (RFRGRW(((s/sys/lib/python/httplib.pyRscBseZRS((RFRG(((s/sys/lib/python/httplib.pyR scBseZRS((RFRG(((s/sys/lib/python/httplib.pyR scBseZdZRS(cCs|f|_||_dS(N(Rtpartial(R$R((s/sys/lib/python/httplib.pyRWs (RFRGRW(((s/sys/lib/python/httplib.pyR scBseZRS((RFRG(((s/sys/lib/python/httplib.pyR scBseZRS((RFRG(((s/sys/lib/python/httplib.pyRscBseZRS((RFRG(((s/sys/lib/python/httplib.pyRscBseZRS((RFRG(((s/sys/lib/python/httplib.pyRscBseZdZRS(cCs|f|_||_dS(N(RRD(R$RD((s/sys/lib/python/httplib.pyRW s (RFRGRW(((s/sys/lib/python/httplib.pyR sR\cBsJeZdZdZdZdZddZdZddZ RS(s2A limited file-like object for HTTP/0.9 responses.cCs7||_||_d|_d|_t||_dS(Ni(t_linet_filet_line_consumedt _line_offsetR>t _line_left(R$RDR((s/sys/lib/python/httplib.pyRWs     cCst|i|S(N(RR (R$R((s/sys/lib/python/httplib.pyR!scCs:d|_|ii|_|ii|_|ii|_dS(Ni(R R RpR7R(R$((s/sys/lib/python/httplib.pyt_done$s cCs"|io|ii|Sn|ipt|djp||ijo^|i|i}|i|djo||iiSq||ii|t |Snu||ijpt|i}||}|i||!}||_|i|8_|idjo|in|SdS(Ni( R R RpR RuR"RR R R>(R$RrRsRwR((s/sys/lib/python/httplib.pyRp-s$   "   cCsJ|io|iiSn|ipt|i|i}|i|S(N(R R R7R RuRR R (R$Rs((s/sys/lib/python/httplib.pyR7Cs   cCs|io|ii|Sn|ipt|i|ig}|i|djo||iiSn||ii|SdS(N( R R RR RuRR R R"(R$RR((s/sys/lib/python/httplib.pyRKs   N( RFRGRRWRR R"RpR7R(((s/sys/lib/python/httplib.pyR\s    c Csddk}ddk}|i|idd\}}d}x/|D]'\}}|djo|d}qDqDWd}d}|do|d}n|do|d}nt} | i|| i|| id || i| i\} } } d G| GHd G| GHd Gt | i i GHH| o#x | i D]} | i GHq>WnHd tfdY}|d} | id d| i| i| ittdoxdD]\}}d||fGHt}|i||i||id ||i|i\} } } d G| GHd G| GHd Gt |i i GHH| o#x | i D]} | i GHqkWnHqWndS(sTest this module. A hodge podge of tests collected here, because they have too many external dependencies for the regular test suite. iNitdis-dswww.python.orgRtGETsstatus =sreason =RptHTTP11cBseZdZdZRS(i sHTTP/1.1(RFRGRR(((s/sys/lib/python/httplib.pyRvsshttp://www.python.org/~jeremy/Rssourceforge.nets/projects/pythons https://%s%s(ssourceforge.nets/projects/python((ssourceforge.nets/projects/python(tsystgetopttargvRRRRRRR>RRpR/R:R[R1RR(RRtoptsRtdltotaRtselectorthR0RPR/RRths((s/sys/lib/python/httplib.pyttestVsb                      t__main__(`RRt mimetoolsRturlparseRt cStringIORt ImportErrort__all__RRRNRRRR`tSWITCHING_PROTOCOLSt PROCESSINGRtCREATEDtACCEPTEDtNON_AUTHORITATIVE_INFORMATIONRdt RESET_CONTENTtPARTIAL_CONTENTt MULTI_STATUStIM_USEDtMULTIPLE_CHOICEStMOVED_PERMANENTLYtFOUNDt SEE_OTHERRet USE_PROXYtTEMPORARY_REDIRECTt BAD_REQUESTt UNAUTHORIZEDtPAYMENT_REQUIREDt FORBIDDENt NOT_FOUNDtMETHOD_NOT_ALLOWEDtNOT_ACCEPTABLEtPROXY_AUTHENTICATION_REQUIREDtREQUEST_TIMEOUTtCONFLICTtGONEtLENGTH_REQUIREDtPRECONDITION_FAILEDtREQUEST_ENTITY_TOO_LARGEtREQUEST_URI_TOO_LONGtUNSUPPORTED_MEDIA_TYPEtREQUESTED_RANGE_NOT_SATISFIABLEtEXPECTATION_FAILEDtUNPROCESSABLE_ENTITYtLOCKEDtFAILED_DEPENDENCYtUPGRADE_REQUIREDtINTERNAL_SERVER_ERRORtNOT_IMPLEMENTEDt BAD_GATEWAYtSERVICE_UNAVAILABLEtGATEWAY_TIMEOUTtHTTP_VERSION_NOT_SUPPORTEDtINSUFFICIENT_STORAGEt NOT_EXTENDEDRRytMessageRRRRRRRRRR1Rt ExceptionRRR RR R R R RRRRRR\RRF(((s/sys/lib/python/httplib.pysCs                                                i1Od YD =