Remove strict parameter
MODIFY
src/urllib3/connection.py
src/urllib3/connection.py
@@ -64,7 +64,6 @@ class HTTPConnection(_HTTPConnection):
Additional keyword parameters are used to configure attributes of the connection.
Accepted parameters include:
- - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
- ``source_address``: Set the source address for the current connection.
- ``socket_options``: Set specific options on the underlying socket. If not specified, then
defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
@@ -92,8 +91,6 @@ class HTTPConnection(_HTTPConnection):
is_verified = False
def __init__(self, *args, **kw):
- kw.pop("strict", None)
-
# Pre-set source_address.
self.source_address = kw.get("source_address")
@@ -274,14 +271,13 @@ class HTTPSConnection(HTTPConnection):
key_file=None,
cert_file=None,
key_password=None,
- strict=None,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
ssl_context=None,
server_hostname=None,
**kw,
):
- HTTPConnection.__init__(self, host, port, strict=strict, timeout=timeout, **kw)
+ HTTPConnection.__init__(self, host, port, timeout=timeout, **kw)
self.key_file = key_file
self.cert_file = cert_file

MODIFY
src/urllib3/connectionpool.py
src/urllib3/connectionpool.py
@@ -109,14 +109,6 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
Port used for this HTTP Connection (None is equivalent to 80), passed
into :class:`http.client.HTTPConnection`.
- :param strict:
- Causes BadStatusLine to be raised if the status line can't be parsed
- as a valid HTTP/1.0 or 1.1 status line, passed into
- :class:`http.client.HTTPConnection`.
-
- .. note::
- Only works in Python 2. This parameter is ignored in Python 3.
-
:param timeout:
Socket timeout in seconds for each individual connection. This can
be a float or integer, which sets the timeout for the HTTP request,
@@ -165,7 +157,6 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
self,
host,
port=None,
- strict=False,
timeout=Timeout.DEFAULT_TIMEOUT,
maxsize=1,
block=False,
@@ -179,8 +170,6 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
ConnectionPool.__init__(self, host, port)
RequestMethods.__init__(self, headers)
- self.strict = strict
-
if not isinstance(timeout, Timeout):
timeout = Timeout.from_float(timeout)
@@ -231,7 +220,6 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
host=self.host,
port=self.port,
timeout=self.timeout.connect_timeout,
- strict=self.strict,
**self.conn_kw,
)
return conn
@@ -877,7 +865,6 @@ class HTTPSConnectionPool(HTTPConnectionPool):
self,
host,
port=None,
- strict=False,
timeout=Timeout.DEFAULT_TIMEOUT,
maxsize=1,
block=False,
@@ -901,7 +888,6 @@ class HTTPSConnectionPool(HTTPConnectionPool):
self,
host,
port,
- strict,
timeout,
maxsize,
block,
@@ -984,7 +970,6 @@ class HTTPSConnectionPool(HTTPConnectionPool):
host=actual_host,
port=actual_port,
timeout=self.timeout.connect_timeout,
- strict=self.strict,
cert_file=self.cert_file,
key_file=self.key_file,
key_password=self.key_password,

MODIFY
src/urllib3/poolmanager.py
src/urllib3/poolmanager.py
@@ -40,7 +40,6 @@ _key_fields = (
"key_port", # int
"key_timeout", # int or float or Timeout
"key_retries", # int or Retry
- "key_strict", # bool
"key_block", # bool
"key_source_address", # str
"key_key_file", # str

MODIFY
src/urllib3/response.py
src/urllib3/response.py
@@ -196,7 +196,6 @@ class HTTPResponse(io.IOBase):
status=0,
version=0,
reason=None,
- strict=0,
preload_content=True,
decode_content=True,
original_response=None,
@@ -217,7 +216,6 @@ class HTTPResponse(io.IOBase):
self.status = status
self.version = version
self.reason = reason
- self.strict = strict
self.decode_content = decode_content
self.retries = retries
self.enforce_content_length = enforce_content_length
@@ -588,15 +586,12 @@ class HTTPResponse(io.IOBase):
if not isinstance(headers, HTTPHeaderDict):
headers = HTTPHeaderDict(headers.items())
- # HTTPResponse objects in Python 3 don't have a .strict attribute
- strict = getattr(r, "strict", 0)
resp = ResponseCls(
body=r,
headers=headers,
status=r.status,
version=r.version,
reason=r.reason,
- strict=strict,
original_response=r,
**response_kw,
)

MODIFY
test/test_compatibility.py
test/test_compatibility.py
import http.cookiejar
import urllib
-import warnings
-import pytest
-
-from urllib3.connection import HTTPConnection
from urllib3.response import HTTPResponse
-class TestVersionCompatibility:
- def test_connection_strict(self):
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always")
-
- # strict=True is deprecated in Py33+
- HTTPConnection("localhost", 12345, strict=True)
-
- if w:
- pytest.fail(
- f"HTTPConnection raised warning on strict=True: {w[0].message!r}"
- )
-
- def test_connection_source_address(self):
- try:
- # source_address does not exist in Py26-
- HTTPConnection("localhost", 12345, source_address="127.0.0.1")
- except TypeError as e:
- pytest.fail(f"HTTPConnection raised TypeError on source_address: {e!r}")
-
-
class TestCookiejar:
def test_extract(self):
request = urllib.request.Request("http://google.com")

MODIFY
test/test_poolmanager.py
test/test_poolmanager.py
@@ -107,7 +107,6 @@ class TestPoolManager:
"timeout": timeout.Timeout(3.14),
"retries": retry.Retry(total=6, connect=2),
"block": True,
- "strict": True,
"source_address": "127.0.0.1",
}
p = PoolManager()
@@ -135,7 +134,6 @@ class TestPoolManager:
"timeout": timeout.Timeout(3.14),
"retries": retry.Retry(total=6, connect=2),
"block": True,
- "strict": True,
"source_address": "127.0.0.1",
"key_file": "/root/totally_legit.key",
"cert_file": "/root/totally_legit.crt",
@@ -290,37 +288,33 @@ class TestPoolManager:
def test_override_pool_kwargs_url(self):
"""Assert overriding pool kwargs works with connection_from_url."""
- p = PoolManager(strict=True)
- pool_kwargs = {"strict": False, "retries": 100, "block": True}
+ p = PoolManager()
+ pool_kwargs = {"retries": 100, "block": True}
default_pool = p.connection_from_url("http://example.com/")
override_pool = p.connection_from_url(
"http://example.com/", pool_kwargs=pool_kwargs
)
- assert default_pool.strict
assert retry.Retry.DEFAULT == default_pool.retries
assert not default_pool.block
- assert not override_pool.strict
assert 100 == override_pool.retries
assert override_pool.block
def test_override_pool_kwargs_host(self):
"""Assert overriding pool kwargs works with connection_from_host"""
- p = PoolManager(strict=True)
- pool_kwargs = {"strict": False, "retries": 100, "block": True}
+ p = PoolManager()
+ pool_kwargs = {"retries": 100, "block": True}
default_pool = p.connection_from_host("example.com", scheme="http")
override_pool = p.connection_from_host(
"example.com", scheme="http", pool_kwargs=pool_kwargs
)
- assert default_pool.strict
assert retry.Retry.DEFAULT == default_pool.retries
assert not default_pool.block
- assert not override_pool.strict
assert 100 == override_pool.retries
assert override_pool.block
@@ -343,13 +337,13 @@ class TestPoolManager:
def test_merge_pool_kwargs(self):
"""Assert _merge_pool_kwargs works in the happy case"""
- p = PoolManager(strict=True)
+ p = PoolManager(retries=100)
merged = p._merge_pool_kwargs({"new_key": "value"})
- assert {"strict": True, "new_key": "value"} == merged
+ assert {"retries": 100, "new_key": "value"} == merged
def test_merge_pool_kwargs_none(self):
"""Assert false-y values to _merge_pool_kwargs result in defaults"""
- p = PoolManager(strict=True)
+ p = PoolManager(retries=100)
merged = p._merge_pool_kwargs({})
assert p.connection_pool_kw == merged
merged = p._merge_pool_kwargs(None)
@@ -357,18 +351,18 @@ class TestPoolManager:
def test_merge_pool_kwargs_remove_key(self):
"""Assert keys can be removed with _merge_pool_kwargs"""
- p = PoolManager(strict=True)
- merged = p._merge_pool_kwargs({"strict": None})
- assert "strict" not in merged
+ p = PoolManager(retries=100)
+ merged = p._merge_pool_kwargs({"retries": None})
+ assert "retries" not in merged
def test_merge_pool_kwargs_invalid_key(self):
"""Assert removing invalid keys with _merge_pool_kwargs doesn't break"""
- p = PoolManager(strict=True)
+ p = PoolManager(retries=100)
merged = p._merge_pool_kwargs({"invalid_key": None})
assert p.connection_pool_kw == merged
def test_pool_manager_no_url_absolute_form(self):
"""Valides we won't send a request with absolute form without a proxy"""
- p = PoolManager(strict=True)
+ p = PoolManager()
assert p._proxy_requires_url_absolute_form("http://example.com") is False
assert p._proxy_requires_url_absolute_form("https://example.com") is False

Remove strict parameter (#2064)