Spade
Mini Shell
�
8��\c@sBddlZddlZddlZddlZddlmZmZddlZy ddl m
Z
mZmZWn9e
k
r�ddlm
Z
mZmZddlZnXddlmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZddl
m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*dd
l+m,Z,ddl-m.Z.ddl/m0Z0dd
l1m2Z2ddl3m4Z4ej5j6Z6ej7e8�Z9e:�Z;de:fd��YZ<e=ej>ej?g�Z@de<e*fd��YZAdeAfd��YZBd�ZCdS(i����N(terrorttimeout(t LifoQueuetEmptytFulli(tClosedPoolErrort
ProtocolErrortEmptyPoolErrortHostChangedErrortLocationValueErrort
MaxRetryErrort
ProxyErrortReadTimeoutErrortSSLErrortTimeoutErrortInsecureRequestWarning(tCertificateError(tsix(tport_by_schemetDummyConnectiontHTTPConnectiontHTTPSConnectiontVerifiedHTTPSConnectiont
HTTPExceptiontBaseSSLErrortConnectionError(tRequestMethods(tHTTPResponse(tis_connection_dropped(tRetry(tTimeout(tget_hosttConnectionPoolcBsJeZdZdZeZdd�Zd�Zd�Z d�Z
d�ZRS(sz
Base class for all connection pools, such as
:class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.
cCs4|std��n|jd�|_||_dS(NsNo host
specified.s[](R tstripthosttport(tselfR"R#((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt__init__?scCs
dt|�j|j|jfS(Ns%s(host=%r,
port=%r)(ttypet__name__R"R#(R$((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt__str__GscCs|S(N((R$((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt __enter__KscCs|j�tS(N(tclosetFalse(R$texc_typetexc_valtexc_tb((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt__exit__Ns
cCsdS(sD
Close all pooled connections and disable the pool.
N((((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR*SsN(R't
__module__t__doc__tNonetschemeRtQueueClsR%R(R)R/R*(((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR
6s tHTTPConnectionPoolc
Bs�eZdZdZeZdeej deddddd� Z
d�Zdd�Zd�Z
d�Zd�Zd �Zd
�Zed�Zd�Zd
�Zdddeeeddd�ZRS(sN
Thread-safe connection pool for one host.
:param host:
Host used for this HTTP Connection (e.g. "localhost"),
passed into
:class:`httplib.HTTPConnection`.
:param port:
Port used for this HTTP Connection (None is equivalent to 80),
passed
into :class:`httplib.HTTPConnection`.
:param strict:
Causes BadStatusLine to be raised if the status line can't be
parsed
as a valid HTTP/1.0 or 1.1 status line, passed into
:class:`httplib.HTTPConnection`.
.. note::
Only works in Python 2. This parameter is ignored in Python 3.
:param timeout:
Socket timeout in seconds for each individual connection. This can
be a float or integer, which sets the timeout for the HTTP request,
or an instance of :class:`urllib3.util.Timeout` which gives you
more
fine-grained control over request timeouts. After the constructor
has
been parsed, this is always a `urllib3.util.Timeout` object.
:param maxsize:
Number of connections to save that can be reused. More than 1 is
useful
in multithreaded situations. If ``block`` is set to false, more
connections will be created but they will not be saved once
they've
been used.
:param block:
If set to True, no more than ``maxsize`` connections will be used
at
a time. When no free connections are available, the call will block
until a connection has been released. This is a useful side effect
for
particular multithreaded situations where one does not want to use
more
than maxsize connections per host to prevent flooding.
:param headers:
Headers to include with all requests, unless other headers are
given
explicitly.
:param retries:
Retry configuration to use by default with requests in this pool.
:param _proxy:
Parsed proxy URL, should not be used directly, instead, see
:class:`urllib3.connectionpool.ProxyManager`"
:param _proxy_headers:
A dictionary with proxy headers, should not be used directly,
instead, see :class:`urllib3.connectionpool.ProxyManager`"
:param \**conn_kw:
Additional parameters are used to create fresh
:class:`urllib3.connection.HTTPConnection`,
:class:`urllib3.connection.HTTPSConnection` instances.
thttpic
Kstj|||�tj||�||_t|t�sMtj|�}n|dkretj }n||_
||_|j|�|_
||_| |_|
p�i|_x$t|�D]}|j
jd�q�Wd|_d|_||_|jr|jjdg�ndS(Nitsocket_options(R
R%Rtstrictt
isinstanceRt
from_floatR2RtDEFAULTRtretriesR4tpooltblocktproxyt
proxy_headerstxrangetputtnum_connectionstnum_requeststconn_kwt
setdefault(
R$R"R#R8RtmaxsizeR>theadersR<t_proxyt_proxy_headersREt_((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR%�s( c
Csi|jd7_tjd|j|jf�|jd|jd|jd|jjd|j|j �}|S(s9
Return a fresh :class:`HTTPConnection`.
is%Starting new HTTP connection (%d): %sR"R#RR8(
RCtlogtinfoR"t
ConnectionClsR#Rtconnect_timeoutR8RE(R$tconn((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt _new_conn�s cCs�d }y"|jjd|jd|�}WnKtk
rJt|d��n,tk
ru|jrvt|d��qvnX|r�t|�r�t j
d|j�|j�t
|dd�dkr�d }q�n|p�|j�S(
s�
Get a connection. Will return a pooled connection if one is
available.
If no connections are available and :prop:`.block` is ``False``,
then a
fresh connection is returned.
:param timeout:
Seconds to wait before giving up and raising
:class:`urllib3.exceptions.EmptyPoolError` if the pool is empty
and
:prop:`.block` is ``True``.
R>RsPool is closed.s>Pool reached maximum size and no more
connections are allowed.s Resetting dropped connection:
%st auto_openiiN(R2R=tgetR>tAttributeErrorRRRRRLRMR"R*tgetattrRQ(R$RRP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt _get_conn�s
"
cCsmy|jj|dt�dSWn5tk
r1n%tk
rUtjd|j�nX|ri|j�ndS(s�
Put a connection back into the pool.
:param conn:
Connection object for the current host and port as returned by
:meth:`._new_conn` or :meth:`._get_conn`.
If the pool is already full, the connection is closed and discarded
because we exceeded maxsize. If connections are discarded
frequently,
then maxsize should be increased.
If the pool is closed, then the connection will be closed and
discarded.
R>Ns2Connection pool is full, discarding connection:
%s( R=RBR+RTRRLtwarningR"R*(R$RP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt _put_conn�s
cCsdS(sU
Called right before a request is made, after the socket is created.
N((R$RP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt_validate_connscCsdS(N((R$RP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt_prepare_proxyscCsC|tkr|jj�St|t�r2|j�Stj|�SdS(s<
Helper that always returns a :class:`urllib3.util.Timeout`
N(t_DefaultRtcloneR9RR:(R$R((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt_get_timeout
s
cCs�t|t�r(t||d|��nt|d�r_|jtkr_t||d|��ndt|�ks�dt|�kr�t||d|��ndS(sAIs
the error actually a timeout? Will raise a ReadTimeout or passs!Read timed
out. (read timeout=%s)terrnos timed outsdid not complete
(read)N(R9t
SocketTimeoutRthasattrR^t_blocking_errnoststr(R$terrturlt
timeout_value((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt_raise_timeout,s$cKs�|jd7_|j|�}|j�|j|_y|j|�Wn;ttfk
r�}|jd|d|d|j��nX|j |||�|j
}t|dd�r|dkr�t
||d|��n|tjkr�|jjtj��q|jj|�ny:y|jdt�} Wntk
rI|j�} nXWn;tttfk
r�}|jd|d|d|��nXt|d d
�}
tjd|||
| j| jf�| S(
s
Perform a request on a given urllib connection object taken from
our
pool.
:param conn:
a connection from one of our connection pools
:param timeout:
Socket timeout in seconds for the request. This can be a
float or integer, which will set the same timeout value for
the socket connect and the socket read, or an instance of
:class:`urllib3.util.Timeout`, which gives you more
fine-grained
control over your timeouts.
iRcRdRetsockis!Read timed out. (read
timeout=%s)t bufferingt
_http_vsn_strsHTTP/?s"%s %s %s" %s
%sN(RDR]t
start_connectRORRYR_RRftrequesttread_timeoutRUR2RRtDEFAULT_TIMEOUTRgt
settimeouttsockettgetdefaulttimeouttgetresponsetTruet TypeErrortSocketErrorRLtdebugtstatustlength(R$RPtmethodRdRthttplib_request_kwttimeout_objteRlthttplib_responsethttp_version((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt
_make_request=s>
cCsa|jd}|_y6x/trG|jdt�}|r|j�qqWWntk
r\nXdS(sD
Close all pooled connections and disable the pool.
R>N(R=R2RrRSR+R*R(R$told_poolRP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR*�s
cCs�|jd�rtSt|�\}}}|jrJ|rJtj|�}n(|jrr|tj|�krrd}n|||f|j|j|jfkS(sj
Check if the given ``url`` is a member of the same host as this
connection pool.
t/N( t
startswithRrRR#RRSR2R3R"(R$RdR3R"R#((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pytis_same_host�s cKs�|dkr|j}nt|t�sHtj|d|d|j�}n|
dkri|jdt�}
n|r�|j|�r�t |||��nd}|j
dkr�|j�}|j|j
�nd}
zy�|j|�}|jd| �}|j|_|jdk o
t|dd�}|r9|j|�n|j|||d|d|d|�}|
oj|}tj|d |d
||�}WnOtk
r�t|d��n0ttfk
r�}|r�|j�d}nt|��n�tk
r|r|j�d}n�n�ttt t!fk
r�}|rK|j�d}nt|t �ru|jrut"d|�}n't|t
tf�r�t#d
|�}n|j$||d|d|dt%j&�d�}|j'�|}
nXWd|
r�|j(|�nX|sMt)j*d||
|f�|j+|||||||d|d| d|
|�S|o\|j,�}|r|j-dkr}d}ny"|j$||d|d|�}Wn!t.k
r�|j/r��n|SXt)j0d||f�|j+||||d|d|d|d|d| d|
|�S|j1|d|j-�r�|j$||d|d|�}|j'�t)j0d|�|j+||||d|d|d|d|d| d|
|�S|S(s
Get a connection from the pool and perform an HTTP request. This is
the
lowest level call for making a request, so you'll need to
specify all
the raw details.
.. note::
More commonly, it's appropriate to use a convenience method
provided
by :class:`.RequestMethods`, such as :meth:`request`.
.. note::
`release_conn` will only behave as expected if
`preload_content=False` because we want to make
`preload_content=False` the default behaviour someday soon
without
breaking backwards compatibility.
:param method:
HTTP request method (such as GET, POST, PUT, etc.)
:param body:
Data to send in the request body (useful for creating
POST requests, see HTTPConnectionPool.post_url for
more convenience).
:param headers:
Dictionary of custom headers to send, such as User-Agent,
If-None-Match, etc. If None, pool headers are used. If
provided,
these headers completely replace any pool-specific headers.
:param retries:
Configure the number of retries to allow before raising a
:class:`~urllib3.exceptions.MaxRetryError` exception.
Pass ``None`` to retry until you receive a response. Pass a
:class:`~urllib3.util.retry.Retry` object for fine-grained
control
over different types of retries.
Pass an integer number to retry connection errors that many
times,
but no other types of errors. Pass zero to never retry.
If ``False``, then retries are disabled and any exception is
raised
immediately. Also, instead of raising a MaxRetryError on
redirects,
the redirect response will be returned.
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an
int.
:param redirect:
If True, automatically handle redirects (status codes 301, 302,
303, 307, 308). Each redirect counts as a retry. Disabling
retries
will disable redirect, too.
:param assert_same_host:
If ``True``, will make sure that the host of the pool requests
is
consistent else will raise HostChangedError. When False, you
can
use the pool on an HTTP proxy and request foreign hosts.
:param timeout:
If specified, overrides the default timeout for this one
request. It may be a float (in seconds) or an instance of
:class:`urllib3.util.Timeout`.
:param pool_timeout:
If set and the pool is set to block=True, then this method will
block for ``pool_timeout`` seconds and raise EmptyPoolError if
no
connection is available within the time period.
:param release_conn:
If False, then the urlopen call will not release the connection
back into the pool once a response is received (but will
release if
you read the entire contents of the response such as when
`preload_content=True`). This is useful if you're not
preloading
the response's content immediately. You will need to call
``r.release_conn()`` on the response ``r`` to return the
connection
back into the pool. If None, it takes the value of
``response_kw.get('preload_content', True)``.
:param \**response_kw:
Additional parameters are passed to
:meth:`urllib3.response.HTTPResponse.from_httplib`
tredirecttdefaulttpreload_contentR6RRgtbodyRHR=t
connections"No pool connections are available.sCannot connect to
proxy.sConnection aborted.Rt_poolt_stacktraceiNs1Retrying (%r) after
connection broken by '%r':
%stpool_timeouttrelease_conni/tGETtresponsesRedirecting %s ->
%sR<tassert_same_hosttstatus_codesForced retry:
%s(2R2RHR9Rtfrom_intR<RSRrR�RR3tcopytupdateR@R]RVRORR?RURZR~Rtfrom_httplibRRRRR*R
RRRtRRRt incrementtsystexc_infotsleepRXRLRWturlopentget_redirect_locationRvR
traise_on_redirectRMtis_forced_retry(R$RxRdR�RHR<R�R�RR�R�tresponse_kwRPRcRztis_new_proxy_connR|t
response_connR�R{tredirect_location((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR��s�S!"
"
N(R'R0R1R3RRNR2R+RRmR%RQRVRXRYRZR]RfR[R~R*R�RrR�(((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR5^s(:%
& E tHTTPSConnectionPoolcBszeZdZdZeZd
eej ded
d
d
d
d
d
ddd
d
d
d�Z
d�Zd�Zd�Z
d �ZRS(s�
Same as :class:`.HTTPConnectionPool`, but HTTPS.
When Python is compiled with the :mod:`ssl` module, then
:class:`.VerifiedHTTPSConnection` is used, which *can* verify
certificates,
instead of :class:`.HTTPSConnection`.
:class:`.VerifiedHTTPSConnection` uses one of ``assert_fingerprint``,
``assert_hostname`` and ``host`` in this order to verify connections.
If ``assert_hostname`` is False, no verification is done.
The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs`` and
``ssl_version`` are only used if :mod:`ssl` is available and are fed
into
:meth:`urllib3.util.ssl_wrap_socket` to upgrade the connection socket
into an SSL socket.
thttpsit
CERT_REQUIREDs/etc/ssl/certs/ca-bundle.crtc
Ksqtj|||||||||| |
|�||_||_|
|_||_||_||_||_dS(N( R5R%tkey_filet cert_filet cert_reqstca_certstssl_versiontassert_hostnametassert_fingerprint(R$R"R#R8RRGR>RHR<RIRJR�R�R�R�R�R�R�RE((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR%�s c
Csbt|t�r^|jd|jd|jd|jd|jd|jd|j�|j |_ n|S(s�
Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket`
and establish the tunnel if proxy is used.
R�R�R�R�R�R�(
R9Rtset_certR�R�R�R�R�R�R�(R$RP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt
_prepare_conn�s
cCs�y
|j}Wntk
r)|j}nXtjdkrY|jrY||j|j�n||j|j|j�|j�dS(s�
Establish tunnel connection early, because otherwise httplib
would improperly set Host: header to proxy's IP:port.
iiiN(iii( t
set_tunnelRTt_set_tunnelR�tversion_infoR@R"R#tconnect(R$RPR�((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyRZ�s
cCs�|jd7_tjd|j|jf�|jsE|jtkrTtd��n|j}|j}|jdk r�|jj}|jj}n|jd|d|d|j
jd|j|j
�}|j|�S( sB
Return a fresh :class:`httplib.HTTPSConnection`.
is&Starting new HTTPS connection (%d): %ssCCan't connect
to HTTPS URL because the SSL module is not
available.R"R#RR8N(RCRLRMR"RNRR
R#R?R2RROR8RER�(R$tactual_hosttactual_portRP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyRQ�s cCsUtt|�j|�t|dd�s5|j�n|jsQtjdt �ndS(sU
Called right before a request is made, after the socket is created.
Rgs�Unverified HTTPS request is being made. Adding certificate
verification is strongly advised. See:
https://urllib3.readthedocs.org/en/latest/security.htmlN(
tsuperR�RYRUR2R�tis_verifiedtwarningstwarnR(R$RP((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyRY�s
N(R'R0R1R3RRNR2R+RRmR%R�RZRQRY(((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyR��s cKsKt|�\}}}|dkr4t|d||�St|d||�SdS(s�
Given a url, return an :class:`.ConnectionPool` instance of its host.
This is a shortcut for not having to parse out the scheme, host, and
port
of the url before creating an :class:`.ConnectionPool` instance.
:param url:
Absolute URL string that must include the scheme. Port is optional.
:param \**kw:
Passes additional parameters to the constructor of the appropriate
:class:`.ConnectionPool`. Useful for specifying things like
timeout, maxsize, headers, etc.
Example::
>>> conn =
connection_from_url('http://google.com/')
>>> r = conn.request('GET', '/')
R�R#N(RR�R5(RdtkwR3R"R#((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pytconnection_from_urls(DR^tloggingR�R�RoRRtRR_tqueueRRRtImportErrortQueueRKt
exceptionsRRRRR R
RRR
RRtpackages.ssl_match_hostnameRtpackagesRR�RRRRRRRRRkRR�Rtutil.connectionRt
util.retryRtutil.timeoutRtutil.urlRtmovesRAt getLoggerR'RLtobjectR[R
tsettEAGAINtEWOULDBLOCKRaR5R�R�(((s:/usr/lib/python2.7/site-packages/urllib3/connectionpool.pyt<module>s<
L
: %��1w