1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-09-11 20:47:56 +03:00

Clean code handling keyword args for html5lib.parse

This commit is contained in:
Guillaume Ayoub 2023-12-16 22:21:15 +01:00
parent 92948eb2e5
commit f58fd3b42b

View File

@ -162,15 +162,12 @@ class HTML:
if isinstance(source, str):
result = html5lib.parse(source, namespaceHTMLElements=False)
else:
potentially_undefined_kwargs = {
'namespaceHTMLElements': False,
'transport_encoding': protocol_encoding,
'override_encoding': encoding,
}
filtered_kwargs = {k: v for k, v in potentially_undefined_kwargs.items() if v is not None}
result = html5lib.parse(source, **filtered_kwargs)
kwargs = {'namespaceHTMLElements': False}
if protocol_encoding is not None:
kwargs['transport_encoding'] = protocol_encoding
if encoding is not None:
kwargs['override_encoding'] = encoding
result = html5lib.parse(source, **kwargs)
self.base_url = _find_base_url(result, base_url)
self.url_fetcher = url_fetcher
self.media_type = media_type