ó ŸçƒQc@sŠdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ej e ƒZ ddgZ dZdZdd>Zdd >Zd Zd Zd Zd ZdZdZdZedZdZeZdefd„ƒYZdefd„ƒYZdej fd„ƒYZ!dej fd„ƒYZ"dej fd„ƒYZ#dej fd„ƒYZ$ej%Z%dS(sXImproved HTTP/1.1 client library This library contains an HTTPConnection which is similar to the one in httplib, but has several additional features: * supports keepalives natively * uses select() to block for incoming data * notices when the server responds early to a request * implements ssl inline instead of in a different class iÿÿÿÿNtHTTPConnectiont HTTPResponsesHTTP/1.0sHTTP/1.1iiisaccept-encodingt connectionscontent-lengthstransfer-encodingtchunkedtcloses icBs_eZdZd„Zed„ƒZd„Zd„Zd„Zd d„Z d„Z d„Z RS( s¯Response from an HTTP server. The response will continue to load as available. If you need the complete response before continuing, check the .complete() method. cCs‹||_||_d|_d|_d|_t|_d|_d|_ t|_ d|_ d|_ d|_ d|_t|_||_dS(Nti(tsocktmethodt raw_responset _headers_lentNonetheaderstFalset will_closet status_linetstatust continuedt http_versiontreasont_readert_read_locationtEOLt_eolt_timeout(tselfRttimeoutR((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyt__init__Us              cCs |jdS(Ni(R(R((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyt _end_headershscCs|jr|jjƒSdS(sReturns true if this response is completely loaded. Note that if this is a connection where complete means the socket is closed, this will nearly always return False, even in cases where all the data has actually been loaded. N(Rtdone(R((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pytcompletels cCs#|jdk r|jjƒndS(N(RR t_close(R((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyRvscCsgg}xQtrY|jjd|ƒ|r<|dddksH|jƒrLPn|jƒq Wdj|ƒS(s”Read a single line from the response body. This may block until either a line ending is found or the response is complete. s iÿÿÿÿR(tTrueRtreadtoRt_selecttjoin(Rtblocks((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pytreadlinezs &cCs‡x4|jƒ r6| s)||jjkr6|jƒqW|sL|jj}n|jj|ƒ}|jƒrƒ|jrƒ|jjƒn|S(N(RRtavailable_dataR!treadR RR(Rtlengthtr((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR&‹scCstj|jggg|jƒ\}}}|sa|jƒsatjd|jƒtdƒ‚qany|jjtƒ}Wn@t j k r¹}|j dt j kr¨‚ntj dƒtSXtj dt|ƒƒ|só|jrï|jjƒntS|j|ƒtSdS(Nstimed out with timeout of %sstimeout reading datais2SSL_ERROR_WANT_READ in _select, should retry laters$response read %d data during _select(tselectRRRtloggertinfotHTTPTimeoutExceptiontrecvtINCOMING_BUFFER_SIZEtsockettsslerrortargstSSL_ERROR_WANT_READtdebugRtlenRRR t_load_response(RR(t_tdatate((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR!˜s&*    c Cse|j|7_|j|jkr†xbdD]W}||jkr(|jj|ƒt|jƒdkr(tjd|ƒ||_Pq(q(Wn|j|jks¡|jr¥dS|jj|jdƒ\}}|jddƒ\}}|j dƒr||_t |_ tj d|ƒdS|jj|jdƒ\}}|`|j|krd|j|jdƒ\|_ }n||_ d}|j jdd ƒ\|_|_|_t|jƒ|_|jtkrÓ|j|jd ƒ}ntjtj|ƒƒ}d}t|krt|tƒ}n|jtkr+t |_n(t|krS|tjƒtk|_nt|krš|tjƒt kršt!j"|jƒ|_#tj d ƒn‰|j$d ksÄ|j$d krÍ|dkrÍd}n|dk rþtj d|ƒt!j%|ƒ|_#n%t!j&ƒ|_#tj dƒt |_|r<|j#j'|ƒntj dƒ||_|j#j'|_(dS(Ns s is-bogus line endings detected, using %r for EOLt t100s!continue seen, setting body to %rRis susing a chunked readertHEADtCONNECTis,using a content-length reader with length %dsusing a close-is-end readersheaders complete(s s ()RRtindexR4R*R+RR tsplitt startswithRRR3RRRRtintRtreplacetrfc822tMessaget cStringIOtStringIOR tHDR_CONTENT_LENGTHt HTTP_VER_1_0R tHDR_CONNECTION_CTRLtlowertCONNECTION_CLOSEtHDR_XFER_ENCODINGtXFER_ENCODING_CHUNKEDt_readerst ChunkedReaderRRtContentLengthReadertCloseIsEndReadert_loadR5( RR7tbad_eolthdrstbodythttp_verRR t content_len((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR5³sp      ! '            N( t__name__t __module__t__doc__RtpropertyRRRR$R R&R!R5(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyROs    cBsteZdZeZeZdddee dd„Z d„Z d„Z d„Z d„Zdied„Zd„ZRS( s’Connection to a single http server. Supports 100-continue and keepalives natively. Uses select() for non-blocking socket operations. c Ks|d kr!|jdƒdks-d|krp|jddƒ\}}t|ƒ}d|krp|dd!}qpn|d kr—|d kr—t}d}n<|d kr²|dk}n!|d krÓ|rÊdpÍd}n||_|rûtj rûtdƒ‚n||_ ||_ ||_ ||_ d |_ d |_t|_|d krYd |_|_n|\|_|_||_||_d S( sCreate a new HTTPConnection. Args: host: The host to which we'll connect. port: Optional. The port over which we'll connect. Default 80 for non-ssl, 443 for ssl. use_ssl: Optional. Whether to use ssl. Defaults to False if port is not 443, true if port is 443. ssl_validator: a function(socket) to validate the ssl cert timeout: Optional. Connection timeout, default is TIMEOUT_DEFAULT. continue_timeout: Optional. Timeout for waiting on an expected "100 Continue" response. Default is TIMEOUT_ASSUME_CONTINUE. proxy_hostport: Optional. Tuple of (host, port) to use as an http proxy for the connection. Default is to not use a proxy. t:is]:t[iÿÿÿÿiPi»s,ssl requested but unavailable on this PythonN(R tcounttrsplitR@R tportt socketutilthave_sslt Exceptiontssltssl_optst_ssl_validatorthostRt_current_responset_current_response_takent _proxy_hostt _proxy_portRtcontinue_timeout( RRfR_tuse_sslt ssl_validatorRRktproxy_hostportRd((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyRs6-               cCsó|jr dS|jdk rdtjd|j|jƒtj|j|jfƒ}|jr|j dd|j |j fit ƒ}|j |ƒ|jdƒ|j||jdƒ}tdƒ}xR|jƒsy(|jƒsõ|jƒsõ|‚qõnWqÂtk r|‚qÂXqÂW|jdkrEtd|j|jƒfƒ‚ntjd |j |j ƒqntj|j |j fƒ}|jrÙ|jd ƒtjd |jƒtj||j}|jrÙ|j|ƒqÙn|jdƒ||_dS( s3Connect to the host and port specified in __init__.NsConnecting to http proxy %s:%sR<s%s:%dis1Timed out waiting for CONNECT response from proxyiÈsProxy connection failed: %d %ss/CONNECT (for SSL) to %s:%s via proxy succeeded.is'wrapping socket for ssl with options %r(RRiR R*R+RjR`tcreate_connectionRct buildheadersRfR_RGtsendt setblockingtresponse_classRR,RR!RtHTTPProxyConnectFailedExceptionR&R3Rdt wrap_socketRe(RRR7R(t timeout_exc((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyt_connectGsN                    c Cs=|jr|jdks'|jdkr3|j}n>d|jkr[d|j|jf}nd|j|jf}|jr³|j r³|ddks tdƒ‚d ||f}nd |||tfg}d |f|d ËstexpectRis 100-continuetExpects 100-Continuet__len__R&s body has no __len__() nor read()cs(tjd|ƒˆjƒˆjƒdS(Nsreconnecting during %s(R*R+RRw(twhere(R(sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyt reconnectâs s:waiting up to %s seconds for continue response from serversTno response to continue expectation from server, optimistically sending request bodystimeout sending datais3SSL_ERROR_WANT_READ while sending data, retrying...ssocket appears closed in reads2Got an early response, aborting remaining request.sOConnection appeared closed in read on first request loop iteration, will retry.sjConnection appears closed after some request data was written, but the response was missing or incomplete!sread %d bytes in request()t0itwritessent %ds@stopped sending request early, will close the socket to be safe.N(RR(RŠs 100-Continue(9R…thttplibtCannotSendRequestR RhR*R+RfR_tdictt iteritemstgetRIRRFtgetattrR4RKRLtBadRequestDataRwRpRR RRR RRkRR)R,R-R.R/R0R1R2R3RgRtHTTPStateErrorRsR5terrorterrnotEPIPER&tOUTGOING_BUFFER_SIZERthexRqtSSL_ERROR_WANT_WRITERct ECONNRESETtboolR (RRRRTR texpect_continueRSRtoutgoing_headerstresponsetfirstRtselect_timeouttouttblocking_on_continuetwR(txt was_firstR7R8tamtt sent_dataRt data_left((RsA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pytrequest¸sô    "           ''             %           cCs©|jdkrtjƒ‚n|j}x<|jdkre|jƒ r*|jƒ r*tjƒ‚q*q*W|j r„d|_ d|_n!|jƒrœd|_n t |_ |S(N( RgR RtResponseNotReadyR R!RRMtHTTPRemoteClosedErrorR RRRh(RR(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyt getresponsews       N(RWRXRYt HTTP_VER_1_1RRRsR tTIMEOUT_DEFAULTtTIMEOUT_ASSUME_CONTINUERRwRpRR…R R­R°(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR s  . 4   ¾R,cBseZdZRS(s/A timeout occurred while waiting on the server.(RWRXRY(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR,ˆsR–cBseZdZRS(s1Request body object has neither __len__ nor read.(RWRXRY(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR–ŒsRtcBseZdZRS(s$Connecting to the HTTP proxy failed.(RWRXRY(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyRtsR—cBseZdZRS(s#Invalid internal state encountered.(RWRXRY(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR—”s(&RYRDR™RtloggingRBR)R/RMR`t getLoggerRWR*t__all__RGR±R›R.R|RHRFRKRLRJRt _END_HEADERSR³R R²tobjectRRt HTTPExceptionR,R–RtR—R¯(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyt&sB             ¾ÿ|