ó gP¾[c@sûddlZddlZddlmZmZddlZy0ddlmZm Z ddlm Z m Z Wn=e k r©ddl mZm Z ddl m Z m Z nXy ddlmZmZmZWn9e k rddlmZmZmZddlZnXyseZdefd„ƒYZeZyddlmZWn!e k rbddl mZnXddlZejZWne efk r’nXd d lmZmZmZm Z m!Z!mZm"Z"m#Z#d d l$m%Z%m&Z&ddl'Z'd d l(m)Z)d d l*m+Z+d dl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3e'j4j5Z5ej6e7ƒZ8eƒZ9ie d6e d6Z:defd„ƒYZ;defd„ƒYZ<e=ej>ej?gƒZ@de<e)fd„ƒYZAdeAfd„ƒYZBd„ZCdS(iÿÿÿÿN(terrorttimeout(tHTTPConnectiont HTTPException(t HTTP_PORTt HTTPS_PORT(t LifoQueuetEmptytFullt BaseSSLErrorcBseZRS((t__name__t __module__(((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyR s(tHTTPSConnectioni(tClosedPoolErrortConnectTimeoutErrortEmptyPoolErrortHostChangedErrort MaxRetryErrortSSLErrortReadTimeoutErrort ProxyError(tCertificateErrortmatch_hostname(tRequestMethods(t HTTPResponse(tassert_fingerprinttget_hosttis_connection_droppedtresolve_cert_reqstresolve_ssl_versiontssl_wrap_sockettTimeoutthttpthttpstVerifiedHTTPSConnectioncBsDeZdZdZdZdZddddddd„Zd„ZRS(s[ Based on httplib.HTTPSConnection but wraps the socket with SSL certification. t CERT_REQUIREDs"/etc/ssl/certs/ca-certificates.crtcCs:||_||_||_||_||_||_dS(N(tkey_filet cert_filet cert_reqstca_certstassert_hostnameR(tselfR$R%R&R'R(R((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pytset_cert_s      c Cs^y+tjd|j|jfd|jƒ}Wn0tk r]t|d|j|jfƒ‚nXt|jƒ}t |j ƒ}|j r­||_ |j ƒd|_|j }n |j}t||j|jd|d|jd|d|ƒ|_ |tjkrZ|jr&t|j jd tƒ|jƒqZ|jtk rZt|j jƒ|jpP|ƒqZndS( NtaddressRs0Connection to %s timed out. (connect timeout=%s)iR&R'tserver_hostnamet ssl_versiont binary_form(tsockettcreate_connectionthosttportRt SocketTimeoutRRR&RR-t _tunnel_hosttsockt_tunnelt auto_openRR$R%R'tsslt CERT_NONERt getpeercerttTrueR(tFalseR(R)R5tresolved_cert_reqstresolved_ssl_versiont actual_host((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pytconnectjs8            N( R R t__doc__R&R'tNoneR-R*R@(((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyR"Us tConnectionPoolcBs/eZdZdZeZdd„Zd„ZRS(sz Base class for all connection pools, such as :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`. cCs%|jdƒ}||_||_dS(Ns[](tstripR1R2(R)R1R2((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt__init__ s cCs dt|ƒj|j|jfS(Ns%s(host=%r, port=%r)(ttypeR R1R2(R)((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt__str__§sN( R R RARBtschemeRtQueueClsRERG(((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyRC—s  tHTTPConnectionPoolc BsžeZdZdZd eejded d d d„Zd„Z d d„Z d„Z d„Z e d„Zd „Zd „Zd d d eee d d d „ZRS(s5 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 _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`" R ic CsÆtj|||ƒtj||ƒ||_t|tƒsMtj|ƒ}n||_|j|ƒ|_ ||_ ||_ | pƒi|_ x$t |ƒD]} |j jdƒq–Wd|_d|_dS(Ni(RCRERtstrictt isinstanceRt from_floatRRItpooltblocktproxyt proxy_headerstxrangetputRBtnum_connectionst num_requests( R)R1R2RKRtmaxsizeROtheaderst_proxyt_proxy_headerst_((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyREås     cCs¡|jd7_tjd|j|jfƒi}tjsK|j|dPool reached maximum size and no more connections are allowed.s Resetting dropped connection: %sR7iiN(RBRNtgetROtAttributeErrorR RRRR[R\R1tcloseR`Rc(R)RRb((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt _get_conns "      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. RONs5HttpConnectionPool is full, discarding connection: %s( RNRSR<ReRR[twarningR1Rf(R)Rb((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt _put_connAs   cCsC|tkr|jjƒSt|tƒr2|jƒStj|ƒSdS(s< Helper that always returns a :class:`urllib3.util.Timeout` N(t_DefaultRtcloneRLRRM(R)R((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt _get_timeout^s    c Ks×|jd7_|j|ƒ}y-|jƒ|j|_|j|||Wn0tk r}t|d|j|jfƒ‚nX|j }t j d|ƒt |dƒrú|d k rú|tjk rú|dkrçt||d|ƒ‚n|jj|ƒny:y|jdtƒ}Wntk r2|jƒ}nXWndtk r]t||d|ƒ‚n>tk rš} | jtkr”t||d|ƒ‚n‚nXt|dd ƒ} t j d ||| |j|jfƒ|S( s Perform a request on a given httplib 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. is0Connection to %s timed out. (connect timeout=%s)sSetting read timeout to %sR5is!Read timed out. (read timeout=%s)t bufferingt _http_vsn_strsHTTP/?s"%s %s %s" %s %sN(RURlt start_connectR_RtrequestR3RR1t read_timeoutR[tdebugthasattrRBRtDEFAULT_TIMEOUTRR5t settimeoutt getresponseR;t TypeErrort SocketErrorterrnot_blocking_errnosR`tstatustlength( R)RbtmethodturlRthttplib_request_kwt timeout_objRqthttplib_responsetet http_version((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt _make_requestjsN        cCsa|jd}|_y6x/trG|jdtƒ}|r|jƒqqWWntk r\nXdS(sD Close all pooled connections and disable the pool. RON(RNRBR;RdR<RfR(R)told_poolRb((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyRf¶s  cCso|jdƒrtSt|ƒ\}}}|jrJ| rJtj|ƒ}n|||f|j|j|jfkS(sj Check if the given ``url`` is a member of the same host as this connection pool. t/(t startswithR;RR2tport_by_schemeRdRHR1(R)R~RHR1R2((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt is_same_hostÆs ic Ks |dkr|j}n|dkr6t||ƒ‚n| dkrW| jdtƒ} n|r†|j|ƒ r†t|||dƒ‚nd} zŸyh|jd| ƒ} |j| ||d|d|d|ƒ} | oÕ| }t j | d|d|| }Wn0t k rt ||d ƒ‚nt k r>t ||d ƒ‚nìtk r•}d t|ƒksqd t|ƒkr†t ||d ƒ‚nt|ƒ‚n•tk r³}t|ƒ‚nwttfk r)}t|tƒrù|jdk rùtd |ƒ‚nd} |}|dkr*t|||ƒ‚q*nXWd| rD|j| ƒnX| stjd|||fƒ|j|||||d||d|d| d| | S|o¬|jƒ}|r|jdkrÍd}ntjd||fƒ|j|||||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: Number of retries to allow before raising a MaxRetryError exception. :param redirect: If True, automatically handle redirects (status codes 301, 302, 303, 307, 308). Each redirect counts as a retry. :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` itpreload_contentiRtbodyRWRNt connections2Read timed out, no pool connections are available.sRead timed out.s timed outsdid not complete (read)s*Cannot connect to proxy. Socket error: %s.NsARetrying (%d attempts remain) after connection broken by '%r': %st pool_timeoutt release_conni/tGETsRedirecting %s -> %s(RBRWRRdR;R‰RRgR„Rt from_httplibRRR3R tstrRRRRxRLRPRRiR[twarnturlopentget_redirect_locationR{R\(R)R}R~R‹RWtretriestredirecttassert_same_hostRRRŽt response_kwRbRt response_conntresponseR‚terrtredirect_location((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyR“×svE                  N(R R RARHRBR<RRtRERcRgRiRlRjR„RfR‰R;R“(((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyRJ®s3   '  L    tHTTPSConnectionPoolcBs\eZdZdZdeddeddddddddddd„Zd„Zd„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:`httplib.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. R!iR#s"/etc/ssl/certs/ca-certificates.crtc Csktj|||||||||| ƒ | |_| |_| |_| |_||_||_||_dS(N( RJRER$R%R&R'R-R(R(R)R1R2RKRRVRORWRXRYR$R%R&R'R-R(R((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyRE˜s      c CsÁt|tƒr^|jd|jd|jd|jd|jd|jd|jƒ|j |_ n|j dk r½y |j }Wnt k r–|j}nX||j|j|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(RN(RLR"R*R$R%R&R'R(RR-RPRBt set_tunnelRet _set_tunnelR1R2RQR@(R)RŒRž((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pyt _prepare_connªs          c Csï|jd7_tjd|j|jfƒ|j}|j}|jdk rh|jj}|jj}nts™t stt krt dƒ‚nt}nt }i}t j s¾|j|d>> conn = connection_from_url('http://google.com/') >>> r = conn.request('GET', '/') R!R2N(RRRJ(R~tkwRHR1R2((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pytconnection_from_urlæs (DRytloggingR/RRxRR3t http.clientRRRRt ImportErrorthttplibtqueueRRRtQueueRZR¡R t BaseExceptionR RBR8RRet exceptionsR RRRRRRtpackages.ssl_match_hostnameRRR]RpRRšRtutilRRRRRRRtmovesRRt getLoggerR R[RjRˆR"RCtsettEAGAINt EWOULDBLOCKRzRJRR¥(((s:/usr/lib/python2.7/dist-packages/urllib3/connectionpool.pytsZ         :  4   Bÿ×b