Browse Source

Add back try/catch to match dhtml code block

main
Luke Murphy 3 years ago
parent
commit
6cd15a6256
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 80
      etherpump/commands/pull.py

80
etherpump/commands/pull.py

@ -470,22 +470,25 @@ async def handle_pad(args, padid, data, info, session):
downloaded_html = True downloaded_html = True
if html["_code"] == 200: if html["_code"] == 200:
html_body = html["data"]["html"] try:
ver["path"] = p + ".raw.html" html_body = html["data"]["html"]
ver["url"] = quote(ver["path"]) ver["path"] = p + ".raw.html"
doc = html5lib.parse( ver["url"] = quote(ver["path"])
html_body, treebuilder="etree", namespaceHTMLElements=False doc = html5lib.parse(
) html_body, treebuilder="etree", namespaceHTMLElements=False
html5tidy( )
doc, html5tidy(
indent=True, doc,
title=padid, indent=True,
scripts=args.script, title=padid,
links=links, scripts=args.script,
) links=links,
async with await trio.open_file(ver["path"], "w") as f: )
output = ET.tostring(doc, method="html", encoding="unicode") async with await trio.open_file(ver["path"], "w") as f:
await f.write(output) output = ET.tostring(doc, method="html", encoding="unicode")
await f.write(output)
except TypeError:
ver["message"] = html["message"]
if args.all or args.magicwords: if args.all or args.magicwords:
if not downloaded_html: if not downloaded_html:
@ -495,28 +498,31 @@ async def handle_pad(args, padid, data, info, session):
ver["code"] = html["_code"] ver["code"] = html["_code"]
if html["_code"] == 200: if html["_code"] == 200:
html_body = html["data"]["html"] try:
ver["path"] = p + ".magicwords.html" html_body = html["data"]["html"]
ver["url"] = quote(ver["path"]) ver["path"] = p + ".magicwords.html"
for magic_word in magic_words: ver["url"] = quote(ver["path"])
replace_word = ( for magic_word in magic_words:
"<span class='highlight'>" + magic_word + "</span>" replace_word = (
"<span class='highlight'>" + magic_word + "</span>"
)
if magic_word in html_body:
html_body = html_body.replace(magic_word, replace_word)
doc = html5lib.parse(
html_body, treebuilder="etree", namespaceHTMLElements=False
) )
if magic_word in html_body: html5tidy(
html_body = html_body.replace(magic_word, replace_word) doc,
doc = html5lib.parse( indent=True,
html_body, treebuilder="etree", namespaceHTMLElements=False title=padid,
) scripts=args.script,
html5tidy( links=links,
doc, )
indent=True, async with await trio.open_file(ver["path"], "w") as f:
title=padid, output = ET.tostring(doc, method="html", encoding="unicode")
scripts=args.script, await f.write(output)
links=links, except TypeError:
) ver["message"] = html["message"]
async with await trio.open_file(ver["path"], "w") as f:
output = ET.tostring(doc, method="html", encoding="unicode")
await f.write(output)
# output meta # output meta
if args.all or args.meta: if args.all or args.meta:

Loading…
Cancel
Save