code style reformatting using black

This commit is contained in:
Goffi 2018-06-27 20:14:46 +02:00
commit 744cb0c503

View file

@ -20,7 +20,9 @@
import re
# Regexp from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
RE_URL = re.compile(r"""(?i)\b((?:[a-z]{3,}://|(www|ftp)\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/|mailto:|xmpp:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?]))""")
RE_URL = re.compile(
r"""(?i)\b((?:[a-z]{3,}://|(www|ftp)\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/|mailto:|xmpp:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?]))"""
)
# TODO: merge this class with an other module or at least rename it (strings is not a good name)
@ -36,7 +38,7 @@ def getURLParams(url):
dict_ = {}
if "/" in url:
# keep the part after the last "/"
url = url[url.rindex("/") + 1:]
url = url[url.rindex("/") + 1 :]
if url.startswith("?"):
# remove the first "?"
url = url[1:]
@ -60,8 +62,9 @@ def addURLToText(string, new_target=True):
url = match.group(0)
if not re.match(r"""[a-z]{3,}://|mailto:|xmpp:""", url):
url = "http://" + url
target = ' target="_blank"' if new_target else ''
target = ' target="_blank"' if new_target else ""
return '<a href="%s"%s class="url">%s</a>' % (url, target, match.group(0))
return RE_URL.sub(repl, string)
@ -74,6 +77,7 @@ def addURLToImage(string):
def repl(match):
url = match.group(1)
return '<a href="%s" target="_blank">%s</a>' % (url, match.group(0))
pattern = r"""<img[^>]* src="([^"]+)"[^>]*>"""
return re.sub(pattern, repl, string)
@ -96,4 +100,3 @@ def fixXHTMLLinks(xhtml):
for url, new_url in subs:
xhtml = xhtml.replace(url, new_url)
return xhtml