diff --git a/AUTHORS.rst b/AUTHORS.rst index 90401390..998be2f4 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -63,4 +63,5 @@ Patches and suggestions - Ville Skyttä - Hugo van Kemenade - Mark Vasilkov +- Afonso Januário diff --git a/CHANGES.rst b/CHANGES.rst index 47dcda3a..ca514ece 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,9 @@ Bug fixes: * The sanitizer now permits ```` tags. It used to allow ``
`` already. (#423) +* Encoding detection no longer triggers a ``DeprecationWarning`` under + chardet 7+, which moved ``UniversalDetector`` out of + ``chardet.universaldetector``. (#601) 1.1 ~~~ diff --git a/html5lib/_inputstream.py b/html5lib/_inputstream.py index a93b5a4e..a024f4b6 100644 --- a/html5lib/_inputstream.py +++ b/html5lib/_inputstream.py @@ -483,10 +483,16 @@ def determineEncoding(self, chardet=True): # Guess with chardet, if available if chardet: try: - from chardet.universaldetector import UniversalDetector + # chardet 7+ moved UniversalDetector here; the older + # chardet.universaldetector path still works but now raises + # a DeprecationWarning. + from chardet.detector import UniversalDetector except ImportError: - pass - else: + try: + from chardet.universaldetector import UniversalDetector + except ImportError: + UniversalDetector = None + if UniversalDetector is not None: buffers = [] detector = UniversalDetector() while not detector.done: