-import math
import socket
import ssl
from typing import Dict, Iterator, List, Optional, Tuple, Union
import httpcore
-from .._config import DEFAULT_POOL_LIMITS, PoolLimits, Proxy, SSLConfig
+from .._config import Proxy, SSLConfig
from .._content_streams import ByteStream, IteratorStream
from .._types import CertTypes, VerifyTypes
from .._utils import as_network_error, warn_deprecated
verify: VerifyTypes = True,
cert: CertTypes = None,
trust_env: bool = None,
- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,
+ pool_connections: int = 10,
+ pool_maxsize: int = 10,
+ pool_block: bool = False,
):
assert (
urllib3 is not None
ssl_config = SSLConfig(
verify=verify, cert=cert, trust_env=trust_env, http2=False
)
- max_connections = pool_limits.max_connections
- max_keepalive = pool_limits.max_keepalive
-
- # Our connection pool configuration doesn't quite match up with urllib3's
- # controls, but we can put sensible mappings in place:
- if max_connections is None:
- block = False
- if max_keepalive is None:
- num_pools = 1000
- maxsize = 1000
- else:
- num_pools = int(math.sqrt(max_keepalive))
- maxsize = int(math.sqrt(max_keepalive))
- else:
- block = True
- num_pools = int(math.sqrt(max_connections))
- maxsize = int(math.sqrt(max_connections))
self.pool = self.init_pool_manager(
proxy=proxy,
ssl_context=ssl_config.ssl_context,
- num_pools=num_pools,
- maxsize=maxsize,
- block=block,
+ pool_connections=pool_connections,
+ pool_maxsize=pool_maxsize,
+ pool_block=pool_block,
)
def init_pool_manager(
self,
proxy: Optional[Proxy],
ssl_context: ssl.SSLContext,
- num_pools: int,
- maxsize: int,
- block: bool,
+ pool_connections: int,
+ pool_maxsize: int,
+ pool_block: bool,
) -> Union[urllib3.PoolManager, urllib3.ProxyManager]:
if proxy is None:
return urllib3.PoolManager(
ssl_context=ssl_context,
- num_pools=num_pools,
- maxsize=maxsize,
- block=block,
+ num_pools=pool_connections,
+ maxsize=pool_maxsize,
+ block=pool_block,
)
else:
return urllib3.ProxyManager(
proxy_url=str(proxy.url),
proxy_headers=dict(proxy.headers),
ssl_context=ssl_context,
- num_pools=num_pools,
- maxsize=maxsize,
- block=block,
+ num_pools=pool_connections,
+ maxsize=pool_maxsize,
+ block=pool_block,
)
def request(
verify: VerifyTypes = True,
cert: CertTypes = None,
trust_env: bool = None,
- pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,
+ pool_connections: int = 10,
+ pool_maxsize: int = 10,
+ pool_block: bool = False,
):
warn_deprecated("URLLib3Dispatch is deprecated, please use URLLib3Transport")
super().__init__(
verify=verify,
cert=cert,
trust_env=trust_env,
- pool_limits=pool_limits,
+ pool_connections=pool_connections,
+ pool_maxsize=pool_maxsize,
+ pool_block=pool_block,
)