Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57dfcae

Browse files
committed
Make the serializer behave like a normal func with unknown kwargs
1 parent75cf697 commit57dfcae

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+
iflen(unexpected_args)>0:
160+
raiseTypeError("__init__() got an unexpected keyword argument '%s'"%next(iter(unexpected_args)))
158161
if'quote_char'inkwargs:
159162
self.use_best_quote_char=False
160163
forattrinself.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
defserialize_html(input,options):
8181
options=dict([(str(k),v)fork,vinoptions.items()])
82+
encoding=options.get("encoding",None)
83+
if"encoding"inoptions:
84+
deloptions["encoding"]
8285
stream=Lint(JsonWalker(input),False)
8386
serializer=HTMLSerializer(alphabetical_attributes=True,**options)
84-
returnserializer.render(stream,options.get("encoding",None))
87+
returnserializer.render(stream,encoding)
8588

8689

8790
defrunSerializerTest(input,expected,options):
@@ -146,6 +149,11 @@ def testComment():
146149
throwsWithLatin1([["Comment","\u0101"]])
147150

148151

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp