Skip to content

Commit 1f04a3f

Browse files
committed
fixup! fixup! Preserve attribute order when parsing
1 parent d0f1027 commit 1f04a3f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

html5lib/html5parser.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
2-
from six import with_metaclass, viewkeys
2+
from six import with_metaclass, viewkeys, PY3
33

44
import types
55

@@ -2720,7 +2720,11 @@ def processEndTag(self, token):
27202720

27212721

27222722
def adjust_attributes(token, replacements):
2723-
if viewkeys(token['data']) & viewkeys(replacements):
2723+
if PY3 or utils.PY27:
2724+
needs_adjustment = viewkeys(token['data']) & viewkeys(replacements)
2725+
else:
2726+
needs_adjustment = frozenset(token['data']) & frozenset(replacements)
2727+
if needs_adjustment:
27242728
token['data'] = OrderedDict((replacements.get(k, k), v)
27252729
for k, v in token['data'].items())
27262730

html5lib/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3+
import sys
34
from types import ModuleType
45

56
from six import text_type
@@ -12,9 +13,11 @@
1213

1314
__all__ = ["default_etree", "MethodDispatcher", "isSurrogatePair",
1415
"surrogatePairToCodepoint", "moduleFactoryFactory",
15-
"supports_lone_surrogates"]
16+
"supports_lone_surrogates", "PY27"]
1617

1718

19+
PY27 = sys.version_info[0] == 2 and sys.version_info[1] >= 7
20+
1821
# Platforms not supporting lone surrogates (\uD800-\uDFFF) should be
1922
# caught by the below test. In general this would be any platform
2023
# using UTF-16 as its encoding of unicode strings, such as

0 commit comments

Comments
 (0)