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 May 19, 2014
1 parent 9a37828 commit 66b8034
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions html5lib/filters/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from gettext import gettext
_ = gettext

from six import text_type

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

Expand All @@ -24,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 @@ -34,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 @@ -50,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 @@ -67,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 All @@ -80,7 +84,7 @@ def __iter__(self):
name = token["name"]
if contentModelFlag != "PCDATA":
raise LintError(_("Doctype not in PCDATA content model flag: %(name)s") % {"name": name})
if not isinstance(name, str):
if not isinstance(name, text_type):
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
# XXX: what to do with token["data"] ?

Expand Down

0 comments on commit 66b8034

Please sign in to comment.