python-requests: use charset-normalizer instead of chardet
authorAlexandru Ardelean <redacted>
Fri, 12 Jun 2026 04:22:13 +0000 (07:22 +0300)
committerJosef Schlehofer <redacted>
Fri, 12 Jun 2026 10:26:50 +0000 (12:26 +0200)
Switch runtime and host build deps from chardet to charset-normalizer,
the mandatory charset-detection backend since requests 2.26. Extend
test.sh to cover the new backend and bump PKG_RELEASE.

Signed-off-by: Alexandru Ardelean <redacted>
lang/python/python-requests/Makefile
lang/python/python-requests/test.sh

index 1163d2ccb9c56c26e34ed55d26ec19cca5c6563b..53b60cd409689e2353a44f92694b5e2d9e71e00b 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=python-requests
 PKG_VERSION:=2.34.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>, Alexandru Ardelean <ardeleanalex@gmail.com>
 PKG_LICENSE:=Apache-2.0
@@ -20,7 +20,7 @@ PYPI_NAME:=requests
 PKG_HASH:=f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed
 
 HOST_BUILD_DEPENDS:= \
-  python-chardet/host \
+  python-charset-normalizer/host \
   python-idna/host \
   python-urllib3/host \
   python-certifi/host
@@ -39,7 +39,7 @@ define Package/python3-requests
   URL:=https://requests.readthedocs.io
   DEPENDS:= \
          +python3-light  \
-         +python3-chardet  \
+         +python3-charset-normalizer  \
          +python3-idna  \
          +python3-urllib3  \
          +python3-certifi
index 1112a2f79c611526bbf833d3df21cc7cad28b4df..a3f2146787b4e69afe1b88d73676a5b051c95964 100644 (file)
@@ -36,5 +36,32 @@ from requests.exceptions import (
     TooManyRedirects, Timeout, ConnectTimeout, ReadTimeout
 )
 
-print("requests OK")
+# --- charset-normalizer backend (replaces chardet) ---
+# requests now pulls in charset-normalizer instead of chardet for content
+# charset detection. Verify both the standalone library and the path that
+# requests actually exercises (Response.apparent_encoding).
+import charset_normalizer
+from charset_normalizer import from_bytes
+
+sample = 'Bсеки човек има право на образование.'
+encoded = sample.encode('cp1251')
+
+# Standalone detection + decode round-trip.
+best = from_bytes(encoded).best()
+assert best is not None
+assert str(best) == sample
+
+# chardet-compatible detect() shim — this is the exact call requests makes.
+detected = charset_normalizer.detect(encoded)
+assert detected['encoding'] is not None
+
+# requests routes content charset detection through charset-normalizer.
+resp = requests.models.Response()
+resp._content = encoded
+enc = resp.apparent_encoding
+assert enc, "apparent_encoding should be resolved via charset-normalizer"
+resp.encoding = enc
+assert 'образование' in resp.text
+
+print("requests + charset-normalizer OK")
 EOF
git clone https://git.99rst.org/PROJECT