Skip to content

Commit 3640fe8

Browse files
committed
Have a consistent API for errors where the format values are a dict.
Previously, they were sometimes a dict and sometimes needed wrapping before using. This complicates the API for users, and having hacks like this in our testsuite is just wonderful.
1 parent d7c0a1a commit 3640fe8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

html5lib/html5parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ def processCharacters(self, token):
15721572

15731573
def processEOF(self):
15741574
self.parser.parseError("expected-named-closing-tag-but-got-eof",
1575-
self.tree.openElements[-1].name)
1575+
{"name":self.tree.openElements[-1].name})
15761576
self.tree.openElements.pop()
15771577
self.parser.phase = self.parser.originalPhase
15781578
return True
@@ -2392,7 +2392,7 @@ def processStartTag(self, token):
23922392
(token["name"] == "font" and
23932393
set(token["data"].keys()) & set(["color", "face", "size"]))):
23942394
self.parser.parseError("unexpected-html-element-in-foreign-content",
2395-
token["name"])
2395+
{"name": token["name"]})
23962396
while (self.tree.openElements[-1].namespace !=
23972397
self.tree.defaultNamespace and
23982398
not self.parser.isHTMLIntegrationPoint(self.tree.openElements[-1]) and
@@ -2417,7 +2417,7 @@ def processEndTag(self, token):
24172417
nodeIndex = len(self.tree.openElements) - 1
24182418
node = self.tree.openElements[-1]
24192419
if node.name != token["name"]:
2420-
self.parser.parseError("unexpected-end-tag", token["name"])
2420+
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
24212421

24222422
while True:
24232423
if node.name.translate(asciiUpper2Lower) == token["name"]:

html5lib/tests/test_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ def runParserTest(innerHTML, input, expected, errors, treeClass,
5959
errorMsg = "\n".join(["\n\nInput:", input, "\nExpected:", expected,
6060
"\nReceived:", output])
6161
assert expected == output, errorMsg
62-
errStr = ["Line: %i Col: %i %s"%(line, col,
63-
constants.E[errorcode] % datavars if isinstance(datavars, dict) else (datavars,)) for
64-
((line,col), errorcode, datavars) in p.errors]
62+
63+
errStr = []
64+
for (line, col), errorcode, datavars in p.errors:
65+
assert isinstance(datavars, dict), "%s, %s" % (errorcode, repr(datavars))
66+
errStr.append("Line: %i Col: %i %s" % (line, col,
67+
constants.E[errorcode] % datavars))
6568

6669
errorMsg2 = "\n".join(["\n\nInput:", input,
6770
"\nExpected errors (" + str(len(errors)) + "):\n" + "\n".join(errors),

0 commit comments

Comments
 (0)