ce0369
From 99274b9e7524be7e8f041e327be1dd7ba3fdc8a4 Mon Sep 17 00:00:00 2001
ce0369
From: Jeremy Cline <jcline@redhat.com>
ce0369
Date: Thu, 21 Apr 2016 10:56:28 -0700
ce0369
Subject: [PATCH] Key connection pools off custom keys
ce0369
ce0369
---
ce0369
 CONTRIBUTORS.txt         |   3 +
ce0369
 docs/managers.rst        |  44 +++++++++
ce0369
 test/test_poolmanager.py | 230 ++++++++++++++++++++++++++++++++++++++++++++++-
ce0369
 urllib3/poolmanager.py   | 104 +++++++++++++++++++--
ce0369
 4 files changed, 371 insertions(+), 10 deletions(-)
ce0369
ce0369
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
ce0369
index 5141a50..f32faaa 100644
ce0369
--- a/CONTRIBUTORS.txt
ce0369
+++ b/CONTRIBUTORS.txt
ce0369
@@ -142,5 +142,8 @@ In chronological order:
ce0369
 * Alex Gaynor <alex.gaynor@gmail.com>
ce0369
   * Updates to the default SSL configuration
ce0369
 
ce0369
+* Jeremy Cline <jeremy@jcline.org>
ce0369
+  * Added connection pool keys by scheme
ce0369
+
ce0369
 * [Your name or handle] <[email or website]>
ce0369
   * [Brief summary of your changes]
ce0369
diff --git a/docs/managers.rst b/docs/managers.rst
ce0369
index 6c841b7..ef91ca4 100644
ce0369
--- a/docs/managers.rst
ce0369
+++ b/docs/managers.rst
ce0369
@@ -28,6 +28,44 @@ so you don't have to.
ce0369
     >>> conn.num_requests
ce0369
     3
ce0369
 
ce0369
+A :class:`.PoolManager` will create a new :doc:`ConnectionPool <pools>`
ce0369
+when no :doc:`ConnectionPools <pools>` exist with a matching pool key.
ce0369
+The pool key is derived using the requested URL and the current values
ce0369
+of the ``connection_pool_kw`` instance variable on :class:`.PoolManager`.
ce0369
+
ce0369
+The keys in ``connection_pool_kw`` used when deriving the key are
ce0369
+configurable. For example, by default the ``my_field`` key is not
ce0369
+considered.
ce0369
+
ce0369
+.. doctest ::
ce0369
+
ce0369
+    >>> from urllib3.poolmanager import PoolManager
ce0369
+    >>> manager = PoolManager(10, my_field='wheat')
ce0369
+    >>> manager.connection_from_url('http://example.com')
ce0369
+    >>> manager.connection_pool_kw['my_field'] = 'barley'
ce0369
+    >>> manager.connection_from_url('http://example.com')
ce0369
+    >>> len(manager.pools)
ce0369
+    1
ce0369
+
ce0369
+To make the pool manager create new pools when the value of
ce0369
+``my_field`` changes, you can define a custom pool key and alter
ce0369
+the ``key_fn_by_scheme`` instance variable on :class:`.PoolManager`.
ce0369
+
ce0369
+.. doctest ::
ce0369
+
ce0369
+    >>> import functools
ce0369
+    >>> from collections import namedtuple
ce0369
+    >>> from urllib3.poolmanager import PoolManager, HTTPPoolKey
ce0369
+    >>> from urllib3.poolmanager import default_key_normalizer as normalizer
ce0369
+    >>> CustomKey = namedtuple('CustomKey', HTTPPoolKey._fields + ('my_field',))
ce0369
+    >>> manager = PoolManager(10, my_field='wheat')
ce0369
+    >>> manager.key_fn_by_scheme['http'] = functools.partial(normalizer, CustomKey)
ce0369
+    >>> manager.connection_from_url('http://example.com')
ce0369
+    >>> manager.connection_pool_kw['my_field'] = 'barley'
ce0369
+    >>> manager.connection_from_url('http://example.com')
ce0369
+    >>> len(manager.pools)
ce0369
+    2
ce0369
+
ce0369
 The API of a :class:`.PoolManager` object is similar to that of a
ce0369
 :doc:`ConnectionPool <pools>`, so they can be passed around interchangeably.
ce0369
 
ce0369
@@ -59,6 +97,12 @@ API
ce0369
 
ce0369
     .. autoclass:: PoolManager
ce0369
        :inherited-members:
ce0369
+    .. autoclass:: BasePoolKey
ce0369
+       :inherited-members:
ce0369
+    .. autoclass:: HTTPPoolKey
ce0369
+       :inherited-members:
ce0369
+    .. autoclass:: HTTPSPoolKey
ce0369
+       :inherited-members:
ce0369
 
ce0369
 ProxyManager
ce0369
 ============
ce0369
diff --git a/test/test_poolmanager.py b/test/test_poolmanager.py
ce0369
index 6195d51..fb134fb 100644
ce0369
--- a/test/test_poolmanager.py
ce0369
+++ b/test/test_poolmanager.py
ce0369
@@ -1,11 +1,21 @@
ce0369
+import functools
ce0369
 import unittest
ce0369
+from collections import namedtuple
ce0369
 
ce0369
-from urllib3.poolmanager import PoolManager
ce0369
+from urllib3.poolmanager import (
ce0369
+    _default_key_normalizer,
ce0369
+    HTTPPoolKey,
ce0369
+    HTTPSPoolKey,
ce0369
+    key_fn_by_scheme,
ce0369
+    PoolManager,
ce0369
+    SSL_KEYWORDS,
ce0369
+)
ce0369
 from urllib3 import connection_from_url
ce0369
 from urllib3.exceptions import (
ce0369
     ClosedPoolError,
ce0369
     LocationValueError,
ce0369
 )
ce0369
+from urllib3.util import retry, timeout
ce0369
 
ce0369
 
ce0369
 class TestPoolManager(unittest.TestCase):
ce0369
@@ -87,6 +97,224 @@ class TestPoolManager(unittest.TestCase):
ce0369
 
ce0369
         self.assertEqual(len(p.pools), 0)
ce0369
 
ce0369
+    def test_http_pool_key_fields(self):
ce0369
+        """Assert the HTTPPoolKey fields are honored when selecting a pool."""
ce0369
+        connection_pool_kw = {
ce0369
+            'timeout': timeout.Timeout(3.14),
ce0369
+            'retries': retry.Retry(total=6, connect=2),
ce0369
+            'block': True,
ce0369
+            'strict': True,
ce0369
+            'source_address': '127.0.0.1',
ce0369
+        }
ce0369
+        p = PoolManager()
ce0369
+        conn_pools = [
ce0369
+            p.connection_from_url('http://example.com/'),
ce0369
+            p.connection_from_url('http://example.com:8000/'),
ce0369
+            p.connection_from_url('http://other.example.com/'),
ce0369
+        ]
ce0369
+
ce0369
+        for key, value in connection_pool_kw.items():
ce0369
+            p.connection_pool_kw[key] = value
ce0369
+            conn_pools.append(p.connection_from_url('http://example.com/'))
ce0369
+
ce0369
+        self.assertTrue(
ce0369
+            all(
ce0369
+                x is not y
ce0369
+                for i, x in enumerate(conn_pools)
ce0369
+                for j, y in enumerate(conn_pools)
ce0369
+                if i != j
ce0369
+            )
ce0369
+        )
ce0369
+        self.assertTrue(
ce0369
+            all(
ce0369
+                isinstance(key, HTTPPoolKey)
ce0369
+                for key in p.pools.keys())
ce0369
+        )
ce0369
+
ce0369
+    def test_http_pool_key_extra_kwargs(self):
ce0369
+        """Assert non-HTTPPoolKey fields are ignored when selecting a pool."""
ce0369
+        p = PoolManager()
ce0369
+        conn_pool = p.connection_from_url('http://example.com/')
ce0369
+        p.connection_pool_kw['some_kwarg'] = 'that should be ignored'
ce0369
+        other_conn_pool = p.connection_from_url('http://example.com/')
ce0369
+
ce0369
+        self.assertTrue(conn_pool is other_conn_pool)
ce0369
+
ce0369
+    def test_http_pool_key_https_kwargs(self):
ce0369
+        """Assert HTTPSPoolKey fields are ignored when selecting a HTTP pool."""
ce0369
+        p = PoolManager()
ce0369
+        conn_pool = p.connection_from_url('http://example.com/')
ce0369
+        for key in SSL_KEYWORDS:
ce0369
+            p.connection_pool_kw[key] = 'this should be ignored'
ce0369
+        other_conn_pool = p.connection_from_url('http://example.com/')
ce0369
+
ce0369
+        self.assertTrue(conn_pool is other_conn_pool)
ce0369
+
ce0369
+    def test_https_pool_key_fields(self):
ce0369
+        """Assert the HTTPSPoolKey fields are honored when selecting a pool."""
ce0369
+        connection_pool_kw = {
ce0369
+            'timeout': timeout.Timeout(3.14),
ce0369
+            'retries': retry.Retry(total=6, connect=2),
ce0369
+            'block': True,
ce0369
+            'strict': True,
ce0369
+            'source_address': '127.0.0.1',
ce0369
+            'key_file': '/root/totally_legit.key',
ce0369
+            'cert_file': '/root/totally_legit.crt',
ce0369
+            'cert_reqs': 'CERT_REQUIRED',
ce0369
+            'ca_certs': '/root/path_to_pem',
ce0369
+            'ssl_version': 'SSLv23_METHOD',
ce0369
+        }
ce0369
+        p = PoolManager()
ce0369
+        conn_pools = [
ce0369
+            p.connection_from_url('https://example.com/'),
ce0369
+            p.connection_from_url('https://example.com:4333/'),
ce0369
+            p.connection_from_url('https://other.example.com/'),
ce0369
+        ]
ce0369
+        # Asking for a connection pool with the same key should give us an
ce0369
+        # existing pool.
ce0369
+        dup_pools = []
ce0369
+
ce0369
+        for key, value in connection_pool_kw.items():
ce0369
+            p.connection_pool_kw[key] = value
ce0369
+            conn_pools.append(p.connection_from_url('https://example.com/'))
ce0369
+            dup_pools.append(p.connection_from_url('https://example.com/'))
ce0369
+
ce0369
+        self.assertTrue(
ce0369
+            all(
ce0369
+                x is not y
ce0369
+                for i, x in enumerate(conn_pools)
ce0369
+                for j, y in enumerate(conn_pools)
ce0369
+                if i != j
ce0369
+            )
ce0369
+        )
ce0369
+        self.assertTrue(all(pool in conn_pools for pool in dup_pools))
ce0369
+        self.assertTrue(
ce0369
+            all(
ce0369
+                isinstance(key, HTTPSPoolKey)
ce0369
+                for key in p.pools.keys())
ce0369
+        )
ce0369
+
ce0369
+    def test_https_pool_key_extra_kwargs(self):
ce0369
+        """Assert non-HTTPSPoolKey fields are ignored when selecting a pool."""
ce0369
+        p = PoolManager()
ce0369
+        conn_pool = p.connection_from_url('https://example.com/')
ce0369
+        p.connection_pool_kw['some_kwarg'] = 'that should be ignored'
ce0369
+        other_conn_pool = p.connection_from_url('https://example.com/')
ce0369
+
ce0369
+        self.assertTrue(conn_pool is other_conn_pool)
ce0369
+
ce0369
+    def test_default_pool_key_funcs_copy(self):
ce0369
+        """Assert each PoolManager gets a copy of ``pool_keys_by_scheme``."""
ce0369
+        p = PoolManager()
ce0369
+        self.assertEqual(p.key_fn_by_scheme, p.key_fn_by_scheme)
ce0369
+        self.assertFalse(p.key_fn_by_scheme is key_fn_by_scheme)
ce0369
+
ce0369
+    def test_pools_keyed_with_from_host(self):
ce0369
+        """Assert pools are still keyed correctly with connection_from_host."""
ce0369
+        ssl_kw = {
ce0369
+            'key_file': '/root/totally_legit.key',
ce0369
+            'cert_file': '/root/totally_legit.crt',
ce0369
+            'cert_reqs': 'CERT_REQUIRED',
ce0369
+            'ca_certs': '/root/path_to_pem',
ce0369
+            'ssl_version': 'SSLv23_METHOD',
ce0369
+        }
ce0369
+        p = PoolManager(5, **ssl_kw)
ce0369
+        conns = []
ce0369
+        conns.append(
ce0369
+            p.connection_from_host('example.com', 443, scheme='https')
ce0369
+        )
ce0369
+
ce0369
+        for k in ssl_kw:
ce0369
+            p.connection_pool_kw[k] = 'newval'
ce0369
+            conns.append(
ce0369
+                p.connection_from_host('example.com', 443, scheme='https')
ce0369
+            )
ce0369
+
ce0369
+        self.assertTrue(
ce0369
+            all(
ce0369
+                x is not y
ce0369
+                for i, x in enumerate(conns)
ce0369
+                for j, y in enumerate(conns)
ce0369
+                if i != j
ce0369
+            )
ce0369
+        )
ce0369
+
ce0369
+    def test_https_connection_from_url_case_insensitive(self):
ce0369
+        """Assert scheme case is ignored when pooling HTTPS connections."""
ce0369
+        p = PoolManager()
ce0369
+        pool = p.connection_from_url('https://example.com/')
ce0369
+        other_pool = p.connection_from_url('HTTPS://EXAMPLE.COM/')
ce0369
+
ce0369
+        self.assertEqual(1, len(p.pools))
ce0369
+        self.assertTrue(pool is other_pool)
ce0369
+        self.assertTrue(all(isinstance(key, HTTPSPoolKey) for key in p.pools.keys()))
ce0369
+
ce0369
+    def test_https_connection_from_host_case_insensitive(self):
ce0369
+        """Assert scheme case is ignored when getting the https key class."""
ce0369
+        p = PoolManager()
ce0369
+        pool = p.connection_from_host('example.com', scheme='https')
ce0369
+        other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTPS')
ce0369
+
ce0369
+        self.assertEqual(1, len(p.pools))
ce0369
+        self.assertTrue(pool is other_pool)
ce0369
+        self.assertTrue(all(isinstance(key, HTTPSPoolKey) for key in p.pools.keys()))
ce0369
+
ce0369
+    def test_https_connection_from_context_case_insensitive(self):
ce0369
+        """Assert scheme case is ignored when getting the https key class."""
ce0369
+        p = PoolManager()
ce0369
+        context = {'scheme': 'https', 'host': 'example.com', 'port': '443'}
ce0369
+        other_context = {'scheme': 'HTTPS', 'host': 'EXAMPLE.COM', 'port': '443'}
ce0369
+        pool = p.connection_from_context(context)
ce0369
+        other_pool = p.connection_from_context(other_context)
ce0369
+
ce0369
+        self.assertEqual(1, len(p.pools))
ce0369
+        self.assertTrue(pool is other_pool)
ce0369
+        self.assertTrue(all(isinstance(key, HTTPSPoolKey) for key in p.pools.keys()))
ce0369
+
ce0369
+    def test_http_connection_from_url_case_insensitive(self):
ce0369
+        """Assert scheme case is ignored when pooling HTTP connections."""
ce0369
+        p = PoolManager()
ce0369
+        pool = p.connection_from_url('http://example.com/')
ce0369
+        other_pool = p.connection_from_url('HTTP://EXAMPLE.COM/')
ce0369
+
ce0369
+        self.assertEqual(1, len(p.pools))
ce0369
+        self.assertTrue(pool is other_pool)
ce0369
+        self.assertTrue(all(isinstance(key, HTTPPoolKey) for key in p.pools.keys()))
ce0369
+
ce0369
+    def test_http_connection_from_host_case_insensitive(self):
ce0369
+        """Assert scheme case is ignored when getting the https key class."""
ce0369
+        p = PoolManager()
ce0369
+        pool = p.connection_from_host('example.com', scheme='http')
ce0369
+        other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTP')
ce0369
+
ce0369
+        self.assertEqual(1, len(p.pools))
ce0369
+        self.assertTrue(pool is other_pool)
ce0369
+        self.assertTrue(all(isinstance(key, HTTPPoolKey) for key in p.pools.keys()))
ce0369
+
ce0369
+    def test_http_connection_from_context_case_insensitive(self):
ce0369
+        """Assert scheme case is ignored when getting the https key class."""
ce0369
+        p = PoolManager()
ce0369
+        context = {'scheme': 'http', 'host': 'example.com', 'port': '8080'}
ce0369
+        other_context = {'scheme': 'HTTP', 'host': 'EXAMPLE.COM', 'port': '8080'}
ce0369
+        pool = p.connection_from_context(context)
ce0369
+        other_pool = p.connection_from_context(other_context)
ce0369
+
ce0369
+        self.assertEqual(1, len(p.pools))
ce0369
+        self.assertTrue(pool is other_pool)
ce0369
+        self.assertTrue(all(isinstance(key, HTTPPoolKey) for key in p.pools.keys()))
ce0369
+
ce0369
+    def test_custom_pool_key(self):
ce0369
+        """Assert it is possible to define addition pool key fields."""
ce0369
+        custom_key = namedtuple('CustomKey', HTTPPoolKey._fields + ('my_field',))
ce0369
+        p = PoolManager(10, my_field='barley')
ce0369
+
ce0369
+        p.key_fn_by_scheme['http'] = functools.partial(_default_key_normalizer, custom_key)
ce0369
+        p.connection_from_url('http://example.com')
ce0369
+        p.connection_pool_kw['my_field'] = 'wheat'
ce0369
+        p.connection_from_url('http://example.com')
ce0369
+
ce0369
+        self.assertEqual(2, len(p.pools))
ce0369
+
ce0369
 
ce0369
 if __name__ == '__main__':
ce0369
     unittest.main()
ce0369
diff --git a/urllib3/poolmanager.py b/urllib3/poolmanager.py
ce0369
index b8d1e74..4fdae8d 100644
ce0369
--- a/urllib3/poolmanager.py
ce0369
+++ b/urllib3/poolmanager.py
ce0369
@@ -1,3 +1,5 @@
ce0369
+import collections
ce0369
+import functools
ce0369
 import logging
ce0369
 
ce0369
 try:  # Python 3
ce0369
@@ -17,16 +19,69 @@ from .util.retry import Retry
ce0369
 __all__ = ['PoolManager', 'ProxyManager', 'proxy_from_url']
ce0369
 
ce0369
 
ce0369
+log = logging.getLogger(__name__)
ce0369
+
ce0369
+SSL_KEYWORDS = ('key_file', 'cert_file', 'cert_reqs', 'ca_certs',
ce0369
+                'ssl_version', 'ca_cert_dir')
ce0369
+
ce0369
+# The base fields to use when determining what pool to get a connection from;
ce0369
+# these do not rely on the ``connection_pool_kw`` and can be determined by the
ce0369
+# URL and potentially the ``urllib3.connection.port_by_scheme`` dictionary.
ce0369
+#
ce0369
+# All custom key schemes should include the fields in this key at a minimum.
ce0369
+BasePoolKey = collections.namedtuple('BasePoolKey', ('scheme', 'host', 'port'))
ce0369
+
ce0369
+# The fields to use when determining what pool to get a HTTP and HTTPS
ce0369
+# connection from. All additional fields must be present in the PoolManager's
ce0369
+# ``connection_pool_kw`` instance variable.
ce0369
+HTTPPoolKey = collections.namedtuple(
ce0369
+    'HTTPPoolKey', BasePoolKey._fields + ('timeout', 'retries', 'strict',
ce0369
+                                          'block', 'source_address')
ce0369
+)
ce0369
+HTTPSPoolKey = collections.namedtuple(
ce0369
+    'HTTPSPoolKey', HTTPPoolKey._fields + SSL_KEYWORDS
ce0369
+)
ce0369
+
ce0369
+
ce0369
+def _default_key_normalizer(key_class, request_context):
ce0369
+    """
ce0369
+    Create a pool key of type ``key_class`` for a request.
ce0369
+
ce0369
+    According to RFC 3986, both the scheme and host are case-insensitive.
ce0369
+    Therefore, this function normalizes both before constructing the pool
ce0369
+    key for an HTTPS request. If you wish to change this behaviour, provide
ce0369
+    alternate callables to ``key_fn_by_scheme``.
ce0369
+
ce0369
+    :param key_class:
ce0369
+        The class to use when constructing the key. This should be a namedtuple
ce0369
+        with the ``scheme`` and ``host`` keys at a minimum.
ce0369
+
ce0369
+    :param request_context:
ce0369
+        A dictionary-like object that contain the context for a request.
ce0369
+        It should contain a key for each field in the :class:`HTTPPoolKey`
ce0369
+    """
ce0369
+    context = {}
ce0369
+    for key in key_class._fields:
ce0369
+        context[key] = request_context.get(key)
ce0369
+    context['scheme'] = context['scheme'].lower()
ce0369
+    context['host'] = context['host'].lower()
ce0369
+    return key_class(**context)
ce0369
+
ce0369
+
ce0369
+# A dictionary that maps a scheme to a callable that creates a pool key.
ce0369
+# This can be used to alter the way pool keys are constructed, if desired.
ce0369
+# Each PoolManager makes a copy of this dictionary so they can be configured
ce0369
+# globally here, or individually on the instance.
ce0369
+key_fn_by_scheme = {
ce0369
+    'http': functools.partial(_default_key_normalizer, HTTPPoolKey),
ce0369
+    'https': functools.partial(_default_key_normalizer, HTTPSPoolKey),
ce0369
+}
ce0369
+
ce0369
 pool_classes_by_scheme = {
ce0369
     'http': HTTPConnectionPool,
ce0369
     'https': HTTPSConnectionPool,
ce0369
 }
ce0369
 
ce0369
-log = logging.getLogger(__name__)
ce0369
-
ce0369
-SSL_KEYWORDS = ('key_file', 'cert_file', 'cert_reqs', 'ca_certs',
ce0369
-                'ssl_version')
ce0369
-
ce0369
 
ce0369
 class PoolManager(RequestMethods):
ce0369
     """
ce0369
@@ -64,6 +119,11 @@ class PoolManager(RequestMethods):
ce0369
         self.pools = RecentlyUsedContainer(num_pools,
ce0369
                                            dispose_func=lambda p: p.close())
ce0369
 
ce0369
+        # Locally set the pool classes and keys so other PoolManagers can
ce0369
+        # override them.
ce0369
+        self.pool_classes_by_scheme = pool_classes_by_scheme
ce0369
+        self.key_fn_by_scheme = key_fn_by_scheme.copy()
ce0369
+
ce0369
     def __enter__(self):
ce0369
         return self
ce0369
 
ce0369
@@ -109,10 +169,36 @@ class PoolManager(RequestMethods):
ce0369
         if not host:
ce0369
             raise LocationValueError("No host specified.")
ce0369
 
ce0369
-        scheme = scheme or 'http'
ce0369
-        port = port or port_by_scheme.get(scheme, 80)
ce0369
-        pool_key = (scheme, host, port)
ce0369
+        request_context = self.connection_pool_kw.copy()
ce0369
+        request_context['scheme'] = scheme or 'http'
ce0369
+        if not port:
ce0369
+            port = port_by_scheme.get(request_context['scheme'].lower(), 80)
ce0369
+        request_context['port'] = port
ce0369
+        request_context['host'] = host
ce0369
+
ce0369
+        return self.connection_from_context(request_context)
ce0369
+
ce0369
+    def connection_from_context(self, request_context):
ce0369
+        """
ce0369
+        Get a :class:`ConnectionPool` based on the request context.
ce0369
+
ce0369
+        ``request_context`` must at least contain the ``scheme`` key and its
ce0369
+        value must be a key in ``key_fn_by_scheme`` instance variable.
ce0369
+        """
ce0369
+        scheme = request_context['scheme'].lower()
ce0369
+        pool_key_constructor = self.key_fn_by_scheme[scheme]
ce0369
+        pool_key = pool_key_constructor(request_context)
ce0369
+
ce0369
+        return self.connection_from_pool_key(pool_key)
ce0369
 
ce0369
+    def connection_from_pool_key(self, pool_key):
ce0369
+        """
ce0369
+        Get a :class:`ConnectionPool` based on the provided pool key.
ce0369
+
ce0369
+        ``pool_key`` should be a namedtuple that only contains immutable
ce0369
+        objects. At a minimum it must have the ``scheme``, ``host``, and
ce0369
+        ``port`` fields.
ce0369
+        """
ce0369
         with self.pools.lock:
ce0369
             # If the scheme, host, or port doesn't match existing open
ce0369
             # connections, open a new ConnectionPool.
ce0369
@@ -121,7 +207,7 @@ class PoolManager(RequestMethods):
ce0369
                 return pool
ce0369
 
ce0369
             # Make a fresh ConnectionPool of the desired type
ce0369
-            pool = self._new_pool(scheme, host, port)
ce0369
+            pool = self._new_pool(pool_key.scheme, pool_key.host, pool_key.port)
ce0369
             self.pools[pool_key] = pool
ce0369
 
ce0369
         return pool
ce0369
-- 
ce0369
2.5.5
ce0369