diff --git a/html5lib/_tokenizer.py b/html5lib/_tokenizer.py index 6078f66a..9754763a 100644 --- a/html5lib/_tokenizer.py +++ b/html5lib/_tokenizer.py @@ -2,8 +2,6 @@ from six import unichr as chr -from collections import deque - from .constants import spaceCharacters from .constants import entities from .constants import asciiLetters, asciiUpper2Lower @@ -15,6 +13,11 @@ from ._trie import Trie +try: + from collections.abc import deque +except ImportError: + from collections import deque + entitiesTrie = Trie(entities) diff --git a/html5lib/filters/alphabeticalattributes.py b/html5lib/filters/alphabeticalattributes.py index 5ba926e3..ccdb58c8 100644 --- a/html5lib/filters/alphabeticalattributes.py +++ b/html5lib/filters/alphabeticalattributes.py @@ -2,7 +2,10 @@ from . import base -from collections import OrderedDict +try: + from collections.abc import OrderedDict +except ImportError: + from collections import OrderedDict def _attr_key(attr): diff --git a/html5lib/html5parser.py b/html5lib/html5parser.py index 9d39b9d4..a6a38f4f 100644 --- a/html5lib/html5parser.py +++ b/html5lib/html5parser.py @@ -2,7 +2,6 @@ from six import with_metaclass, viewkeys import types -from collections import OrderedDict from . import _inputstream from . import _tokenizer @@ -23,6 +22,11 @@ _ReparseException ) +try: + from collections.abc import OrderedDict +except ImportError: + from collections import OrderedDict + def parse(doc, treebuilder="etree", namespaceHTMLElements=True, **kwargs): """Parse an HTML document as a string or file-like object into a tree diff --git a/html5lib/tests/test_alphabeticalattributes.py b/html5lib/tests/test_alphabeticalattributes.py index 7d5b8e0f..75fac3ea 100644 --- a/html5lib/tests/test_alphabeticalattributes.py +++ b/html5lib/tests/test_alphabeticalattributes.py @@ -1,13 +1,16 @@ from __future__ import absolute_import, division, unicode_literals -from collections import OrderedDict - import pytest import html5lib from html5lib.filters.alphabeticalattributes import Filter from html5lib.serializer import HTMLSerializer +try: + from collections.abc import OrderedDict +except ImportError: + from collections import OrderedDict + @pytest.mark.parametrize('msg, attrs, expected_attrs', [ ( diff --git a/html5lib/treewalkers/etree.py b/html5lib/treewalkers/etree.py index d15a7eeb..805cf652 100644 --- a/html5lib/treewalkers/etree.py +++ b/html5lib/treewalkers/etree.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, division, unicode_literals -from collections import OrderedDict import re from six import string_types @@ -8,6 +7,11 @@ from . import base from .._utils import moduleFactoryFactory +try: + from collections.abc import OrderedDict +except ImportError: + from collections import OrderedDict + tag_regexp = re.compile("{([^}]*)}(.*)")