Skip to content

Fix parse.py after #257 #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from optparse import OptionParser

from html5lib import html5parser
from html5lib.tokenizer import HTMLTokenizer
from html5lib import treebuilders, serializer, treewalkers
from html5lib import constants
from html5lib import utils
Expand Down Expand Up @@ -53,9 +52,7 @@ def parse():

treebuilder = treebuilders.getTreeBuilder(opts.treebuilder)

tokenizer = HTMLTokenizer

p = html5parser.HTMLParser(tree=treebuilder, tokenizer=tokenizer, debug=opts.log)
p = html5parser.HTMLParser(tree=treebuilder, debug=opts.log)

if opts.fragment:
parseMethod = p.parseFragment
Expand Down Expand Up @@ -96,7 +93,7 @@ def parse():

def run(parseMethod, f, encoding, scripting):
try:
document = parseMethod(f, encoding=encoding, scripting=scripting)
document = parseMethod(f, override_encoding=encoding, scripting=scripting)
except:
document = None
traceback.print_exc()
Expand All @@ -117,16 +114,14 @@ def printOutput(parser, document, opts):
document.writexml(sys.stdout, encoding="utf-8")
elif tb == "lxml":
import lxml.etree
sys.stdout.write(lxml.etree.tostring(document))
sys.stdout.write(lxml.etree.tostring(document, encoding="unicode"))
elif tb == "etree":
sys.stdout.write(utils.default_etree.tostring(document))
sys.stdout.write(utils.default_etree.tostring(document, encoding="unicode"))
elif opts.tree:
if not hasattr(document, '__getitem__'):
document = [document]
for fragment in document:
print(parser.tree.testSerializer(fragment))
elif opts.hilite:
sys.stdout.write(document.hilite("utf-8"))
elif opts.html:
kwargs = {}
for opt in serializer.HTMLSerializer.options:
Expand Down Expand Up @@ -188,9 +183,6 @@ def getOptParser():
parser.add_option("", "--no-html", action="store_false", default=True,
dest="html", help="Don't output html")

parser.add_option("", "--hilite", action="store_true", default=False,
dest="hilite", help="Output as formatted highlighted code.")

parser.add_option("-c", "--encoding", action="store_true", default=False,
dest="encoding", help="Print character encoding used")

Expand Down