diff options
| author | robot-piglet <[email protected]> | 2023-11-18 09:45:45 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2023-11-18 10:04:04 +0300 |
| commit | df03ef42eed0a5b601011204e47b72d37c6373a9 (patch) | |
| tree | 530e7eed0215db0b677aa07c5ccc834a8cb60e5a /contrib/python/httpx | |
| parent | 02af688a175993fc8169edf79bef767977b91764 (diff) | |
Intermediate changes
Diffstat (limited to 'contrib/python/httpx')
| -rw-r--r-- | contrib/python/httpx/.dist-info/METADATA | 23 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/__version__.py | 2 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_auth.py | 9 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_compat.py | 4 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_config.py | 17 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_models.py | 17 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_multipart.py | 3 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_transports/default.py | 2 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_urlparse.py | 2 | ||||
| -rw-r--r-- | contrib/python/httpx/httpx/_utils.py | 35 | ||||
| -rw-r--r-- | contrib/python/httpx/ya.make | 3 |
11 files changed, 40 insertions, 77 deletions
diff --git a/contrib/python/httpx/.dist-info/METADATA b/contrib/python/httpx/.dist-info/METADATA index f3a6d509cd4..e4abd6660e3 100644 --- a/contrib/python/httpx/.dist-info/METADATA +++ b/contrib/python/httpx/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: httpx -Version: 0.25.0 +Version: 0.25.1 Summary: The next generation HTTP client. Project-URL: Changelog, https://github.com/encode/httpx/blob/master/CHANGELOG.md Project-URL: Documentation, https://www.python-httpx.org @@ -22,10 +22,12 @@ Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 +Classifier: Programming Language :: Python :: 3.12 Classifier: Topic :: Internet :: WWW/HTTP Requires-Python: >=3.8 +Requires-Dist: anyio Requires-Dist: certifi -Requires-Dist: httpcore<0.19.0,>=0.18.0 +Requires-Dist: httpcore Requires-Dist: idna Requires-Dist: sniffio Provides-Extra: brotli @@ -192,23 +194,14 @@ inspiration around the lower-level networking details. ## Release Information -### Removed +### 0.25.1 (3rd November, 2023) -* Drop support for Python 3.7. (#2813) - -### Added - -* Support HTTPS proxies. (#2845) -* Change the type of `Extensions` from `Mapping[Str, Any]` to `MutableMapping[Str, Any]`. (#2803) -* Add `socket_options` argument to `httpx.HTTPTransport` and `httpx.AsyncHTTPTransport` classes. (#2716) -* The `Response.raise_for_status()` method now returns the response instance. For example: `data = httpx.get('...').raise_for_status().json()`. (#2776) +* Add support for Python 3.12. (#2854) +* Add support for httpcore 1.0 (#2885) ### Fixed -* Return `500` error response instead of exceptions when `raise_app_exceptions=False` is set on `ASGITransport`. (#2669) -* Ensure all `WSGITransport` environs have a `SERVER_PROTOCOL`. (#2708) -* Always encode forward slashes as `%2F` in query parameters (#2723) -* Use Mozilla documentation instead of `httpstatuses.com` for HTTP error reference (#2768) +* Raise `ValueError` on `Response.encoding` being set after `Response.text` has been accessed. (#2852) --- diff --git a/contrib/python/httpx/httpx/__version__.py b/contrib/python/httpx/httpx/__version__.py index bfa421ad60e..9f92ef99b90 100644 --- a/contrib/python/httpx/httpx/__version__.py +++ b/contrib/python/httpx/httpx/__version__.py @@ -1,3 +1,3 @@ __title__ = "httpx" __description__ = "A next generation HTTP client, for Python 3." -__version__ = "0.25.0" +__version__ = "0.25.1" diff --git a/contrib/python/httpx/httpx/_auth.py b/contrib/python/httpx/httpx/_auth.py index 1d7385d5733..c2c38f39455 100644 --- a/contrib/python/httpx/httpx/_auth.py +++ b/contrib/python/httpx/httpx/_auth.py @@ -1,5 +1,4 @@ import hashlib -import netrc import os import re import time @@ -8,7 +7,7 @@ from base64 import b64encode from urllib.request import parse_http_list from ._exceptions import ProtocolError -from ._models import Request, Response +from ._models import Cookies, Request, Response from ._utils import to_bytes, to_str, unquote if typing.TYPE_CHECKING: # pragma: no cover @@ -148,6 +147,10 @@ class NetRCAuth(Auth): """ def __init__(self, file: typing.Optional[str] = None): + # Lazily import 'netrc'. + # There's no need for us to load this module unless 'NetRCAuth' is being used. + import netrc + self._netrc_info = netrc.netrc(file) def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]: @@ -217,6 +220,8 @@ class DigestAuth(Auth): request.headers["Authorization"] = self._build_auth_header( request, self._last_challenge ) + if response.cookies: + Cookies(response.cookies).set_cookie_header(request=request) yield request def _parse_challenge( diff --git a/contrib/python/httpx/httpx/_compat.py b/contrib/python/httpx/httpx/_compat.py index a271c6b8008..493e6210873 100644 --- a/contrib/python/httpx/httpx/_compat.py +++ b/contrib/python/httpx/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/contrib/python/httpx/httpx/_config.py b/contrib/python/httpx/httpx/_config.py index 8d4e03add5a..50bcede7f71 100644 --- a/contrib/python/httpx/httpx/_config.py +++ b/contrib/python/httpx/httpx/_config.py @@ -1,7 +1,6 @@ import logging import os import ssl -import sys import typing from pathlib import Path @@ -132,11 +131,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. @@ -175,10 +173,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/contrib/python/httpx/httpx/_models.py b/contrib/python/httpx/httpx/_models.py index e1e45cf06b2..4e4162db1a8 100644 --- a/contrib/python/httpx/httpx/_models.py +++ b/contrib/python/httpx/httpx/_models.py @@ -43,7 +43,6 @@ from ._types import ( ) from ._urls import URL from ._utils import ( - guess_json_utf, is_known_encoding, normalize_header_key, normalize_header_value, @@ -603,6 +602,16 @@ class Response: @encoding.setter def encoding(self, value: str) -> None: + """ + Set the encoding to use for decoding the byte content into text. + + If the `text` attribute has been accessed, attempting to set the + encoding will throw a ValueError. + """ + if hasattr(self, "_text"): + raise ValueError( + "Setting encoding after `text` has been accessed is not allowed." + ) self._encoding = value @property @@ -749,11 +758,7 @@ class Response: raise HTTPStatusError(message, request=request, response=self) def json(self, **kwargs: typing.Any) -> typing.Any: - if self.charset_encoding is None and self.content and len(self.content) > 3: - encoding = guess_json_utf(self.content) - if encoding is not None: - return jsonlib.loads(self.content.decode(encoding), **kwargs) - return jsonlib.loads(self.text, **kwargs) + return jsonlib.loads(self.content, **kwargs) @property def cookies(self) -> "Cookies": diff --git a/contrib/python/httpx/httpx/_multipart.py b/contrib/python/httpx/httpx/_multipart.py index 446f4ad2df3..6d5baa86398 100644 --- a/contrib/python/httpx/httpx/_multipart.py +++ b/contrib/python/httpx/httpx/_multipart.py @@ -1,4 +1,3 @@ -import binascii import io import os import typing @@ -200,7 +199,7 @@ class MultipartStream(SyncByteStream, AsyncByteStream): boundary: typing.Optional[bytes] = None, ) -> None: if boundary is None: - boundary = binascii.hexlify(os.urandom(16)) + boundary = os.urandom(16).hex().encode("ascii") self.boundary = boundary self.content_type = "multipart/form-data; boundary=%s" % boundary.decode( diff --git a/contrib/python/httpx/httpx/_transports/default.py b/contrib/python/httpx/httpx/_transports/default.py index 7dba5b8208a..76c543ce4e9 100644 --- a/contrib/python/httpx/httpx/_transports/default.py +++ b/contrib/python/httpx/httpx/_transports/default.py @@ -64,7 +64,7 @@ SOCKET_OPTION = typing.Union[ def map_httpcore_exceptions() -> typing.Iterator[None]: try: yield - except Exception as exc: # noqa: PIE-786 + except Exception as exc: mapped_exc = None for from_exc, to_exc in HTTPCORE_EXC_MAP.items(): diff --git a/contrib/python/httpx/httpx/_urlparse.py b/contrib/python/httpx/httpx/_urlparse.py index e1ba8dcdb76..8e060424e89 100644 --- a/contrib/python/httpx/httpx/_urlparse.py +++ b/contrib/python/httpx/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/contrib/python/httpx/httpx/_utils.py b/contrib/python/httpx/httpx/_utils.py index 1775b1a1ef9..ba5807c0487 100644 --- a/contrib/python/httpx/httpx/_utils.py +++ b/contrib/python/httpx/httpx/_utils.py @@ -91,41 +91,6 @@ def format_form_param(name: str, value: str) -> bytes: return f'{name}="{value}"'.encode() -# Null bytes; no need to recreate these on each call to guess_json_utf -_null = b"\x00" -_null2 = _null * 2 -_null3 = _null * 3 - - -def guess_json_utf(data: bytes) -> typing.Optional[str]: - # JSON always starts with two ASCII characters, so detection is as - # easy as counting the nulls and from their location and count - # determine the encoding. Also detect a BOM, if present. - sample = data[:4] - if sample in (codecs.BOM_UTF32_LE, codecs.BOM_UTF32_BE): - return "utf-32" # BOM included - if sample[:3] == codecs.BOM_UTF8: - return "utf-8-sig" # BOM included, MS style (discouraged) - if sample[:2] in (codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE): - return "utf-16" # BOM included - nullcount = sample.count(_null) - if nullcount == 0: - return "utf-8" - if nullcount == 2: - if sample[::2] == _null2: # 1st and 3rd are null - return "utf-16-be" - if sample[1::2] == _null2: # 2nd and 4th are null - return "utf-16-le" - # Did not detect 2 valid UTF-16 ascii-range characters - if nullcount == 3: - if sample[:3] == _null3: - return "utf-32-be" - if sample[1:] == _null3: - return "utf-32-le" - # Did not detect a valid UTF-32 ascii-range character - return None - - def get_ca_bundle_from_env() -> typing.Optional[str]: if "SSL_CERT_FILE" in os.environ: ssl_file = Path(os.environ["SSL_CERT_FILE"]) diff --git a/contrib/python/httpx/ya.make b/contrib/python/httpx/ya.make index 850e354ef05..112b04e9982 100644 --- a/contrib/python/httpx/ya.make +++ b/contrib/python/httpx/ya.make @@ -2,11 +2,12 @@ PY3_LIBRARY() -VERSION(0.25.0) +VERSION(0.25.1) LICENSE(BSD-3-Clause) PEERDIR( + contrib/python/anyio contrib/python/certifi contrib/python/httpcore contrib/python/idna |
