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 17, 2016
1 parent 556043b commit 28fb733
Show file tree
Hide file tree
Showing 2 changed files with 7 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
5 changes: 4 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

0 comments on commit 28fb733

Please sign in to comment.