8000 Fix #112: fix parse.py to work with default args and XML serialisation. · pombredanne/html5lib-python@e3bedc5 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 header class="HeaderMktg header-logged-out js-details-container js-header Details f4 py-3" role="banner" data-is-top="true" data-color-mode=light data-light-theme=light data-dark-theme=dark>

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

Appearance settings

Commit e3bedc5

Browse files
committed
Fix html5lib#112: fix parse.py to work with default args and XML serialisation.
This is the result of fallout from the removal of simpletree!
1 parent f04b07b commit e3bedc5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

parse.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from html5lib.tokenizer import HTMLTokenizer
1414
from html5lib import treebuilders, serializer, treewalkers
1515
from html5lib import constants
16+
from html5lib import utils
1617

1718
def parse():
1819
optParser = getOptParser()
@@ -108,7 +109,14 @@ def printOutput(parser, document, opts):
108109

109110
if document is not None:
110111
if opts.xml:
111-
sys.stdout.write(document.toxml("utf-8"))
112+
tb = opts.treebuilder.lower()
113+
if tb == "dom":
114+
document.writexml(sys.stdout, encoding="utf-8")
115+
elif tb == "lxml":
116+
import lxml.etree
117+
sys.stdout.write(lxml.etree.tostring(document))
118+
elif tb == "etree":
119+
sys.stdout.write(utils.default_etree.tostring(document))
112120
elif opts.tree:
113121
if not hasattr(document,'__getitem__'):
114122
7204 document = [document]
@@ -152,7 +160,7 @@ def getOptParser():
152160
help="Time the run using time.time (may not be accurate on all platforms, especially for short runs)")
153161

154162
parser.add_option("-b", "--treebuilder", action="store", type="string",
155-
dest="treebuilder", default="simpleTree")
163+
dest="treebuilder", default="etree")
156164

157165
parser.add_option("-e", "--error", action="store_true", default=False,
158166
dest="error", help="Print a list of parse errors")

0 commit comments

Comments
 (0)
0