From 66b8034c50b3bb6000e65c92dbeea006f8347b3d Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Tue, 27 Aug 2013 20:17:19 +0100 Subject: [PATCH] Update lint filter for Py3 and namespaced attributes. --- html5lib/filters/lint.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/html5lib/filters/lint.py b/html5lib/filters/lint.py index 7cc99a4b..9b4962b9 100644 --- a/html5lib/filters/lint.py +++ b/html5lib/filters/lint.py @@ -3,6 +3,8 @@ from gettext import gettext _ = gettext +from six import text_type + from . import _base from ..constants import cdataElements, rcdataElements, voidElements @@ -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")) @@ -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" @@ -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")) @@ -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}) @@ -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"] ?