"""
requests.adapters
~~~~~~~~~~~~~~~~~

This module contains the transport adapters that Requests uses to define
and maintain connections.
"""

"""Sends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        """

"""The built-in HTTP Adapter for urllib3.

    Provides a general-case interface for Requests sessions to contact HTTP and
    HTTPS urls by implementing the Transport Adapter interface. This class will
    usually be created by the :class:`Session <Session>` class under the
    covers.

    :param pool_connections: The number of urllib3 connection pools to cache.
    :param pool_maxsize: The maximum number of connections to save in the pool.
    :param max_retries: The maximum number of retries each connection
        should attempt. Note, this applies only to failed DNS lookups, socket
        connections and connection timeouts, never to requests where data has
        made it to the server. By default, Requests does not retry failed
        connections. If you need granular control over the conditions under
        which we retry a request, import urllib3's ``Retry`` class and pass
        that instead.
    :param pool_block: Whether the connection pool should block for connections.

    Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> a = requests.adapters.HTTPAdapter(max_retries=3)
      >>> s.mount('http://', a)
    """

        # Can't handle by adding 'proxy_manager' to self.__attrs__ because
        # self.poolmanager uses a lambda function, which isn't pickleable.
        
"""Initializes a urllib3 PoolManager.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param connections: The number of urllib3 connection pools to cache.
        :param maxsize: The maximum number of connections to save in the pool.
        :param block: Block when no free connections are available.
        :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
        """

"""Return urllib3 ProxyManager for the given proxy.

        :param proxy: The proxy to return a urllib3 ProxyManager for.
        :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
        :returns: ProxyManager
        :rtype: urllib3.ProxyManager
        """

"""Verify a SSL certificate. This method should not be called from user
        code, and is only exposed for use when subclassing the

        :param conn: The urllib3 connection object associated with the cert.
        :param url: The requested URL.
        :param verify: Either a boolean, in which case it controls whether we verify
        :param cert: The SSL certificate to verify.
        """

"""Builds a :class:`Response <requests.Response>` object from a urllib3
        response. This should not be called from user code, and is only exposed
        for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`

        :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
        :param resp: The urllib3 response object.
        :rtype: requests.Response
        """

        # Fallback to None if there's no status_code, for whatever reason.
        
"""Returns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the

        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        """

"""Disposes of any internal state.

        Currently, this closes the PoolManager and any active ProxyManager,
        which closes any pooled connections.
        """

"""Obtain the url to use when making the final request.

        If the message is being sent through a HTTP proxy, the full URL has to
        be used. Otherwise, we should only use the path portion of the URL.

        This should not be called from user code, and is only exposed for use
        when subclassing the

        :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
        :rtype: str
        """

"""Add any headers needed by the connection. As of v2.0 this does
        nothing by default, but is left for overriding by users that subclass
        the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
        :param kwargs: The keyword arguments from the call to send().
        """

"""Returns a dictionary of the headers to add to any request sent
        through a proxy. This works with urllib3 magic to ensure that they are
        correctly sent to the proxy, rather than in a tunnelled request if
        CONNECT is being used.

        :param proxy: The url of the proxy being used for this request.
        :rtype: dict
        """

        :type timeout: float or tuple or urllib3 Timeout object
        :param verify: (optional) Either a boolean, in which case it controls whether
            we verify the server's TLS certificate, or a string, in which case it
            must be a path to a CA bundle to use
        """

                # TODO: Remove this in 3.0.0: see #2811
                
                # This branch is for urllib3 v1.22 and later.
                
                # This branch is for urllib3 versions earlier than v1.22
                
from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError

        raise InvalidSchema("Missing dependencies for SOCKS support.")

        self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None

        """Sends PreparedRequest object. Returns Response object.

        self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)

        return {attr: getattr(self, attr, None) for attr in self.__attrs__}

            self._pool_connections, self._pool_maxsize, block=self._pool_block

        self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs

            manager = self.proxy_manager[proxy] = SOCKSProxyManager(

            manager = self.proxy_manager[proxy] = proxy_from_url(

        """Verify a SSL certificate. This method should not be called from user

                cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)

                    f"Could not find a suitable TLS CA certificate bundle, "

            if conn.cert_file and not os.path.exists(conn.cert_file):

                    f"Could not find the TLS certificate file, "

            if conn.key_file and not os.path.exists(conn.key_file):

                    f"Could not find the TLS key file, invalid path: {conn.key_file}"

        """Builds a :class:`Response <requests.Response>` object from a urllib3

        response.headers = CaseInsensitiveDict(getattr(resp, "headers", {}))

        response.encoding = get_encoding_from_headers(response.headers)

        """Returns a urllib3 connection for the given URL. This should not be

        """Obtain the url to use when making the final request.

            using_socks_proxy = proxy_scheme.startswith("socks")

        """Add any headers needed by the connection. As of v2.0 this does

        """Returns a dictionary of the headers to add to any request sent

            headers["Proxy-Authorization"] = _basic_auth_str(username, password)

        chunked = not (request.body is None or "Content-Length" in request.headers)

                timeout = TimeoutSauce(connect=connect, read=read)

                    f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "

                    f"or a single float to set both timeouts to the same value."

            timeout = TimeoutSauce(connect=timeout, read=timeout)

                if not isinstance(e.reason, NewConnectionError):