Skip to content

Commit f61e328

Browse files
mikewestgsnedders
authored andcommitted
Fix warnings xgettext gives in html5lib.
This is relatively trivially resolved by changing the bare `%s`, `%r`, etc. into named substitutions.
1 parent 9f42786 commit f61e328

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

html5lib/filters/lint.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ def __iter__(self):
2323
if type in ("StartTag", "EmptyTag"):
2424
name = token["name"]
2525
if contentModelFlag != "PCDATA":
26-
raise LintError(_("StartTag not in PCDATA content model flag: %s") % name)
26+
raise LintError(_("StartTag not in PCDATA content model flag: %(tag)s") % {"tag": name})
2727
if not isinstance(name, str):
28-
raise LintError(_("Tag name is not a string: %r") % name)
28+
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
2929
if not name:
3030
raise LintError(_("Empty tag name"))
3131
if type == "StartTag" and name in voidElements:
32-
raise LintError(_("Void element reported as StartTag token: %s") % name)
32+
raise LintError(_("Void element reported as StartTag token: %(tag)s") % {"tag": name})
3333
elif type == "EmptyTag" and name not in voidElements:
34-
raise LintError(_("Non-void element reported as EmptyTag token: %s") % token["name"])
34+
raise LintError(_("Non-void element reported as EmptyTag token: %(tag)s") % {"tag": token["name"]})
3535
if type == "StartTag":
3636
open_elements.append(name)
3737
for name, value in token["data"]:
3838
if not isinstance(name, str):
39-
raise LintError(_("Attribute name is not a string: %r") % name)
39+
raise LintError(_("Attribute name is not a string: %(name)r") % {"name": name})
4040
if not name:
4141
raise LintError(_("Empty attribute name"))
4242
if not isinstance(value, str):
43-
raise LintError(_("Attribute value is not a string: %r") % value)
43+
raise LintError(_("Attribute value is not a string: %(value)r") % {"value": value})
4444
if name in cdataElements:
4545
contentModelFlag = "CDATA"
4646
elif name in rcdataElements:
@@ -51,14 +51,14 @@ def __iter__(self):
5151
elif type == "EndTag":
5252
name = token["name"]
5353
if not isinstance(name, str):
54-
raise LintError(_("Tag name is not a string: %r") % name)
54+
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
5555
if not name:
5656
raise LintError(_("Empty tag name"))
5757
if name in voidElements:
58-
raise LintError(_("Void element reported as EndTag token: %s") % name)
58+
raise LintError(_("Void element reported as EndTag token: %(tag)s") % {"tag": name})
5959
start_name = open_elements.pop()
6060
if start_name != name:
61-
raise LintError(_("EndTag (%s) does not match StartTag (%s)") % (name, start_name))
61+
raise LintError(_("EndTag (%(end)s) does not match StartTag (%(start)s)") % {"end": name, "start": start_name})
6262
contentModelFlag = "PCDATA"
6363

6464
elif type == "Comment":
@@ -68,26 +68,26 @@ def __iter__(self):
6868
elif type in ("Characters", "SpaceCharacters"):
6969
data = token["data"]
7070
if not isinstance(data, str):
71-
raise LintError(_("Attribute name is not a string: %r") % data)
71+
raise LintError(_("Attribute name is not a string: %(name)r") % {"name": data})
7272
if not data:
73-
raise LintError(_("%s token with empty data") % type)
73+
raise LintError(_("%(type)s token with empty data") % {"type": type})
7474
if type == "SpaceCharacters":
7575
data = data.strip(spaceCharacters)
7676
if data:
77-
raise LintError(_("Non-space character(s) found in SpaceCharacters token: ") % data)
77+
raise LintError(_("Non-space character(s) found in SpaceCharacters token: %(token)r") % {"token": data})
7878

7979
elif type == "Doctype":
8080
name = token["name"]
8181
if contentModelFlag != "PCDATA":
82-
raise LintError(_("Doctype not in PCDATA content model flag: %s") % name)
82+
raise LintError(_("Doctype not in PCDATA content model flag: %(name)s") % {"name": name})
8383
if not isinstance(name, str):
84-
raise LintError(_("Tag name is not a string: %r") % name)
84+
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
8585
# XXX: what to do with token["data"] ?
8686

8787
elif type in ("ParseError", "SerializeError"):
8888
pass
8989

9090
else:
91-
raise LintError(_("Unknown token type: %s") % type)
91+
raise LintError(_("Unknown token type: %(type)s") % {"type": type})
9292

9393
yield token

0 commit comments

Comments
 (0)