Skip to content

Commit 28fb733

Browse files
committed
Make the serializer behave like a normal func with unknown kwargs
1 parent 556043b commit 28fb733

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

html5lib/serializer/htmlserializer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def __init__(self, **kwargs):
155155
156156
.. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation
157157
"""
158+
unexpected_args = frozenset(kwargs) - frozenset(self.options)
159+
if len(unexpected_args) > 0:
160+
raise TypeError("__init__() got an unexpected keyword argument '%s'" % next(iter(unexpected_args)))
158161
if 'quote_char' in kwargs:
159162
self.use_best_quote_char = False
160163
for attr in self.options:

html5lib/tests/test_serializer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ def _convertAttrib(self, attribs):
7979

8080
def serialize_html(input, options):
8181
options = dict([(str(k), v) for k, v in options.items()])
82+
encoding = options.get("encoding", None)
83+
if "encoding" in options:
84+
del options["encoding"]
8285
stream = Lint(JsonWalker(input), False)
8386
serializer = HTMLSerializer(alphabetical_attributes=True, **options)
84-
return serializer.render(stream, options.get("encoding", None))
87+
return serializer.render(stream, encoding)
8588

8689

8790
def runSerializerTest(input, expected, options):

0 commit comments

Comments
 (0)