� ��^c@@s�ddlmZddlZddlZddlZddlmZddlmZm Z ddlm Z ddl m Z m Z mZddlmZdd lmZdd lmZdd lmZdd lmZd ddgZeje�Zd8Zd9Zejd1e�Z d2�Z!iej"e!e �d36ej"e!e �d46Z#ied36e d46Z$d efd5��YZ%de%fd6��YZ&d7�Z'dS(:i(tabsolute_importNi(tRecentlyUsedContainer(tHTTPConnectionPooltHTTPSConnectionPool(tport_by_scheme(tLocationValueErrort MaxRetryErrortProxySchemeUnknown(tsix(turljoin(tRequestMethods(t parse_url(tRetryt PoolManagert ProxyManagertproxy_from_urltkey_filet cert_filet cert_reqstca_certst ssl_versiont ca_cert_dirt ssl_contextt key_passwordt key_schemetkey_hosttkey_portt key_timeoutt key_retriest key_strictt key_blocktkey_source_addresst key_key_filetkey_key_passwordt key_cert_filet key_cert_reqst key_ca_certstkey_ssl_versiontkey_ca_cert_dirtkey_ssl_contextt key_maxsizet key_headerst key__proxytkey__proxy_headerstkey_socket_optionstkey__socks_optionstkey_assert_hostnametkey_assert_fingerprinttkey_server_hostnametPoolKeycC@s|j�}|dj�|d<|dj�|d>> manager = PoolManager(num_pools=2) >>> r = manager.request('GET', 'http://google.com/') >>> r = manager.request('GET', 'http://google.com/mail') >>> r = manager.request('GET', 'http://yahoo.com/') >>> len(manager.pools) 2 i cK@sMtj||�||_t|dd��|_t|_tj�|_dS(Nt dispose_funccS@s |j�S(N(tclose(tp((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyt�t(R t__init__tconnection_pool_kwRtpoolstpool_classes_by_schemetkey_fn_by_schemeR9(tselft num_poolsR4RS((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRR�s   cC@s|S(N((RW((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyt __enter__�scC@s|j�tS(N(tcleartFalse(RWtexc_typetexc_valtexc_tb((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyt__exit__�s cC@s�|j|}|dkr+|jj�}nxdD]}|j|d�q2W|dkr|x!tD]}|j|d�q_Wn||||�S(s� Create a new :class:`ConnectionPool` based on host, port, scheme, and any additional pool keyword arguments. If ``request_context`` is provided, it is provided as keyword arguments to the pool class used. This method is used to actually create the connection pools handed out by :meth:`connection_from_url` and companion methods. It is intended to be overridden for customization. R2R3tportRKN(R2R3R`(RUR;RSR9RBt SSL_KEYWORDS(RWR2R3R`REtpool_clsRGtkw((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyt _new_pool�s     cC@s|jj�dS(s� Empty our store of pools and direct them all to close. This will not affect in-flight connections, but they will not be re-used after completion. N(RTRZ(RW((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRZ�sRKcC@sz|std��n|j|�}|p-d|d<|sYtj|dj�d�}n||d<||d<|j|�S(s� Get a :class:`ConnectionPool` based on the host, port, and scheme. If ``port`` isn't given, it will be derived from the ``scheme`` using ``urllib3.connectionpool.port_by_scheme``. If ``pool_kwargs`` is provided, it is merged with the instance's ``connection_pool_kw`` variable and used to create the new connection pool, if one is needed. sNo host specified.RKR2iPR`R3(Rt_merge_pool_kwargsRR>R:tconnection_from_context(RWR3R`R2t pool_kwargsRE((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pytconnection_from_host�s   cC@s<|dj�}|j|}||�}|j|d|�S(s� Get a :class:`ConnectionPool` based on the request context. ``request_context`` must at least contain the ``scheme`` key and its value must be a key in ``key_fn_by_scheme`` instance variable. R2RE(R:RVtconnection_from_pool_key(RWRER2tpool_key_constructortpool_key((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRf�s  c C@sy|jj�g|jj|�}|r)|S|d}|d}|d}|j|||d|�}||j|Rd(RWRkREtpoolR2R3R`((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRi�s    cC@s4t|�}|j|jd|jd|jd|�S(s� Similar to :func:`urllib3.connectionpool.connection_from_url`. If ``pool_kwargs`` is not provided and a new pool needs to be constructed, ``self.connection_pool_kw`` is used to initialize the :class:`urllib3.connectionpool.ConnectionPool`. If ``pool_kwargs`` is provided, it is used instead. Note that if a new pool does not need to be created for the request, the provided ``pool_kwargs`` are not used. R`R2Rg(R RhR3R`R2(RWturlRgtu((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pytconnection_from_urls cC@sq|jj�}|rmxU|j�D]D\}}|dkr\y ||=Wqftk rXqfXq"||| %sN(R RhR3R`R2R[R4R9tproxyR;turlopent request_uritget_redirect_locationR tstatusR>t isinstanceR tfrom_inttremove_headers_on_redirectt is_same_hostR@RtiterkeysR:RBt incrementRtraise_on_redirecttlogtinfo( RWtmethodRnRvRcRotconnRytredirect_locationRxR4theader((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyR|5sD $      "    N(t__name__t __module__t__doc__R;R{RRRYR_RdRZRhRfRiRpRetTrueR|(((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyR �s       cB@sJeZdZdddd�Zdddd�Zdd�Zed�ZRS(sx Behaves just like :class:`PoolManager`, but sends all requests through the defined proxy, using the CONNECT method for HTTPS URLs. :param proxy_url: The URL of the proxy to be used. :param proxy_headers: A dictionary containing headers that will be sent to the proxy. In case of HTTP they are being sent with each request, while in the HTTPS/CONNECT case they are sent only once. Could be used for proxy authentication. Example: >>> proxy = urllib3.ProxyManager('http://localhost:3128/') >>> r1 = proxy.request('GET', 'http://google.com/') >>> r2 = proxy.request('GET', 'http://httpbin.org/') >>> len(proxy.pools) 1 >>> r3 = proxy.request('GET', 'https://httpbin.org/') >>> r4 = proxy.request('GET', 'https://twitter.com/') >>> len(proxy.pools) 3 i cK@s�t|t�r.d|j|j|jf}nt|�}|jsmtj|jd�}|jd|�}n|jdkr�t |j��n||_ |p�i|_ |j |d<|j |dt_replaceRR{t proxy_headerstsuperRRR(RWt proxy_urlRXR4R�RSR{R`((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRR�s      RKcC@sb|dkr.tt|�j|||d|�Stt|�j|jj|jj|jjd|�S(NRLRg(R�RRhR{R3R`R2(RWR3R`R2Rg((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRh�s  cC@sIidd6}t|�j}|r/||dR4R�R�RR|(RWR�RnRvRcRoR4((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyR|�s  N( R�R�R�R;RRRhR�R�R|(((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyRts  cK@std||�S(NR�(R(RnRc((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pyR�s(RRRRRRRR(RRRRRRRRR R!R"R#R$R%R&R'R(R)R*R+R,R-R.R/R0((t __future__Rt collectionst functoolstloggingt _collectionsRtconnectionpoolRRRt exceptionsRRRtpackagesRtpackages.six.moves.urllib.parseR trequestR tutil.urlR t util.retryR t__all__t getLoggerR�R�Rat _key_fieldst namedtupleR1RJtpartialRVRUR RR(((s4/tmp/pip-build-1THPZW/urllib3/urllib3/poolmanager.pytsp    5�a