V~gc@sdZddlmZddlZddlZddlZddlmZddlmZddl Z e j -ere j dde nddl Z WdQXyddlmZWn!ek rddlmZnXd d d d d ddddddddddddgZdZdZdZdZdZdZd Zd!Zd"Zd#Zd$Zd%Zd&Zd'Zd(Z d)Z!d*Z"d+Z#d,Z$d-Z%d.Z&d/Z'd0Z(d1Z)d2Z*d3Z+d4Z,d5Z-d6Z.d7Z/d8Z0d9Z1d:Z2d;Z3d<Z4d=Z5d>Z6d?Z7d@Z8dAZ9dBZ:dCZ;dDZ<dEZ=dFZ>dGZ?dHZ@dIZAdJZBdKZCdLZDdMZEdNZFdOZGdPZHi)dQd 6dRd!6dSd#6dTd$6dUd%6dVd&6dWd'6dXd(6dYd)6dZd,6d[d-6d\d.6d]d/6d^d06d_d16d`da6dbd26dcd36ddd46ded56dfd66dgd76dhd86did96djd:6dkd;6dld<6dmd=6dnd>6dod?6dpd@6dqdA6drdB6dsdC6dtdD6dudI6dvdJ6dwdK6dxdL6dydM6dzdN6ZId{ZJd|ZKd ZLejMd}jNZOejMd~jPZQejMdZRdddhZSde jTfdYZUd fdYZVd fdYZWd fdYZXyddlYZYWnek rJnCXdeWfdYZZej[ddeXfdYZ\dZ]d e^fdYZ_d e_fdYZ`de_fdYZade_fdYZbde_fdYZcde_fdYZdde_fdYZede_fdYZfdeffdYZgdeffdYZhdeffdYZide_fdYZjde_fdYZke_ZldfdYZmdS(s HTTP/1.1 client library 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 i(tarrayN(t py3kwarning(turlsplittignores.*mimetools has been removed(tStringIOtHTTPt HTTPResponsetHTTPConnectiont 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 Supportediis\A[^:\s][^:\r\n]*\Zs\n(?![ \t])|\r(?![ \t\n])s[- -]tPATCHtPOSTtPUTt HTTPMessagecBs#eZdZdZdZRS(cCsT|jj|}|dkr.||j|No status line received - the server has closed the connectioniR1sHTTP/sHTTP/0.9iidi(sHTTP/0.9iR1(R7R>R?R;R@RPtreprRtsplitR't ValueErrorRARQtclosetLineAndFileWrappertint(R)RJRUR5RV((s,/opt/alt/python27/lib64/python2.7/httplib.pyt _read_statuss8       cCs |jdk rdSxtr|j\}}}|tkrAPnxrtr|jjtd}t|tkrt dn|j }|sPn|j dkrDdG|GHqDqDWqW||_ |j |_ |dkrd|_n?|jdrd|_n$|d krd |_n t||jd krid|_d|_d|_tt|_dSt|jd|_|j dkrx|jjD]}dG|GqWnd|j_|jjd }|r|jd krd|_d|_n d|_|j|_|jjd }|r|j ryt||_Wntk rcd|_qX|jdkrd|_qn d|_|tks|tksd|kodkns|jdkrd|_n|j r |j r |jdkr d|_ndS(Nis header lineisheader:sHTTP/1.0i sHTTP/1.i sHTTP/0.9i stransfer-encodingRWscontent-lengthiditHEAD( RSR'R:RetCONTINUER7R>R?R;R@RCRPR5RVRURAR RYRWRZR$RR4t getheadertlowerRXt _check_closeRdRat NO_CONTENTt NOT_MODIFIEDRR(R)RUR5RVtskipthdrttr_encRY((s,/opt/alt/python27/lib64/python2.7/httplib.pytbeginst                        cCs|jjd}|jdkrS|jjd}|rOd|jkrOtStS|jjdritS|rd|jkrtS|jjd}|rd|jkrtStS(Nt connectioni Rbs keep-alivesproxy-connection(RSRhRURiR:tFalse(R)tconntpconn((s,/opt/alt/python27/lib64/python2.7/httplib.pyRjscCs)|j}|r%d|_|jndS(N(R7R'Rb(R)R7((s,/opt/alt/python27/lib64/python2.7/httplib.pyRb-s  cCs |jdkS(N(R7R'(R)((s,/opt/alt/python27/lib64/python2.7/httplib.pytisclosed3scCs[|jdkrdS|jdkr0|jdS|jrF|j|S|dkr|jdkrs|jj}n@y|j|j}Wnt k r|jnXd|_|j|S|jdk r||jkr|j}qn|jj|}| r|r|jn|jdk rW|jt |8_|jsW|jqWn|S(NR1Rfi( R7R'RRRbRWt _read_chunkedRYtreadt _safe_readR R;(R)tamtts((s,/opt/alt/python27/lib64/python2.7/httplib.pyRw>s:           cCsC|jtkst|j}g}xtr|dkr|jjtd}t |tkrpt dn|j d}|dkr|| }nyt |d}Wn0t k r|jtdj|nX|dkrPqn|dkr|j|j|n||krR|j|j||||_dj|S||kr|j|j||jdd|_dj|S|j|j|||8}|jdd}q'Wx[tr+|jjtd}t |tkrt dn|sPn|d krPqqW|jdj|S( Nis chunk sizet;iiR1is trailer lines (RWRTtAssertionErrorRXR:R'R7R>R?R;R@tfindRdRaRbR R(RBRx(R)RyRXR+RJti((s,/opt/alt/python27/lib64/python2.7/httplib.pyRvksV                      cCsg}xi|dkrq|jjt|t}|sQtdj||n|j||t|8}q Wdj|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. iR1(R7Rwtmint MAXAMOUNTR R(RBR;(R)RyRztchunk((s,/opt/alt/python27/lib64/python2.7/httplib.pyRxs cCs |jjS(N(R7tfileno(R)((s,/opt/alt/python27/lib64/python2.7/httplib.pyRscCs.|jdkrtn|jj||S(N(RSR'RRh(R)tnametdefault((s,/opt/alt/python27/lib64/python2.7/httplib.pyRhs cCs(|jdkrtn|jjS(s&Return list of (header, value) tuples.N(RSR'Rtitems(R)((s,/opt/alt/python27/lib64/python2.7/httplib.pyt getheaderss N(RLRMR'RrR^ReRpRjRbRuRwRvRxRRhR(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRls  ' V   - :   cBseZdZdZeZeZdZdZ dZ dde j ddZdddZdZdZdZd Zd Zd Zd Zdd ZdddZdZdZdZdZddZdidZdZdZ e!dZ"RS(i sHTTP/1.1iicCs||_||_d|_g|_d|_t|_d|_d|_ d|_ i|_ |dk rr||_ n|j ||\|_|_|j|jtj|_dS(N(ttimeouttsource_addressR'R[t_buffert_HTTPConnection__responset_CS_IDLEt_HTTPConnection__stateRRt _tunnel_hostt _tunnel_portt_tunnel_headersRQt _get_hostportthosttportt_validate_hosttsockettcreate_connectiont_create_connection(R)RRRQRR((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^s            cCsY|jrtdn|j||\|_|_|rH||_n |jjdS(sC Set up host and port for HTTP CONNECT tunnelling. In a connection that uses HTTP Connect tunneling, the host passed to the constructor is used as proxy server that relays all communication to the endpoint passed to set_tunnel. This is done by sending a HTTP CONNECT request to the proxy server when the connection is established. This method must be called before the HTTP connection has been established. The headers argument should be a mapping of extra HTTP headers to send with the CONNECT request. s.Can't setup tunnel for established connection.N(R[t RuntimeErrorRRRRtclear(R)RRR4((s,/opt/alt/python27/lib64/python2.7/httplib.pyt set_tunnels   cCs|dkr|jd}|jd}||kryt||d}WnItk r||ddkr~|j}qtd||dnX|| }n |j}|r|ddkr|ddkr|dd!}qn||fS( Nt:t]iR1snonnumeric port: '%s'it[i(R'trfindRdRat default_portR(R)RRR~tj((s,/opt/alt/python27/lib64/python2.7/httplib.pyR s      &cCs ||_dS(N(RP(R)tlevel((s,/opt/alt/python27/lib64/python2.7/httplib.pytset_debuglevelscCs\|jd|j|jfx4|jjD]#\}}|jd||fq-W|jd|j|jd|jd|j}|j \}}}|dkr|j t j dn|dkr|j t j d ||j fnx[trW|jjtd }t|tkr:td n|sDPn|dkrPqqWdS( NsCONNECT %s:%d HTTP/1.0 s%s: %s s RQR\sHTTP/0.9s$Invalid response from tunnel requestisTunnel connection failed: %d %sis header line(tsendRRRt iteritemstresponse_classR[RQRRReRbRRRCR:R7R>R?R;R@(R)theaderR+tresponseRUtcodetmessageRJ((s,/opt/alt/python27/lib64/python2.7/httplib.pyt_tunnel s.         cCsD|j|j|jf|j|j|_|jr@|jndS(s3Connect to the host and port specified in __init__.N(RRRRRR[RR(R)((s,/opt/alt/python27/lib64/python2.7/httplib.pytconnect>s cCs_t|_z)|j}|r1d|_|jnWd|j}|rZd|_|jnXdS(s(Close the connection to the HTTP server.N(RRR[R'RbR(R)R[R((s,/opt/alt/python27/lib64/python2.7/httplib.pyRbFs     cCs|jdkr1|jr%|jq1tn|jdkrRdGt|GHnd}t|drt|t  r|jdkrdGHn|j |}x<|r|jj ||j |}qWn|jj |dS(sSend `data' to the server.issend:i RwssendIng a read()ableN( R[R't auto_openRR RPR_R6t isinstanceRRwtsendall(R)tdatat blocksizet datablock((s,/opt/alt/python27/lib64/python2.7/httplib.pyRTs    cCs|jj|dS(suAdd a line of output to the current request buffer. Assumes that the line does *not* end with \r\n. N(RRB(R)Rz((s,/opt/alt/python27/lib64/python2.7/httplib.pyt_outputhscCsx|jjddj|j}|j2t|trK||7}d}n|j||dk rt|j|ndS(sSend the currently buffered request and clear the buffer. Appends an extra \r\n to the buffer. A message_body may be specified, to be appended to the request. R1s N(R1R1(RtextendR(RtstrR'R(R)t message_bodyRS((s,/opt/alt/python27/lib64/python2.7/httplib.pyt _send_outputos    c Cs|jr$|jjr$d|_n|jtkr?t|_n t||_|pZd}|j|d|||j f}|j |j ||j dkr|sd}|j drt|\}}}}}n|r-y|jd}Wn tk r|jd}nX|jd|q|jrK|j} |j} n|j} |j} y| jd} Wn tk r| jd} nX| jd d krd | d } n| |jkr|jd| q|jdd | | fn|s|jddqndS(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 R1thttptasciitidnatHostRiRRs%s:%ssAccept-EncodingtidentityN(RRuR'RRt_CS_REQ_STARTEDRRRt_validate_patht _http_vsn_strRt_encode_requestt _http_vsnRARtencodetUnicodeEncodeErrort putheaderRRRRR}R( R)R\turlt skip_hosttskip_accept_encodingtrequesttnetloctnilt netloc_encRRthost_enc((s,/opt/alt/python27/lib64/python2.7/httplib.pyt putrequestsL                cCs|S(N((R)R((s,/opt/alt/python27/lib64/python2.7/httplib.pyRscCsFtj|}|rBdjd|jd|}t|ndS(sValidate a url for putrequest.sJURL can't contain control characters. {url!r} (found at least {matched!r})tmatchedRN(t!_contains_disallowed_url_pchar_retsearchtformattgroupR(R)RtmatchRS((s,/opt/alt/python27/lib64/python2.7/httplib.pyRs  cCsFtj|}|rBdjd|jd|}t|ndS(s9Validate a host so it doesn't contain control characters.sKURL can't contain control characters. {host!r} (found at least {matched!r})RRN(RRRRR(R)RRRS((s,/opt/alt/python27/lib64/python2.7/httplib.pyR s  cGs|jtkrtnd|}t|sGtd|fng|D]}t|^qN}x0|D](}t|rmtd|fqmqmWd|dj|f}|j|dS(skSend a request header line to the server. For example: h.putheader('Accept', 'text/html') s%ssInvalid header name %rsInvalid header value %rs%s: %ss N( RRRt_is_legal_header_nameRaRt_is_illegal_header_valueR(R(R)Rtvaluestvt one_valueRn((s,/opt/alt/python27/lib64/python2.7/httplib.pyRs     cCs5|jtkrt|_n t|j|dS(sIndicate that the last header line has been sent to the server. This method sends the request to the server. The optional message_body argument can be used to pass a message body associated with the request. The message body will be sent in the same packet as the message headers if it is string, otherwise it is sent as a separate packet. N(RRt _CS_REQ_SENTRR(R)R((s,/opt/alt/python27/lib64/python2.7/httplib.pyt endheaders)s   cCs|j||||dS(s&Send a complete request to the server.N(t _send_request(R)R\RtbodyR4((s,/opt/alt/python27/lib64/python2.7/httplib.pyR8scCsd}|dkr-|jtkr-d}n|dk rytt|}Wqttfk ry"ttj|j j }Wqtt fk r|j dkrdGHqqXqXn|dk r|j d|ndS(Nt0is Cannot stat!!sContent-Length(R'tuppert_METHODS_EXPECTING_BODYRR;t TypeErrortAttributeErrortostfstatRtst_sizetOSErrorRPR(R)RR\tthelen((s,/opt/alt/python27/lib64/python2.7/httplib.pyt_set_content_length<s  " c Cstjg|D]}|j^q }i}d|krGd|deZdZeZddddejdddZdZ RS(s(This class allows communication via SSL.c Csutj||||||||_||_|dkrItj}n|sU|rh|j||n||_dS(N( RR^tkey_filet cert_fileR'tsslt_create_default_https_contexttload_cert_chaint_context( R)RRRRRQRRtcontext((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^s    cCsMtj||jr"|j}n |j}|jj|jd||_dS(s(Connect to a host on a given (SSL) port.tserver_hostnameN(RRRRRt wrap_socketR[(R)R((s,/opt/alt/python27/lib64/python2.7/httplib.pyR s     N( RLRMRt HTTPS_PORTRR'RRR^R(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRs    tHTTPScBs/eZdZeZdddddddZRS(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. R1c CsS|dkrd}n|j|j|||||d|||_||_dS(NiR(R'RRRR(R)RRRRRQR((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^%s     N(RLRMRRRR'R^(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRs cCstjddtdd|S(Ns0FakeSocket is deprecated, and won't be in 3.x. s5Use the result of ssl.wrap_socket() directly instead.t stackleveli(twarningstwarntDeprecationWarning(R[tsslobj((s,/opt/alt/python27/lib64/python2.7/httplib.pyt FakeSocket6s  cBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyR=scBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyR BscBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyREscBseZdZRS(cCs|f|_||_dS(N(RRU(R)RU((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^Is (RLRMR^(((s,/opt/alt/python27/lib64/python2.7/httplib.pyR HscBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyR MscBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyR PscBs&eZddZdZdZRS(cCs"|f|_||_||_dS(N(Rtpartialtexpected(R)R R ((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^Ts  cCs<|jdk rd|j}nd}dt|j|fS(Ns, %i more expectedR1sIncompleteRead(%i bytes read%s)(R R'R;R (R)R((s,/opt/alt/python27/lib64/python2.7/httplib.pyt__repr__XscCs t|S(N(R_(R)((s,/opt/alt/python27/lib64/python2.7/httplib.pyt__str__^sN(RLRMR'R^R R (((s,/opt/alt/python27/lib64/python2.7/httplib.pyR Ss  cBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRascBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRdscBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRgscBseZRS((RLRM(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRjscBseZdZRS(cCs.|st|}n|f|_||_dS(N(R_RRJ(R)RJ((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^ns (RLRMR^(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRmsR@cBseZdZRS(cCstj|dt|fdS(Ns&got more than %d bytes when reading %s(RR^R?(R)t line_type((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^us (RLRMR^(((s,/opt/alt/python27/lib64/python2.7/httplib.pyR@tsRccBsJeZdZdZdZdZddZdZddZ 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)RJR((s,/opt/alt/python27/lib64/python2.7/httplib.pyR^s     cCst|j|S(N(tgetattrR(R)tattr((s,/opt/alt/python27/lib64/python2.7/httplib.pyt __getattr__scCs:d|_|jj|_|jj|_|jj|_dS(Ni(RRRwR>t readlines(R)((s,/opt/alt/python27/lib64/python2.7/httplib.pyt_dones cCs|jr|jj|S|js(t|dksC||jkr|j|j}|j|dkrz||jjS||jj|t |Snp||jkst|j}||}|j||!}||_|j|8_|jdkr|jn|SdS(Ni( RRRwRR|R'RRRR;(R)RyRzR~R((s,/opt/alt/python27/lib64/python2.7/httplib.pyRws$   !    cCsC|jr|jjS|js%t|j|j}|j|S(N(RRR>RR|RRR(R)Rz((s,/opt/alt/python27/lib64/python2.7/httplib.pyR>s    cCsz|jr|jj|S|js(t|j|jg}|j|dkrb||jjS||jj|SdS(N( RRRRR|RRRR'(R)tsizetL((s,/opt/alt/python27/lib64/python2.7/httplib.pyRs   N( RLRMRR^RRR'RwR>R(((s,/opt/alt/python27/lib64/python2.7/httplib.pyRc|s    (nRRRtreRtsysRturlparseRRtcatch_warningstfilterwarningsRt mimetoolst cStringIORt ImportErrort__all__RRRTRRRRgtSWITCHING_PROTOCOLSt PROCESSINGRtCREATEDtACCEPTEDtNON_AUTHORITATIVE_INFORMATIONRkt RESET_CONTENTtPARTIAL_CONTENTt MULTI_STATUStIM_USEDtMULTIPLE_CHOICEStMOVED_PERMANENTLYtFOUNDt SEE_OTHERRlt 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_EXTENDEDRRR?R<tcompileRRRRRRtMessageR$RRRRRRBRR t ExceptionRR RR R R R RRRRRR@RRc(((s,/opt/alt/python27/lib64/python2.7/httplib.pytCs6             ce[