python codes cleanup

This commit is contained in:
jnozsc 2020-07-26 09:56:12 -07:00
parent 62392966a3
commit db4e9722bf

View File

@ -125,8 +125,8 @@ except ImportError:
from htmlentitydefs import name2codepoint
# "void elements" (no closing tag) from the HTML Standard section 12.1.2
VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'])
VOID_ELEMENTS = {'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'}
# Python 2 -> 3 compatibility
try:
@ -146,7 +146,7 @@ class CustomHTMLParser(HTMLParser):
self.__builder = target or ET.TreeBuilder()
def handle_starttag(self, tag, attrs):
attrs = dict((k, v or '') for k, v in attrs)
attrs = {k: v or '' for k, v in attrs}
self.__builder.start(tag, attrs)
if tag in VOID_ELEMENTS:
self.__builder.end(tag)
@ -155,7 +155,7 @@ class CustomHTMLParser(HTMLParser):
self.__builder.end(tag)
def handle_startendtag(self, tag, attrs):
attrs = dict((k, v or '') for k, v in attrs)
attrs = {k: v or '' for k, v in attrs}
self.__builder.start(tag, attrs)
self.__builder.end(tag)