Skip to content

Commit 106c0af

Browse files
committed
Update lint filter for Py3 and namespaced attributes.
1 parent 1e14765 commit 106c0af

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

html5lib/filters/lint.py

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

3+
from gettext import gettext
4+
_ = gettext
5+
6+
from six import text_type
7+
38
from . import _base
49
from ..constants import cdataElements, rcdataElements, voidElements
510

@@ -21,7 +26,7 @@ def __iter__(self):
2126
name = token["name"]
2227
if contentModelFlag != "PCDATA":
2328
raise LintError("StartTag not in PCDATA content model flag: %(tag)s" % {"tag": name})
24-
if not isinstance(name, str):
29+
if not isinstance(name, text_type):
2530
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
2631
if not name:
2732
raise LintError("Empty tag name")
@@ -31,12 +36,14 @@ def __iter__(self):
3136
raise LintError("Non-void element reported as EmptyTag token: %(tag)s" % {"tag": token["name"]})
3237
if type == "StartTag":
3338
open_elements.append(name)
34-
for name, value in token["data"]:
35-
if not isinstance(name, str):
39+
for (ns, name), value in token["data"].items():
40+
if ns is not None and not isinstance(ns, text_type):
41+
raise LintError("Attribute namespace is not None or a string: %(name)r" % {"name": name})
42+
if not isinstance(name, text_type):
3643
raise LintError("Attribute name is not a string: %(name)r" % {"name": name})
3744
if not name:
3845
raise LintError("Empty attribute name")
39-
if not isinstance(value, str):
46+
if not isinstance(value, text_type):
4047
raise LintError("Attribute value is not a string: %(value)r" % {"value": value})
4148
if name in cdataElements:
4249
contentModelFlag = "CDATA"
@@ -47,7 +54,7 @@ def __iter__(self):
4754

4855
elif type == "EndTag":
4956
name = token["name"]
50-
if not isinstance(name, str):
57+
if not isinstance(name, text_type):
5158
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
5259
if not name:
5360
raise LintError("Empty tag name")
@@ -64,7 +71,7 @@ def __iter__(self):
6471

6572
elif type in ("Characters", "SpaceCharacters"):
6673
data = token["data"]
67-
if not isinstance(data, str):
74+
if not isinstance(data, text_type):
6875
raise LintError("Attribute name is not a string: %(name)r" % {"name": data})
6976
if not data:
7077
raise LintError("%(type)s token with empty data" % {"type": type})

0 commit comments

Comments
 (0)