Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_starttag_node(self):
with self.assertRaises(InvalidHTML):
html_to_nodes(HTML_NO_STARTTAG)
def test_html_to_nodes_invalid_html(self):
with self.assertRaises(InvalidHTML):
html_to_nodes('<p><b></b></p>')
def handle_endtag(self, tag):
if tag in VOID_ELEMENTS:
return
if not len(self.parent_nodes):
raise InvalidHTML('"{}" missing start tag'.format(
tag
))
self.current_nodes = self.parent_nodes.pop()
last_node = self.current_nodes[-1]
if last_node['tag'] != tag:
raise InvalidHTML('"{}" tag closed instead of "{}"'.format(
tag, last_node['tag']
))
if not last_node['children']:
last_node.pop('children')
def get_nodes(self):
if self.parent_nodes:
not_closed_tag = self.parent_nodes[-1][-1]['tag']
raise InvalidHTML('"{}" tag is not closed'.format(not_closed_tag))
return self.nodes