Created
May 2, 2017 16:36
-
-
Save indivisible/c31f800e9c0b463009f5f69f65aecba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import html5lib | |
| def test_parse_serialize(html, tree_type): | |
| walker = html5lib.getTreeWalker(tree_type) | |
| serializer = html5lib.serializer.HTMLSerializer() | |
| #root = html5lib.parseFragment(html, namespaceHTMLElements=False, treebuilder=tree_type) | |
| root = html5lib.parseFragment(html, treebuilder=tree_type) | |
| stream = walker(root) | |
| return serializer.render(stream) | |
| def test_html(html, tree_types=('etree', 'lxml')): | |
| print ('\ntesting %r:' % html) | |
| for tt in ('etree', 'lxml'): | |
| print (' with %r:\n %r' % (tt, test_parse_serialize(html, tt))) | |
| if __name__ == '__main__': | |
| # works | |
| test_html('<a>one</a>') | |
| # errors out for 'lxml' ('etree' works fine) | |
| test_html('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment