From 7c9db49f0c6c454fa6d0d7bdbd0d71c0a0cbacfd Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 21 Sep 2023 08:35:56 -0600 Subject: [PATCH 1/9] Add support for Python 3.12 (#2854) * Add support for Python 3.12 * Bump GitHub Actions * Remove redundant version checks * Add CHANGELOG entry --- .github/workflows/publish.yml | 2 +- .github/workflows/test-suite.yml | 5 +++-- CHANGELOG.md | 4 ++++ httpx/_compat.py | 4 +--- httpx/_config.py | 17 +++++++---------- pyproject.toml | 1 + 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3cbd4a8a..4ceb8c69 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,7 +14,7 @@ jobs: name: deploy steps: - - uses: "actions/checkout@v3" + - uses: "actions/checkout@v4" - uses: "actions/setup-python@v4" with: python-version: 3.8 diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index eb1cc7e2..c3ad08f1 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -14,13 +14,14 @@ jobs: strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - - uses: "actions/checkout@v3" + - uses: "actions/checkout@v4" - uses: "actions/setup-python@v4" with: python-version: "${{ matrix.python-version }}" + allow-prereleases: true - name: "Install dependencies" run: "scripts/install" - name: "Run linting checks" diff --git a/CHANGELOG.md b/CHANGELOG.md index 4842dfff..73b99c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Added + +* Add support for Python 3.12. (#2854) + ### Fixed * Raise `ValueError` on `Response.encoding` being set after `Response.text` has been accessed. (#2852) diff --git a/httpx/_compat.py b/httpx/_compat.py index a271c6b8..493e6210 100644 --- a/httpx/_compat.py +++ b/httpx/_compat.py @@ -16,9 +16,7 @@ except ImportError: # pragma: no cover except ImportError: brotli = None -if sys.version_info >= (3, 10) or ( - sys.version_info >= (3, 8) and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7) -): +if sys.version_info >= (3, 10) or ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7): def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None: # The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of diff --git a/httpx/_config.py b/httpx/_config.py index 39d81a20..45ed29ed 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -1,7 +1,6 @@ import logging import os import ssl -import sys import typing from pathlib import Path @@ -128,11 +127,10 @@ class SSLConfig: # Signal to server support for PHA in TLS 1.3. Raises an # AttributeError if only read-only access is implemented. - if sys.version_info >= (3, 8): # pragma: no cover - try: - context.post_handshake_auth = True - except AttributeError: # pragma: no cover - pass + try: + context.post_handshake_auth = True + except AttributeError: # pragma: no cover + pass # Disable using 'commonName' for SSLContext.check_hostname # when the 'subjectAltName' extension isn't available. @@ -168,10 +166,9 @@ class SSLConfig: alpn_idents = ["http/1.1", "h2"] if self.http2 else ["http/1.1"] context.set_alpn_protocols(alpn_idents) - if sys.version_info >= (3, 8): # pragma: no cover - keylogfile = os.environ.get("SSLKEYLOGFILE") - if keylogfile and self.trust_env: - context.keylog_filename = keylogfile + keylogfile = os.environ.get("SSLKEYLOGFILE") + if keylogfile and self.trust_env: + context.keylog_filename = keylogfile return context diff --git a/pyproject.toml b/pyproject.toml index 753e671e..baa92e9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Internet :: WWW/HTTP", ] dependencies = [ From 5d32e4c1bf7c11725ca01e30d2c394a623f1157a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:53:13 -0600 Subject: [PATCH 2/9] Bump cryptography from 41.0.3 to 41.0.4 (#2859) Bumps [cryptography](https://github.com/pyca/cryptography) from 41.0.3 to 41.0.4. - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/41.0.3...41.0.4) --- updated-dependencies: - dependency-name: cryptography dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a884446e..f5ec5ab3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,7 +21,7 @@ twine==4.0.2 # Tests & Linting black==23.7.0 coverage[toml]==7.3.0 -cryptography==41.0.3 +cryptography==41.0.4 mypy==1.5.1 types-certifi==2021.10.8.2 pytest==7.4.0 From c684e9f3aae6a34271260dedb06f5b932a2867b9 Mon Sep 17 00:00:00 2001 From: Kar Petrosyan <92274156+karosis88@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:30:49 -0400 Subject: [PATCH 3/9] Hishel as an alternative for "cachecontrol" and "requests-cache". (#2866) * Add Caching section in compatibility * typo --- docs/compatibility.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/compatibility.md b/docs/compatibility.md index b2092477..3e8bf9b9 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -201,6 +201,10 @@ Besides, `httpx.Request()` does not support the `auth`, `timeout`, `follow_redir If you need to mock HTTPX the same way that test utilities like `responses` and `requests-mock` does for `requests`, see [RESPX](https://github.com/lundberg/respx). +## Caching + +If you use `cachecontrol` or `requests-cache` to add HTTP Caching support to the `requests` library, you can use [Hishel](https://hishel.com) for HTTPX. + ## Networking layer `requests` defers most of its HTTP networking code to the excellent [`urllib3` library](https://urllib3.readthedocs.io/en/latest/). From 47fe956f74b2303bc67c0a464730522c9f039e0a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:15:01 -0600 Subject: [PATCH 4/9] Bump black from 23.7.0 to 23.9.1 (#2873) Bumps [black](https://github.com/psf/black) from 23.7.0 to 23.9.1. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/23.7.0...23.9.1) --- updated-dependencies: - dependency-name: black dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f5ec5ab3..c57e2555 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ build==0.10.0 twine==4.0.2 # Tests & Linting -black==23.7.0 +black==23.9.1 coverage[toml]==7.3.0 cryptography==41.0.4 mypy==1.5.1 From e63cec54929a4aac3246a60afa623ec6e02c93b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:26:46 -0600 Subject: [PATCH 5/9] Bump ruff from 0.0.286 to 0.0.291 (#2870) Bumps [ruff](https://github.com/astral-sh/ruff) from 0.0.286 to 0.0.291. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/astral-sh/ruff/compare/v0.0.286...v0.0.291) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c57e2555..c5c2460a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ cryptography==41.0.4 mypy==1.5.1 types-certifi==2021.10.8.2 pytest==7.4.0 -ruff==0.0.286 +ruff==0.0.291 trio==0.22.2 trio-typing==0.8.0 trustme==1.1.0 From 8dc2fb3e33ecc3754b20bcdebf488519104197eb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 23:34:13 -0500 Subject: [PATCH 6/9] Bump mkdocs from 1.5.2 to 1.5.3 (#2869) Bumps [mkdocs](https://github.com/mkdocs/mkdocs) from 1.5.2 to 1.5.3. - [Release notes](https://github.com/mkdocs/mkdocs/releases) - [Commits](https://github.com/mkdocs/mkdocs/compare/1.5.2...1.5.3) --- updated-dependencies: - dependency-name: mkdocs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c5c2460a..83ffa502 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ chardet==5.2.0 types-chardet==5.0.4.5 # Documentation -mkdocs==1.5.2 +mkdocs==1.5.3 mkautodoc==0.2.0 mkdocs-material==9.2.6 From 05b8e328447ec8f5906b1455c32b1071f73dfe23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:39:05 +0100 Subject: [PATCH 7/9] Bump pytest from 7.4.0 to 7.4.2 (#2871) Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.0 to 7.4.2. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.0...7.4.2) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Zanie Blue --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 83ffa502..9218f530 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ coverage[toml]==7.3.0 cryptography==41.0.4 mypy==1.5.1 types-certifi==2021.10.8.2 -pytest==7.4.0 +pytest==7.4.2 ruff==0.0.291 trio==0.22.2 trio-typing==0.8.0 From 3ba5fe0d7ac70222590e759c31442b1cab263791 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:35:16 +0100 Subject: [PATCH 8/9] Bump mkdocs-material from 9.2.6 to 9.4.2 (#2872) Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.2.6 to 9.4.2. - [Release notes](https://github.com/squidfunk/mkdocs-material/releases) - [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG) - [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.2.6...9.4.2) --- updated-dependencies: - dependency-name: mkdocs-material dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom Christie --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9218f530..e3217ab0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ types-chardet==5.0.4.5 # Documentation mkdocs==1.5.3 mkautodoc==0.2.0 -mkdocs-material==9.2.6 +mkdocs-material==9.4.2 # Packaging build==0.10.0 From e63b6594f2863b7c8274eb0991ebc6cad63661f7 Mon Sep 17 00:00:00 2001 From: robinaly Date: Tue, 10 Oct 2023 13:03:47 +0200 Subject: [PATCH 9/9] Fix encode host (#2886) * Fix requiring dot literal rather than any character in IPv4 * Add check to prevent future errors --- httpx/_urlparse.py | 2 +- tests/test_urlparse.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/httpx/_urlparse.py b/httpx/_urlparse.py index e1ba8dcd..8e060424 100644 --- a/httpx/_urlparse.py +++ b/httpx/_urlparse.py @@ -87,7 +87,7 @@ COMPONENT_REGEX = { # We use these simple regexs as a first pass before handing off to # the stdlib 'ipaddress' module for IP address validation. -IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+.[0-9]+.[0-9]+.[0-9]+$") +IPv4_STYLE_HOSTNAME = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$") IPv6_STYLE_HOSTNAME = re.compile(r"^\[.*\]$") diff --git a/tests/test_urlparse.py b/tests/test_urlparse.py index 3ae9b04c..b03291b4 100644 --- a/tests/test_urlparse.py +++ b/tests/test_urlparse.py @@ -45,6 +45,12 @@ def test_urlparse_normalized_host(): assert url.host == "example.com" +def test_urlparse_ipv4_like_host(): + """rare host names used to quality as IPv4""" + url = httpx.URL("https://023b76x43144/") + assert url.host == "023b76x43144" + + def test_urlparse_valid_ipv4(): url = httpx.URL("https://1.2.3.4/") assert url.host == "1.2.3.4"