MCPcopy
hub / github.com/urllib3/urllib3 / connection_from_pool_key

Method connection_from_pool_key

src/urllib3/poolmanager.py:344–368  ·  view source on GitHub ↗

Get a :class:`urllib3.connectionpool.ConnectionPool` based on the provided pool key. ``pool_key`` should be a namedtuple that only contains immutable objects. At a minimum it must have the ``scheme``, ``host``, and ``port`` fields.

(
        self, pool_key: PoolKey, request_context: dict[str, typing.Any]
    )

Source from the content-addressed store, hash-verified

342 return self.connection_from_pool_key(pool_key, request_context=request_context)
343
344 def connection_from_pool_key(
345 self, pool_key: PoolKey, request_context: dict[str, typing.Any]
346 ) -> HTTPConnectionPool:
347 """
348 Get a :class:`urllib3.connectionpool.ConnectionPool` based on the provided pool key.
349
350 ``pool_key`` should be a namedtuple that only contains immutable
351 objects. At a minimum it must have the ``scheme``, ``host``, and
352 ``port`` fields.
353 """
354 with self.pools.lock:
355 # If the scheme, host, or port doesn't match existing open
356 # connections, open a new ConnectionPool.
357 pool = self.pools.get(pool_key)
358 if pool:
359 return pool
360
361 # Make a fresh ConnectionPool of the desired type
362 scheme = request_context["scheme"]
363 host = request_context["host"]
364 port = request_context["port"]
365 pool = self._new_pool(scheme, host, port, request_context=request_context)
366 self.pools[pool_key] = pool
367
368 return pool
369
370 def connection_from_url(
371 self, url: str, pool_kwargs: dict[str, typing.Any] | None = None

Callers 1

Calls 2

_new_poolMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected