Skip to content

Commit 57dfcae

Browse files
committed
Make the serializer behave like a normal func with unknown kwargs
1 parent 75cf697 commit 57dfcae

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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: 9 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):
@@ -146,6 +149,11 @@ def testComment():
146149
throwsWithLatin1([["Comment", "\u0101"]])
147150

148151

152+
def testThrowsUnknownOption():
153+
with pytest.raises(TypeError):
154+
HTMLSerializer(foobar=None)
155+
156+
149157
@pytest.mark.parametrize("c", list("\t\n\u000C\x20\r\"'=<>`"))
150158
def testSpecQuoteAttribute(c):
151159
input_ = [["StartTag", "http://www.w3.org/1999/xhtml", "span",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy