��c@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ej
e�ZddgZ
dZdZdd>Zdd >Zd
ZdZdZd
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�NtHTTPConnectiontHTTPResponsesHTTP/1.0sHTTP/1.1iiisaccept-encodingt
connectionscontent-lengthstransfer-encodingtchunkedtcloses
icBs_eZdZd�Zed��Zd�Zd�Zd�Zd d�Z
d�Zd�ZRS(
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(tsocktmethodtraw_responset_headers_lentNonetheaderstFalset
will_closetstatus_linetstatust continuedthttp_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�}|jdt jkr��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_READtdebugRtlenRRRt_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
|_tjd|�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�|_#tjd�n�|j$dks�|j$d
kr�|dkr�d}n|dk r�jd|�t!j%|�|_#n%t!j&�|_#tjd�t
|_|r<|j#j'|�ntjd�||_|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+RRtsplitt
startswithRRR3RRRRtintRtreplacetrfc822tMessaget cStringIOtStringIOR
tHDR_CONTENT_LENGTHtHTTP_VER_1_0R
tHDR_CONNECTION_CTRLtlowertCONNECTION_CLOSEtHDR_XFER_ENCODINGtXFER_ENCODING_CHUNKEDt_readerst
ChunkedReaderRRtContentLengthReadertCloseIsEndReadert_loadR5( RR7tbad_eolthdrstbodythttp_verRRtcontent_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�Zd�Zd�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�jr�d��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@Rtportt
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
|jfit�}|j
|�|jd�|j||jd�}td�}xR|j�sy(|j�s�j�s��q�Wq�tk
r|�q�Xq�W|jdkrEtd|j|j�f��ntjd |j
|j�qntj|j
|jf�}|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_connectionRctbuildheadersRfR_RGtsendtsetblockingtresponse_classRR,RR!RtHTTPProxyConnectFailedExceptionR&R3Rdtwrap_socketRe(RRR7R(ttimeout_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�|jr�|ddks�td��d ||f}nd
|||tfg}d|f|d<td
f|t<x4|j�D]&\}}|jd||tf�q�jt�dj |�S(Ni�iPR[s[%s]:%ds%s:%dit/spath must start with a /shttp://%s%ss
%s %s %s%stHostRftidentitys%s: %s%sR(
RcR_RfRitAssertionErrorRtHDR_ACCEPT_ENCODINGt
itervaluestappendR"( RRtpathRRUthdrhosttoutgoingthdrtval((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyRp{s'
cCsF|jdkrdS|jj�d|_tjd|j|j�dS(s�Close the connection to the server.
This is a no-op if the connection is already closed. The
connection may automatically close if requested by the server
or required by the nature of a response.
Nsclosed connection to %s on %s(RR
RR*R+RfR_(R((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR�s
cCsa|j}|dk r]|jrY|jr=d|_d|_tS|j�rYd|_tSntStS(s�Returns True if this connection object is currently in use.
If a response is still pending, this will return True, even if
the request has finished sending. In the future,
HTTPConnection may transparently juggle multiple connections
to the server, in which case this will be useful to detect if
any of those connections is ready for use.
N(RgR
RhR
RRRR(Rtcr((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pytbusy�s cs/�j�rtjd��nt�_tjd||�j�j�t d�|j
�D��}|jdd�dj�dkr�t
}n|r�d|d<nt}|rt|krt|d
t�r�t|�f|t<qt|dt�rttf|t<t
}qtd��n�j��j|||�j�}d} t
}
�fd
�}xF|sl|r�| o{| j�r��j}|p�|}
t}|r�r� o�| jp�| jr�jd�j��j}t
}t}
n|
r�jg}ng}tj�jg|g|�\}}}||koO|koOgknr|rpt}tjd�qtd��n|
}|ryVy|dj t!�}WnBt"j#k
r�}|j$dt"j%kr��ntj&d�w`nX|s�tjd�d�_d�_'| dk r(| j(�n| dk rQ| j�rQtjd�Pq�|r�| dkr�tjd�|d�w`q�t)d��ntj&dt|��| dkr��j*|d�j|�} n| j+|�w`Wqt"j,k
r}|dt-j.kr|r�qqXn|r`|
r`y�t|
dt�r�|
j/t0�}|sYw`nt|�t0kr�|r�dt1t1}q�d}n|r�t2t|��dt1|t1}
q�|}
n|dj3|
�}Wn}t"j,k
rR}|dt"j4kr
�j5r
q`n)|dt-j6t-j.fkr3|
r3�n|d��jj3|
�}nXtj&d|�t}
|r||
| }n|
|kr�|
|}q�|
|}q`q`W| dkr��j*�j�j|�} n| j�}t7|p��}|r
tjd�t
| _8n| j8r"d�_n| �_'dS( s�Send a request to the server.
For increased flexibility, this does not return the response
object. Future versions of HTTPConnection that juggle multiple
sockets will be able to send (for example) 5 requests all at
once, and then let the requests arrive as data is
available. Use the `getresponse()` method to retrieve the
response.
s=Can not send another request before current response is read!s*sending %s request for %s to %s on port %scss-|]#\}}|j�||ffVqdS(N(RI(t.0tktv((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pys <genexpr>�stexpectRis100-continuetExpects100-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�s100-Continue(9R�thttplibtCannotSendRequestRRhR*R+RfR_tdictt iteritemstgetRIRRFtgetattrR4RKRLtBadRequestDataRwRpRR
RRRRRkRR)R,R-R.R/R0R1R2R3RgRtHTTPStateErrorRsR5terrorterrnotEPIPER&tOUTGOING_BUFFER_SIZERthexRqtSSL_ERROR_WANT_WRITERct
ECONNRESETtboolR
(RRRRTRtexpect_continueRSRtoutgoing_headerstresponsetfirstR�tselect_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
R�tResponseNotReadyRR!RRMtHTTPRemoteClosedErrorR
RRRh(RR(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pytgetresponsews N(RWRXRYtHTTP_VER_1_1RRRsR
tTIMEOUT_DEFAULTtTIMEOUT_ASSUME_CONTINUERRwRpRR�RR�R�(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR
s . 4
�,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__.pyRt�sR�cBseZdZRS(s#Invalid internal state encountered.(RWRXRY(((sA/sys/lib/python2.7/site-packages/mercurial/httpclient/__init__.pyR��s(&RYRDR�R�tloggingRBR)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<module>&sB
��
|