ž 7’Reic @sddlZddlZddlZddlmZmZddlZy ddlm Z m Z m Z Wn:e k r¢ddl m Z m Z m Z ddl ZYnXddlmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dd l'm(Z(dd l)m*Z*dd l+m,Z,m-Z-m.Z.ej/j0Z0ej1e2ƒZ3e4ƒZ5Gd d „d e4ƒZ6e7ej8ej9gƒZ:Gdd„de6e(ƒZ;Gdd„de;ƒZ<dd„Z=dS(iN(uerrorutimeout(u LifoQueueuEmptyuFulli( uClosedPoolErroruConnectionErroruConnectTimeoutErroruEmptyPoolErroruHostChangedErroruLocationParseErroru MaxRetryErroruSSLErroru TimeoutErroruReadTimeoutErroru ProxyError(uCertificateError(usix(uport_by_schemeuDummyConnectionuHTTPConnectionuHTTPSConnectionuVerifiedHTTPSConnectionu HTTPExceptionu BaseSSLError(uRequestMethods(u HTTPResponse(uget_hostuis_connection_droppeduTimeoutcBsA|EeZdZdZdZeZddd„Zdd„Z dS(uConnectionPooluz Base class for all connection pools, such as :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`. cCs@|dkrt|ƒ‚n|jdƒ}||_||_dS(Nu[](uNoneuLocationParseErrorustripuhostuport(uselfuhostuport((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu__init__Ds   uConnectionPool.__init__cCs dt|ƒj|j|jfS(Nu%s(host=%r, port=%r)(utypeu__name__uhostuport(uself((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu__str__NsuConnectionPool.__str__N( u__name__u __module__u __qualname__u__doc__uNoneuschemeu LifoQueueuQueueClsu__init__u__str__(u __locals__((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyuConnectionPool;s  uConnectionPoolc BsË|EeZdZdZdZeZdde j ddddddd„Z dd„Z ddd „Z d d „Zd d „Zedd„Zdd„Zdd„Zdddddedddd„ZdS(uHTTPConnectionPoolu5 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`" uhttpic Ksñtj|||ƒtj||ƒ||_t|tƒsMtj|ƒ}n||_|j|ƒ|_ ||_ ||_ | pƒi|_ x$t |ƒD]} |j jdƒq–Wd|_d|_tjdkrä| jddƒn| |_dS(Niiiusource_address(ii(uConnectionPoolu__init__uRequestMethodsustrictu isinstanceuTimeoutu from_floatutimeoutuQueueClsupoolublockuproxyu proxy_headersuxrangeuputuNoneunum_connectionsu num_requestsusysu version_infoupopuconn_kw( uselfuhostuportustrictutimeoutumaxsizeublockuheadersu_proxyu_proxy_headersuconn_kwu_((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu__init__s"      uHTTPConnectionPool.__init__c Cs„|jd7_tjd|j|jfƒ|jd|jd|jd|jjd|j|j }|j dk r€d|_ n|S( u9 Return a fresh :class:`HTTPConnection`. iu%Starting new HTTP connection (%d): %suhostuportutimeoutustrictiN( unum_connectionsuloguinfouhostu ConnectionClsuportutimeoutuconnect_timeoutustrictuconn_kwuproxyuNoneu tcp_nodelay(uselfuconn((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu _new_conn®s   uHTTPConnectionPool._new_connc Cs»d}y"|jjd|jd|ƒ}WnMtk rKt|dƒ‚Yn-tk rw|jrst|dƒ‚nYnX|r«t|ƒr«t j d|j ƒ|j ƒn|pº|j ƒS(u™ 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``. ublockutimeoutuPool is closed.u>Pool reached maximum size and no more connections are allowed.u Resetting dropped connection: %sN(uNoneupoolugetublockuAttributeErroruClosedPoolErroruEmptyuEmptyPoolErroruis_connection_droppeduloguinfouhostucloseu _new_conn(uselfutimeoutuconn((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu _get_conn¿s "     uHTTPConnectionPool._get_connc Csoy|jj|ddƒdSWn7tk r2Yn&tk rWtjd|jƒYnX|rk|jƒndS(uä 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. ublockNu2Connection pool is full, discarding connection: %sF( upooluputuFalseuAttributeErroruFulluloguwarninguhostuclose(uselfuconn((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu _put_connàs  uHTTPConnectionPool._put_conncCsC|tkr|jjƒSt|tƒr2|jƒStj|ƒSdS(u< Helper that always returns a :class:`urllib3.util.Timeout` N(u_Defaultutimeoutucloneu isinstanceuTimeoutu from_float(uselfutimeout((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu _get_timeoutþs    uHTTPConnectionPool._get_timeoutc KsH|jd7_|j|ƒ}y-|jƒ|j|_|j|||Wn1tk r~t|d|j|jfƒ‚YnX|j }t |dƒr÷|dkr¼t ||d|ƒ‚n|t j krä|jjtjƒƒq÷|jj|ƒny;y|jddƒ}Wntk r0|jƒ}YnXWn×tk r\t ||d|ƒ‚Yn°tk r¼} zAdt| ƒks’dt| ƒkr§t ||d ƒ‚n‚WYd d } ~ XnPtk r } z0| jtkröt ||d|ƒ‚n‚WYd d } ~ XnXt|d d ƒ} tjd ||| |j|jfƒ|S(u 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. iu0Connection to %s timed out. (connect timeout=%s)usockiu!Read timed out. (read timeout=%s)u bufferingu timed outudid not complete (read)uRead timed out.Nu _http_vsn_struHTTP/?u"%s %s %s" %s %sT(u num_requestsu _get_timeoutu start_connectuconnect_timeoututimeouturequestu SocketTimeoutuConnectTimeoutErroruhostu read_timeoutuhasattruReadTimeoutErroruTimeoutuDEFAULT_TIMEOUTusocku settimeoutusocketugetdefaulttimeoutu getresponseuTrueu TypeErroru BaseSSLErrorustru SocketErroruerrnou_blocking_errnosugetattrulogudebugustatusulength( uselfuconnumethoduurlutimeoutuhttplib_request_kwu timeout_obju read_timeoutuhttplib_responseueu http_version((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu _make_request sV       u HTTPConnectionPool._make_requestc Cs[|jd}|_y/x(|jddƒ}|r|jƒqqWntk rVYnXdS(uD Close all pooled connections and disable the pool. ublockNF(upooluNoneugetuFalseucloseuEmpty(uselfuold_pooluconn((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyucloseas uHTTPConnectionPool.closecCs—|jdƒrdSt|ƒ\}}}|jrJ| rJtj|ƒ}n(|j rr|tj|ƒkrrd}n|||f|j|j|jfkS(uj Check if the given ``url`` is a member of the same host as this connection pool. u/TN( u startswithuTrueuget_hostuportuport_by_schemeugetuNoneuschemeuhost(uselfuurluschemeuhostuport((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu is_same_hostqs uHTTPConnectionPool.is_same_hostic 'Ks]|d kr|j}n|dkrB|dk rBt||ƒ‚n| d krc| jddƒ} n|r’|j|ƒ r’t|||dƒ‚nd } |jdkrÆ|j ƒ}|j |j ƒnd } zyh|j d| ƒ} |j | ||d|d|d|ƒ}| o| }tj|d|d || }Wn!tk rZt|d ƒ‚Ynttfk r–}zd} t|ƒ‚WYd d }~XnÅtttfk rZ}zœ| rÊ| jƒd } n|sBt|tƒrå‚nt|tƒr|jrtd |ƒ‚n|dkr-td |ƒ‚nt|||ƒ‚n|} WYd d }~XnXWd | ru|j| ƒnX| sÎtjd|| |fƒ|j |||||d||d|d| d| | S|oÝ|j!ƒ}|rY|dk rY|j"dkr d}ntj#d||fƒ|j |||||d||d|d| d| | S|S(uÈ 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. If `False`, then retries are disabled and any exception is raised immediately. :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` iupreload_contentiuhttputimeoutubodyuheadersupoolu connectionu"No pool connections are available.NuCannot connect to proxy.uConnection failed.uARetrying (%d attempts remain) after connection broken by '%r': %su pool_timeoutu release_conni/uGETuRedirecting %s -> %sFT($uNoneuheadersuFalseu MaxRetryErrorugetuTrueu is_same_hostuHostChangedErroruschemeucopyuupdateu proxy_headersu _get_connu _make_requestu HTTPResponseu from_httplibuEmptyuEmptyPoolErroru BaseSSLErroruCertificateErroruSSLErroru TimeoutErroru HTTPExceptionu SocketErrorucloseu isinstanceuproxyu ProxyErroruConnectionErroru _put_connuloguwarninguurlopenuget_redirect_locationustatusuinfo(uselfumethoduurlubodyuheadersuretriesuredirectuassert_same_hostutimeoutu pool_timeoutu release_connu response_kwuconnuerruhttplib_responseu response_connuresponseueuredirect_location((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyuurlopen„sxH                  uHTTPConnectionPool.urlopenNFT(u__name__u __module__u __qualname__u__doc__uschemeuHTTPConnectionu ConnectionClsuNoneuFalseuTimeoutuDEFAULT_TIMEOUTu__init__u _new_connu _get_connu _put_connu _get_timeoutu_Defaultu _make_requestucloseu is_same_hostuTrueuurlopen(u __locals__((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyuHTTPConnectionPoolUs 3  !  W    uHTTPConnectionPoolcBsw|EeZdZdZdZeZd d d dd d d d d d d d d d d dd„Z dd„Z dd „Z d S( uHTTPSConnectionPoolu» 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. uhttpsic Ks™tjdkr"|jddƒntj|||||||||| | | |_| |_| |_| |_ ||_ ||_ ||_ ||_ dS(Niiusource_address(ii(usysu version_infoupopuNoneuHTTPConnectionPoolu__init__ukey_fileu cert_fileu cert_reqsuca_certsu ssl_versionuassert_hostnameuassert_fingerprintuconn_kw(uselfuhostuportustrictutimeoutumaxsizeublockuheadersu_proxyu_proxy_headersukey_fileu cert_fileu cert_reqsuca_certsu ssl_versionuassert_hostnameuassert_fingerprintuconn_kw((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu__init__Ws        uHTTPSConnectionPool.__init__c CsÎt|tƒrj|jd|jd|jd|jd|jd|jd|jƒ|j |_ |j |_ n|j dk rÊy |j }Wntk r£|j}YnX||j|j|jƒ|jƒn|S(uˆ Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket` and establish the tunnel if proxy is used. ukey_fileu cert_fileu cert_reqsuca_certsuassert_hostnameuassert_fingerprintN(u isinstanceuVerifiedHTTPSConnectionuset_certukey_fileu cert_fileu cert_reqsuca_certsuassert_hostnameuassert_fingerprintu ssl_versionuconn_kwuproxyuNoneu set_tunneluAttributeErroru _set_tunneluhostuportu proxy_headersuconnect(uselfuconnu set_tunnel((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyu _prepare_connns"         u!HTTPSConnectionPool._prepare_connc Cs|jd7_tjd|j|jfƒ|j sE|jtkrTtdƒ‚n|j}|j}|jd k r|jj}|jj}ni}t j s¯|j |d>> conn = connection_from_url('http://google.com/') >>> r = conn.request('GET', '/') uhttpsuportN(uget_hostuHTTPSConnectionPooluHTTPConnectionPool(uurlukwuschemeuhostuport((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyuconnection_from_url®s uconnection_from_url(>usysuerrnouloggingusocketuerroru SocketErrorutimeoutu SocketTimeoutuqueueu LifoQueueuEmptyuFullu ImportErroruQueueu_u exceptionsuClosedPoolErroruConnectionErroruConnectTimeoutErroruEmptyPoolErroruHostChangedErroruLocationParseErroru MaxRetryErroruSSLErroru TimeoutErroruReadTimeoutErroru ProxyErrorupackages.ssl_match_hostnameuCertificateErrorupackagesusixu connectionuport_by_schemeuDummyConnectionuHTTPConnectionuHTTPSConnectionuVerifiedHTTPSConnectionu HTTPExceptionu BaseSSLErrorurequestuRequestMethodsuresponseu HTTPResponseuutiluget_hostuis_connection_droppeduTimeoutumovesuxrangeu getLoggeru__name__uloguobjectu_DefaultuConnectionPoolusetuEAGAINu EWOULDBLOCKu_blocking_errnosuHTTPConnectionPooluHTTPSConnectionPooluconnection_from_url(((uM/tmp/pip-zej_zi-build/pip/_vendor/requests/packages/urllib3/connectionpool.pyus2      L 4  ÿîl