Skip to content

Commit

Permalink
Emit deprecation warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-parton committed Sep 8, 2023
1 parent 2498f42 commit e530e2a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "utf-8"


class ClientSession:
"""First-class interface for making HTTP requests."""

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e530e2a

Please sign in to comment.