From a023118f50c021f56ac9633e731cbece8b4e189b Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Tue, 23 May 2023 18:40:22 -0700 Subject: [PATCH 1/5] tests(ci): set fail-fast: false so that the whole test matrix is run --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e20117e..c8f1de5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,7 @@ jobs: runs-on: "${{ matrix.os }}" strategy: + fail-fast: false matrix: python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] os: ["macos-10.15", "windows-latest", "ubuntu-latest"] From b6e0c0635bc3b17115f5459e3f5cc82bbf40d268 Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Tue, 23 May 2023 18:50:30 -0700 Subject: [PATCH 2/5] fix(ci): update matrix to use runners that support selected python versions --- .github/workflows/tests.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c8f1de5..5e0c4a5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,8 +16,13 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] - os: ["macos-10.15", "windows-latest", "ubuntu-latest"] + python-version: ["3.7", "3.8", "3.9", "3.10"] + os: ["macos-latest", "windows-latest", "ubuntu-latest"] + include: + - python-version: "3.6" + os: "ubuntu-20.04" + - python-version: "3.6" + os: "windows-latest" steps: - uses: "actions/checkout@v2" From 51b752b33f3dca9859b6635eecbd6a1c0b545578 Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Tue, 23 May 2023 19:22:31 -0700 Subject: [PATCH 3/5] fix: omit `strict` attribute from response serialization The `strict` attribute of `HTTPResponse` is gone in `urllib3>=2.0`. In addition it has no effect, at least when running under Python 3. --- cachecontrol/serialize.py | 1 - tests/test_vary.py | 1 - 2 files changed, 2 deletions(-) diff --git a/cachecontrol/serialize.py b/cachecontrol/serialize.py index 70135d3..f0c215c 100644 --- a/cachecontrol/serialize.py +++ b/cachecontrol/serialize.py @@ -51,7 +51,6 @@ def dumps(self, request, response, body=None): u"status": response.status, u"version": response.version, u"reason": text_type(response.reason), - u"strict": response.strict, u"decode_content": response.decode_content, } } diff --git a/tests/test_vary.py b/tests/test_vary.py index 543294b..28d20bd 100644 --- a/tests/test_vary.py +++ b/tests/test_vary.py @@ -33,7 +33,6 @@ def cached_equal(self, cached, resp): cached.status == resp.raw.status, cached.version == resp.raw.version, cached.reason == resp.raw.reason, - cached.strict == resp.raw.strict, cached.decode_content == resp.raw.decode_content, ] From 240dc16a2091d988d6fbc2767ded16806fb2f084 Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Tue, 23 May 2023 21:21:36 -0700 Subject: [PATCH 4/5] fix: omit `strict` attribute during response deserialization This prevents issues when deserializing responses serialized by an earlier version of cachecontrol. --- cachecontrol/serialize.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cachecontrol/serialize.py b/cachecontrol/serialize.py index f0c215c..738fac7 100644 --- a/cachecontrol/serialize.py +++ b/cachecontrol/serialize.py @@ -137,6 +137,9 @@ def prepare_response(self, request, cached, body_file=None): # TypeError: 'str' does not support the buffer interface body = io.BytesIO(body_raw.encode("utf8")) + # Discard any `strict` parameter serialized by older version of cachecontrol. + cached["response"].pop("strict", None) + return HTTPResponse(body=body, preload_content=False, **cached["response"]) def _loads_v0(self, request, data, body_file=None): From b91b7ebcef29ac8252acf514f5c69f80125a34c8 Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Tue, 23 May 2023 20:18:40 -0700 Subject: [PATCH 5/5] fix(test_etag): fix for requests>=2.29 Patch all the possible methods that might be used to generate a response. --- tests/test_etag.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_etag.py b/tests/test_etag.py index 7523bf8..8668b21 100644 --- a/tests/test_etag.py +++ b/tests/test_etag.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2015 Eric Larson # # SPDX-License-Identifier: Apache-2.0 +from contextlib import ExitStack +from contextlib import suppress import pytest @@ -134,11 +136,20 @@ def test_not_modified_releases_connection(self, server, url): resp = Mock(status=304, headers={}) - # This is how the urllib3 response is created in - # requests.adapters - response_mod = "requests.adapters.HTTPResponse.from_httplib" + # These are various ways the the urllib3 response can created + # in requests.adapters. Which one is actually used depends + # on which version if `requests` is in use, as well as perhaps + # other parameters. + response_mods = [ + "requests.adapters.HTTPResponse.from_httplib", + "urllib3.HTTPConnectionPool.urlopen", + ] + + with ExitStack() as stack: + for mod in response_mods: + with suppress(ImportError): + stack.enter_context(patch(mod, Mock(return_value=resp))) - with patch(response_mod, Mock(return_value=resp)): sess.get(etag_url) assert resp.read.called assert resp.release_conn.called