From 2f43204790d4d159f42270592cfc96b77e78d622 Mon Sep 17 00:00:00 2001 From: John Parton Date: Fri, 8 Sep 2023 14:55:19 -0500 Subject: [PATCH] Emit deprecation warning. --- aiohttp/client.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/aiohttp/client.py b/aiohttp/client.py index 55db672b5b9..2a4e7a8cf90 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -167,6 +167,21 @@ class ClientTimeout: _CharsetResolver = Callable[[ClientResponse, bytes], str] +def _default_fallback_charset_resolver(response: ClientResponse, body: bytes) -> str: + + ret: str = chardet.detect(body)["encoding"] or "utf-8" + + if ret != "utf-8": + warnings.warn( + "Automatic character set detection is deprecated, use " + "fallback_charset_resolver instead.", + DeprecationWarning, + stacklevel=2, + ) + + return ret + + class ClientSession: """First-class interface for making HTTP requests.""" @@ -226,8 +241,8 @@ def __init__( requote_redirect_url: bool = True, trace_configs: Optional[List[TraceConfig]] = None, read_bufsize: int = 2**16, - fallback_charset_resolver: _CharsetResolver = lambda r, b: ( - chardet.detect(b)["encoding"] or "utf-8" + fallback_charset_resolver: _CharsetResolver = ( + _default_fallback_charset_resolver ), ) -> None: if loop is None: