-
Notifications
You must be signed in to change notification settings - Fork 90
Description
Issue #276 was opened for Python 3.11 but this also affects, for example installing under Windows with Python 3.10
The current determination of whether to use cchardet or cchardet happens here
BlackSheep/blacksheep/messages.pyx
Lines 7 to 10 in 34ae494
| try: | |
| import cchardet as chardet | |
| except ImportError: | |
| import chardet |
And it is then used here
BlackSheep/blacksheep/messages.pyx
Line 157 in 34ae494
| return body.decode(chardet.detect(body)['encoding']) |
The current requirements.txt is somehow conflicting, because it allows skipping installation of cchardet for Python 3.11 and the same time says that chardet (the non C version, i.e.: pure python) is also requirement for all versions.
Lines 3 to 8 in 34ae494
| cchardet==2.1.7; python_version < '3.11' | |
| mock==5.0.1; python_version < '3.8' | |
| certifi==2022.12.7 | |
| cffi==1.15.1 | |
| chardet==3.0.4 | |
| charset-normalizer==2.1.1 |
And charset-normalizer, as suggested in issue #276 should be used as a replacement for cchardet. Surprisingly it is a requirement but it is not used.
Suggested actions
-
Drop
cchardetas a hard requirement for anything above3.9. Because there are wheels up to that version. i.e.
Changecchardet==2.1.7; python_version < '3.11'tocchardet==2.1.7; python_version < '3.10' -
Change the imports to also import
charset-normalizerand use it. Thedetectfunction ischardetcompatible.try: import cchardet as chardet except ImportError: try: import charset_normalizer as chardet except ImportError import chardet
This is actually redundant given that
charset-normalizerhas been added a a hard requirement torequirements.txt. A better approach would betry: import cchardet as chardet except ImportError: import charset_normalizer as chardet
And drop the pure python
chardetaltogether fromrequirements.txt. Bothblacksheepandcharset-normalizerare good for python3.8 => 3.11(which is the minimum common denominator, takingblacksheepas the restriction)
The detect portion of the code needs no change.
Should you need a pull-request, don't hesitate to say: yes and I will submit one