diff sat_frontends/tools/strings.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children a754523fc0f6
line wrap: on
line diff
--- a/sat_frontends/tools/strings.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat_frontends/tools/strings.py	Wed Jun 27 20:14:46 2018 +0200
@@ -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 @@
     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 @@
         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 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 @@
     for url, new_url in subs:
         xhtml = xhtml.replace(url, new_url)
     return xhtml
-