Skip to content

Commit

Permalink
Make the serializer behave like a normal func with unknown kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnedders committed May 18, 2016
1 parent 75cf697 commit 57dfcae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions html5lib/serializer/htmlserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def __init__(self, **kwargs):
.. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation
"""
unexpected_args = frozenset(kwargs) - frozenset(self.options)
if len(unexpected_args) > 0:
raise TypeError("__init__() got an unexpected keyword argument '%s'" % next(iter(unexpected_args)))
if 'quote_char' in kwargs:
self.use_best_quote_char = False
for attr in self.options:
Expand Down
10 changes: 9 additions & 1 deletion html5lib/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ def _convertAttrib(self, attribs):

def serialize_html(input, options):
options = dict([(str(k), v) for k, v in options.items()])
encoding = options.get("encoding", None)
if "encoding" in options:
del options["encoding"]
stream = Lint(JsonWalker(input), False)
serializer = HTMLSerializer(alphabetical_attributes=True, **options)
return serializer.render(stream, options.get("encoding", None))
return serializer.render(stream, encoding)


def runSerializerTest(input, expected, options):
Expand Down Expand Up @@ -146,6 +149,11 @@ def testComment():
throwsWithLatin1([["Comment", "\u0101"]])


def testThrowsUnknownOption():
with pytest.raises(TypeError):
HTMLSerializer(foobar=None)


@pytest.mark.parametrize("c", list("\t\n\u000C\x20\r\"'=<>`"))
def testSpecQuoteAttribute(c):
input_ = [["StartTag", "http://www.w3.org/1999/xhtml", "span",
Expand Down

0 comments on commit 57dfcae

Please sign in to comment.