From 0f1290070a9d301060f96bca8e681343b508d5e2 Mon Sep 17 00:00:00 2001 From: Grzegorz Zajac Date: Fri, 21 Mar 2025 15:53:05 +0100 Subject: [PATCH] Add support for Python 3.12+ where six.moves is not available. --- html5lib/_inputstream.py | 8 +++++++- html5lib/filters/sanitizer.py | 6 +++++- html5lib/tests/test_stream.py | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/html5lib/_inputstream.py b/html5lib/_inputstream.py index a93b5a4e..6195abfd 100644 --- a/html5lib/_inputstream.py +++ b/html5lib/_inputstream.py @@ -1,7 +1,13 @@ from __future__ import absolute_import, division, unicode_literals from six import text_type -from six.moves import http_client, urllib + +try: + from six.moves import http_client, urllib +except ModuleNotFoundError: + # Support for Python 3.12+ where six.moves is not available. + import http.client as http_client + import urllib import codecs import re diff --git a/html5lib/filters/sanitizer.py b/html5lib/filters/sanitizer.py index ea2c5dd3..5219c1c4 100644 --- a/html5lib/filters/sanitizer.py +++ b/html5lib/filters/sanitizer.py @@ -12,7 +12,11 @@ import warnings from xml.sax.saxutils import escape, unescape -from six.moves import urllib_parse as urlparse +try: + from six.moves import urllib_parse as urlparse +except ModuleNotFoundError: + # Support for Python 3.12+ where six.moves is not available. + import urllib.parse as urlparse from . import base from ..constants import namespaces, prefixes diff --git a/html5lib/tests/test_stream.py b/html5lib/tests/test_stream.py index efe9b472..063b4ca2 100644 --- a/html5lib/tests/test_stream.py +++ b/html5lib/tests/test_stream.py @@ -9,7 +9,13 @@ import pytest import six -from six.moves import http_client, urllib + +try: + from six.moves import http_client, urllib +except ModuleNotFoundError: + # Support for Python 3.12+ where six.moves is not available. + import http.client as http_client + import urllib from html5lib._inputstream import (BufferedStream, HTMLInputStream, HTMLUnicodeInputStream, HTMLBinaryInputStream)