Skip to content

Commit 66b8034

Browse files
committed
Update lint filter for Py3 and namespaced attributes.
1 parent 9a37828 commit 66b8034

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

html5lib/filters/lint.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from gettext import gettext
44
_ = gettext
55

6+
from six import text_type
7+
68
from . import _base
79
from ..constants import cdataElements, rcdataElements, voidElements
810

@@ -24,7 +26,7 @@ def __iter__(self):
2426
name = token["name"]
2527
if contentModelFlag != "PCDATA":
2628
raise LintError(_("StartTag not in PCDATA content model flag: %(tag)s") % {"tag": name})
27-
if not isinstance(name, str):
29+
if not isinstance(name, text_type):
2830
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
2931
if not name:
3032
raise LintError(_("Empty tag name"))
@@ -34,12 +36,14 @@ def __iter__(self):
3436
raise LintError(_("Non-void element reported as EmptyTag token: %(tag)s") % {"tag": token["name"]})
3537
if type == "StartTag":
3638
open_elements.append(name)
37-
for name, value in token["data"]:
38-
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):
3943
raise LintError(_("Attribute name is not a string: %(name)r") % {"name": name})
4044
if not name:
4145
raise LintError(_("Empty attribute name"))
42-
if not isinstance(value, str):
46+
if not isinstance(value, text_type):
4347
raise LintError(_("Attribute value is not a string: %(value)r") % {"value": value})
4448
if name in cdataElements:
4549
contentModelFlag = "CDATA"
@@ -50,7 +54,7 @@ def __iter__(self):
5054

5155
elif type == "EndTag":
5256
name = token["name"]
53-
if not isinstance(name, str):
57+
if not isinstance(name, text_type):
5458
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
5559
if not name:
5660
raise LintError(_("Empty tag name"))
@@ -67,7 +71,7 @@ def __iter__(self):
6771

6872
elif type in ("Characters", "SpaceCharacters"):
6973
data = token["data"]
70-
if not isinstance(data, str):
74+
if not isinstance(data, text_type):
7175
raise LintError(_("Attribute name is not a string: %(name)r") % {"name": data})
7276
if not data:
7377
raise LintError(_("%(type)s token with empty data") % {"type": type})
@@ -80,7 +84,7 @@ def __iter__(self):
8084
name = token["name"]
8185
if contentModelFlag != "PCDATA":
8286
raise LintError(_("Doctype not in PCDATA content model flag: %(name)s") % {"name": name})
83-
if not isinstance(name, str):
87+
if not isinstance(name, text_type):
8488
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
8589
# XXX: what to do with token["data"] ?
8690

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy