diff --git a/lang/python/python-requests/Makefile b/lang/python/python-requests/Makefile index 1163d2ccb9..53b60cd409 100644 --- a/lang/python/python-requests/Makefile +++ b/lang/python/python-requests/Makefile @@ -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 , Alexandru Ardelean 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 diff --git a/lang/python/python-requests/test.sh b/lang/python/python-requests/test.sh index 1112a2f79c..a3f2146787 100644 --- a/lang/python/python-requests/test.sh +++ b/lang/python/python-requests/test.sh @@ -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