mirror of
https://github.com/openwrt/packages.git
synced 2026-06-17 14:50:07 +04:00
python-requests: use charset-normalizer instead of chardet
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 <alex@shruggie.ro>
This commit is contained in:
committed by
Josef Schlehofer
parent
9c97b73b1a
commit
dcc90f1920
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=python-requests
|
PKG_NAME:=python-requests
|
||||||
PKG_VERSION:=2.34.2
|
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_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>, Alexandru Ardelean <ardeleanalex@gmail.com>
|
||||||
PKG_LICENSE:=Apache-2.0
|
PKG_LICENSE:=Apache-2.0
|
||||||
@@ -20,7 +20,7 @@ PYPI_NAME:=requests
|
|||||||
PKG_HASH:=f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed
|
PKG_HASH:=f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed
|
||||||
|
|
||||||
HOST_BUILD_DEPENDS:= \
|
HOST_BUILD_DEPENDS:= \
|
||||||
python-chardet/host \
|
python-charset-normalizer/host \
|
||||||
python-idna/host \
|
python-idna/host \
|
||||||
python-urllib3/host \
|
python-urllib3/host \
|
||||||
python-certifi/host
|
python-certifi/host
|
||||||
@@ -39,7 +39,7 @@ define Package/python3-requests
|
|||||||
URL:=https://requests.readthedocs.io
|
URL:=https://requests.readthedocs.io
|
||||||
DEPENDS:= \
|
DEPENDS:= \
|
||||||
+python3-light \
|
+python3-light \
|
||||||
+python3-chardet \
|
+python3-charset-normalizer \
|
||||||
+python3-idna \
|
+python3-idna \
|
||||||
+python3-urllib3 \
|
+python3-urllib3 \
|
||||||
+python3-certifi
|
+python3-certifi
|
||||||
|
|||||||
@@ -36,5 +36,32 @@ from requests.exceptions import (
|
|||||||
TooManyRedirects, Timeout, ConnectTimeout, ReadTimeout
|
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
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user