Browse Source

Run formatter with make

main
Luke Murphy 3 years ago
parent
commit
e5077105b8
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 2
      etherpump/api/__init__.py
  2. 45
      etherpump/commands/pull.py

2
etherpump/api/__init__.py

@ -11,7 +11,7 @@ from etherpump.commands.gethtml import main as gethtml # noqa
from etherpump.commands.gettext import main as gettext # noqa from etherpump.commands.gettext import main as gettext # noqa
from etherpump.commands.index import main as index # noqa from etherpump.commands.index import main as index # noqa
from etherpump.commands.init import main # noqa from etherpump.commands.init import main # noqa
from etherpump.commands.init import main as init # noqa from etherpump.commands.init import main as init
from etherpump.commands.list import main as list # noqa from etherpump.commands.list import main as list # noqa
from etherpump.commands.listauthors import main as listauthors # noqa from etherpump.commands.listauthors import main as listauthors # noqa
from etherpump.commands.publication import main as publication # noqa from etherpump.commands.publication import main as publication # noqa

45
etherpump/commands/pull.py

@ -373,19 +373,22 @@ async def handle_pad(args, padid, data, info, session):
# once the content is settled, compute a hash # once the content is settled, compute a hash
# and link it in the metadata! # and link it in the metadata!
# include magic words # include magic words
if args.magicwords: if args.magicwords:
########################################## ##########################################
## INCLUDE __XXX__ MAGIC WORDS ## INCLUDE __XXX__ MAGIC WORDS
########################################## ##########################################
pattern = r'__[a-zA-Z0-9]+?__' pattern = r"__[a-zA-Z0-9]+?__"
magic_words = re.findall(pattern, text) magic_words = re.findall(pattern, text)
magic_words = list(set(magic_words)) magic_words = list(set(magic_words))
if magic_words: if magic_words:
meta["magicwords"] = magic_words meta["magicwords"] = magic_words
print('FOUND MAGIC WORD(s): {} in {}'.format(magic_words, padid)) print(
"FOUND MAGIC WORD(s): {} in {}".format(
magic_words, padid
)
)
links = [] links = []
if args.css: if args.css:
@ -470,7 +473,15 @@ async def handle_pad(args, padid, data, info, session):
# mb: line causing the error of not writing the correct HTML content to the correct HTML file: # mb: line causing the error of not writing the correct HTML content to the correct HTML file:
# url = info["localapiurl"] + "getHTML?" + urlencode(data) # url = info["localapiurl"] + "getHTML?" + urlencode(data)
# mb: warning, HACK! Catching the error by writing the API request url manually ... # mb: warning, HACK! Catching the error by writing the API request url manually ...
url = info["localapiurl"] + "getHTML?" + "padID=" + padid + "&" + 'apikey=' + data["apikey"] url = (
info["localapiurl"]
+ "getHTML?"
+ "padID="
+ padid
+ "&"
+ "apikey="
+ data["apikey"]
)
# print(url) # print(url)
html = await agetjson(session, url) html = await agetjson(session, url)
ver = {"type": "html"} ver = {"type": "html"}
@ -487,7 +498,11 @@ async def handle_pad(args, padid, data, info, session):
html, treebuilder="etree", namespaceHTMLElements=False html, treebuilder="etree", namespaceHTMLElements=False
) )
html5tidy( html5tidy(
doc, indent=True, title=padid, scripts=args.script, links=links, doc,
indent=True,
title=padid,
scripts=args.script,
links=links,
) )
async with await trio.open_file(ver["path"], "w") as f: async with await trio.open_file(ver["path"], "w") as f:
output = ET.tostring(doc, method="html", encoding="unicode") output = ET.tostring(doc, method="html", encoding="unicode")
@ -498,7 +513,15 @@ async def handle_pad(args, padid, data, info, session):
# print("PANIC: {}".format(exception)) # print("PANIC: {}".format(exception))
if args.all or args.magicwords: if args.all or args.magicwords:
url = info["localapiurl"] + "getHTML?" + "padID=" + padid + "&" + 'apikey=' + data["apikey"] url = (
info["localapiurl"]
+ "getHTML?"
+ "padID="
+ padid
+ "&"
+ "apikey="
+ data["apikey"]
)
# print(url) # print(url)
html = await agetjson(session, url) html = await agetjson(session, url)
ver = {"type": "magicwords"} ver = {"type": "magicwords"}
@ -512,7 +535,9 @@ async def handle_pad(args, padid, data, info, session):
ver["path"] = p + ".magicwords.html" ver["path"] = p + ".magicwords.html"
ver["url"] = quote(ver["path"]) ver["url"] = quote(ver["path"])
for magic_word in magic_words: for magic_word in magic_words:
replace_word = "<span class='highlight'>"+magic_word+"</span>" replace_word = (
"<span class='highlight'>" + magic_word + "</span>"
)
if magic_word in html: if magic_word in html:
html = html.replace(magic_word, replace_word) html = html.replace(magic_word, replace_word)
doc = html5lib.parse( doc = html5lib.parse(
@ -520,7 +545,11 @@ async def handle_pad(args, padid, data, info, session):
) )
# INSERT MAGIC WORDS HIGHLIGHTING STUFF HERE!!! # INSERT MAGIC WORDS HIGHLIGHTING STUFF HERE!!!
html5tidy( html5tidy(
doc, indent=True, title=padid, scripts=args.script, links=links, doc,
indent=True,
title=padid,
scripts=args.script,
links=links,
) )
async with await trio.open_file(ver["path"], "w") as f: async with await trio.open_file(ver["path"], "w") as f:
output = ET.tostring(doc, method="html", encoding="unicode") output = ET.tostring(doc, method="html", encoding="unicode")

Loading…
Cancel
Save