From 437ac47fe332106a07a2d5335bb89619f1bc23f7 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 21 Jan 2024 01:51:59 +0000 Subject: [PATCH] [PR #7995/43a5bc50 backport][3.9] Fix examples of `fallback_charset_resolver` function in client_advanced documentation (#8044) **This is a backport of PR #7995 as merged into master (43a5bc5097be31a25037fbfdbe39e86138a29cbd).** Co-authored-by: OMOTO Tsukasa --- CHANGES/7995.doc | 1 + docs/client_advanced.rst | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 CHANGES/7995.doc diff --git a/CHANGES/7995.doc b/CHANGES/7995.doc new file mode 100644 index 00000000000..70e3dfa5469 --- /dev/null +++ b/CHANGES/7995.doc @@ -0,0 +1 @@ +Fix examples of `fallback_charset_resolver` function in client_advanced documentation. -- by :user:`henry0312` diff --git a/docs/client_advanced.rst b/docs/client_advanced.rst index 037e50a9363..958e31dcc7c 100644 --- a/docs/client_advanced.rst +++ b/docs/client_advanced.rst @@ -674,7 +674,7 @@ example, this can be used with the ``chardetng_py`` library.:: def charset_resolver(resp: ClientResponse, body: bytes) -> str: tld = resp.url.host.rsplit(".", maxsplit=1)[-1] - return detect(body, allow_utf8=True, tld=tld) + return detect(body, allow_utf8=True, tld=tld.encode()) ClientSession(fallback_charset_resolver=charset_resolver) @@ -682,4 +682,4 @@ Or, if ``chardetng_py`` doesn't work for you, then ``charset-normalizer`` is ano from charset_normalizer import detect - ClientSession(fallback_charset_resolver=lamba r, b: detect(b)["encoding"] or "utf-8") + ClientSession(fallback_charset_resolver=lambda r, b: detect(b)["encoding"] or "utf-8")