Skip to content

Commit

Permalink
Update lint filter for Py3 and namespaced attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnedders committed Nov 25, 2015
1 parent 1e14765 commit 106c0af
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions html5lib/filters/lint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from __future__ import absolute_import, division, unicode_literals

from gettext import gettext
_ = gettext

from six import text_type

from . import _base
from ..constants import cdataElements, rcdataElements, voidElements

Expand All @@ -21,7 +26,7 @@ def __iter__(self):
name = token["name"]
if contentModelFlag != "PCDATA":
raise LintError("StartTag not in PCDATA content model flag: %(tag)s" % {"tag": name})
if not isinstance(name, str):
if not isinstance(name, text_type):
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
if not name:
raise LintError("Empty tag name")
Expand All @@ -31,12 +36,14 @@ def __iter__(self):
raise LintError("Non-void element reported as EmptyTag token: %(tag)s" % {"tag": token["name"]})
if type == "StartTag":
open_elements.append(name)
for name, value in token["data"]:
if not isinstance(name, str):
for (ns, name), value in token["data"].items():
if ns is not None and not isinstance(ns, text_type):
raise LintError("Attribute namespace is not None or a string: %(name)r" % {"name": name})
if not isinstance(name, text_type):
raise LintError("Attribute name is not a string: %(name)r" % {"name": name})
if not name:
raise LintError("Empty attribute name")
if not isinstance(value, str):
if not isinstance(value, text_type):
raise LintError("Attribute value is not a string: %(value)r" % {"value": value})
if name in cdataElements:
contentModelFlag = "CDATA"
Expand All @@ -47,7 +54,7 @@ def __iter__(self):

elif type == "EndTag":
name = token["name"]
if not isinstance(name, str):
if not isinstance(name, text_type):
raise LintError("Tag name is not a string: %(tag)r" % {"tag": name})
if not name:
raise LintError("Empty tag name")
Expand All @@ -64,7 +71,7 @@ def __iter__(self):

elif type in ("Characters", "SpaceCharacters"):
data = token["data"]
if not isinstance(data, str):
if not isinstance(data, text_type):
raise LintError("Attribute name is not a string: %(name)r" % {"name": data})
if not data:
raise LintError("%(type)s token with empty data" % {"type": type})
Expand Down

0 comments on commit 106c0af

Please sign in to comment.