Tolerate the strict parameter being passed via connection_from_context()
MODIFY
dev-requirements.txt
dev-requirements.txt
@@ -9,3 +9,4 @@ trustme==0.7.0
cryptography==3.4.7
python-dateutil==2.8.1
typing-extensions==3.7.4.3
+requests

MODIFY
src/urllib3/poolmanager.py
src/urllib3/poolmanager.py
import functools
import logging
+import warnings
from typing import (
TYPE_CHECKING,
Any,
@@ -302,6 +303,14 @@ class PoolManager(RequestMethods):
``request_context`` must at least contain the ``scheme`` key and its
value must be a key in ``key_fn_by_scheme`` instance variable.
"""
+ if "strict" in request_context:
+ warnings.warn(
+ "The 'strict' parameter is no longer needed on Python 3+. "
+ "This will raise an error in urllib3 v3.0.0.",
+ DeprecationWarning,
+ )
+ request_context.pop("strict")
+
scheme = request_context["scheme"].lower()
pool_key_constructor = self.key_fn_by_scheme.get(scheme)
if not pool_key_constructor:

MODIFY
test/test_poolmanager.py
test/test_poolmanager.py
import socket
from test import resolvesLocalhostFQDN
+from unittest.mock import patch
import pytest
@@ -267,6 +268,32 @@ class TestPoolManager:
assert pool is other_pool
assert all(isinstance(key, PoolKey) for key in p.pools.keys())
+ @patch("urllib3.poolmanager.PoolManager.connection_from_pool_key")
+ def test_connection_from_context_strict_param(self, connection_from_pool_key):
+ p = PoolManager()
+ context = {
+ "scheme": "http",
+ "host": "example.com",
+ "port": 8080,
+ "strict": True,
+ }
+ with pytest.warns(DeprecationWarning) as record:
+ p.connection_from_context(context)
+
+ assert 1 == len(record)
+ msg = (
+ "The 'strict' parameter is no longer needed on Python 3+. "
+ "This will raise an error in urllib3 v3.0.0."
+ )
+ assert record[0].message.args[0] == msg
+
+ _, kwargs = connection_from_pool_key.call_args
+ assert kwargs["request_context"] == {
+ "scheme": "http",
+ "host": "example.com",
+ "port": 8080,
+ }
+
def test_custom_pool_key(self):
"""Assert it is possible to define a custom key function."""
p = PoolManager(10)

ADD
test/with_dummyserver/test_integration.py
+import pytest
+import requests
+
+from dummyserver.server import DEFAULT_CA
+from dummyserver.testcase import HTTPDummyServerTestCase, HTTPSDummyServerTestCase
+
+
+class TestHTTPIntegration(HTTPDummyServerTestCase):
+ def test_requests_integration(self):
+ with pytest.warns(DeprecationWarning) as record:
+ response = requests.get(f"{self.scheme}://{self.host}:{self.port}")
+
+ assert 200 == response.status_code
+ assert 1 == len(record)
+ msg = (
+ "The 'strict' parameter is no longer needed on Python 3+. "
+ "This will raise an error in urllib3 v3.0.0."
+ )
+ assert record[0].message.args[0] == msg
+
+
+class TestHTTPSIntegration(HTTPSDummyServerTestCase):
+ def test_requests_integration(self):
+ with pytest.warns(DeprecationWarning) as record:
+ response = requests.get(
+ f"{self.scheme}://{self.host}:{self.port}", verify=DEFAULT_CA
+ )
+
+ assert 200 == response.status_code
+ assert 1 == len(record)
+ msg = (
+ "The 'strict' parameter is no longer needed on Python 3+. "
+ "This will raise an error in urllib3 v3.0.0."
+ )
+ assert record[0].message.args[0] == msg

Tolerate the strict parameter being passed via connection_from_context()