Skip to content

Commit e3bedc5

Browse files
committed
Fix #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
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy