Allows for arbitrary requests while transparently keeping track of necessary connection pools for you. :param num_pools: Number of connection pools to cache before discarding the least recently used pool. :param headers: Headers to include with all requests
| 160 | |
| 161 | |
| 162 | class PoolManager(RequestMethods): |
| 163 | """ |
| 164 | Allows for arbitrary requests while transparently keeping track of |
| 165 | necessary connection pools for you. |
| 166 | |
| 167 | :param num_pools: |
| 168 | Number of connection pools to cache before discarding the least |
| 169 | recently used pool. |
| 170 | |
| 171 | :param headers: |
| 172 | Headers to include with all requests, unless other headers are given |
| 173 | explicitly. |
| 174 | |
| 175 | :param \\**connection_pool_kw: |
| 176 | Additional parameters are used to create fresh |
| 177 | :class:`urllib3.connectionpool.ConnectionPool` instances. |
| 178 | |
| 179 | Example: |
| 180 | |
| 181 | .. code-block:: python |
| 182 | |
| 183 | import urllib3 |
| 184 | |
| 185 | http = urllib3.PoolManager(num_pools=2) |
| 186 | |
| 187 | resp1 = http.request("GET", "https://google.com/") |
| 188 | resp2 = http.request("GET", "https://google.com/mail") |
| 189 | resp3 = http.request("GET", "https://yahoo.com/") |
| 190 | |
| 191 | print(len(http.pools)) |
| 192 | # 2 |
| 193 | |
| 194 | """ |
| 195 | |
| 196 | proxy: Url | None = None |
| 197 | proxy_config: ProxyConfig | None = None |
| 198 | |
| 199 | def __init__( |
| 200 | self, |
| 201 | num_pools: int = 10, |
| 202 | headers: typing.Mapping[str, str] | None = None, |
| 203 | **connection_pool_kw: typing.Any, |
| 204 | ) -> None: |
| 205 | super().__init__(headers) |
| 206 | # PoolManager handles redirects itself in PoolManager.urlopen(). |
| 207 | # It always passes redirect=False to the underlying connection pool to |
| 208 | # suppress per-pool redirect handling. If the user supplied a non-Retry |
| 209 | # value (int/bool/etc) for retries and we let the pool normalize it |
| 210 | # while redirect=False, the resulting Retry object would have redirect |
| 211 | # handling disabled, which can interfere with PoolManager's own |
| 212 | # redirect logic. Normalize here so redirects remain governed solely by |
| 213 | # PoolManager logic. |
| 214 | if "retries" in connection_pool_kw: |
| 215 | retries = connection_pool_kw["retries"] |
| 216 | if not isinstance(retries, Retry): |
| 217 | retries = Retry.from_int(retries) |
| 218 | connection_pool_kw = connection_pool_kw.copy() |
| 219 | connection_pool_kw["retries"] = retries |
no outgoing calls