changeset 8788:0383ed91d4ed

lib: move url_re to webutils
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 09 Nov 2020 16:42:43 +0100
parents f375751fe3fa
children 71a37439dcee
files kallithea/lib/helpers.py kallithea/lib/markup_renderer.py kallithea/lib/webutils.py
diffstat 3 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/helpers.py	Mon Nov 09 16:42:43 2020 +0100
+++ b/kallithea/lib/helpers.py	Mon Nov 09 16:42:43 2020 +0100
@@ -36,7 +36,6 @@
 #==============================================================================
 from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel
 from kallithea.lib.diffs import BIN_FILENODE, CHMOD_FILENODE, DEL_FILENODE, MOD_FILENODE, NEW_FILENODE, RENAMED_FILENODE
-from kallithea.lib.markup_renderer import url_re
 from kallithea.lib.pygmentsutils import get_custom_lexer
 from kallithea.lib.utils2 import (AttributeDict, age, asbool, credentials_filter, fmt_date, link_to_ref, safe_bytes, safe_int, safe_str, shorter,
                                   time_to_datetime)
@@ -48,7 +47,7 @@
 from kallithea.lib.vcs.utils import author_email, author_name
 from kallithea.lib.webutils import (HTML, MENTIONS_REGEX, Option, canonical_url, checkbox, chop_at, end_form, escape, form, format_byte_size, hidden,
                                     html_escape, js, jshtml, link_to, literal, password, pop_flash_messages, radio, reset, safeid, select,
-                                    session_csrf_secret_name, session_csrf_secret_token, submit, text, textarea, truncate, url, wrap_paragraphs)
+                                    session_csrf_secret_name, session_csrf_secret_token, submit, text, textarea, truncate, url, url_re, wrap_paragraphs)
 from kallithea.model import db
 from kallithea.model.changeset_status import ChangesetStatusModel
 
--- a/kallithea/lib/markup_renderer.py	Mon Nov 09 16:42:43 2020 +0100
+++ b/kallithea/lib/markup_renderer.py	Mon Nov 09 16:42:43 2020 +0100
@@ -42,10 +42,6 @@
 log = logging.getLogger(__name__)
 
 
-url_re = re.compile(r'''\bhttps?://(?:[\da-zA-Z0-9@:.-]+)'''
-                    r'''(?:[/a-zA-Z0-9_=@#~&+%.,:;?!*()-]*[/a-zA-Z0-9_=@#~])?''')
-
-
 class MarkupRenderer(object):
     RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw']
 
@@ -163,7 +159,7 @@
         def url_func(match_obj):
             url_full = match_obj.group(0)
             return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full})
-        source = url_re.sub(url_func, source)
+        source = webutils.url_re.sub(url_func, source)
         return '<br />' + source.replace("\n", '<br />')
 
     @classmethod
--- a/kallithea/lib/webutils.py	Mon Nov 09 16:42:43 2020 +0100
+++ b/kallithea/lib/webutils.py	Mon Nov 09 16:42:43 2020 +0100
@@ -309,6 +309,10 @@
     return js(escape(val))
 
 
+url_re = re.compile(r'''\bhttps?://(?:[\da-zA-Z0-9@:.-]+)'''
+                    r'''(?:[/a-zA-Z0-9_=@#~&+%.,:;?!*()-]*[/a-zA-Z0-9_=@#~])?''')
+
+
 # Must match regexp in kallithea/public/js/base.js MentionsAutoComplete()
 # Check char before @ - it must not look like we are in an email addresses.
 # Matching is greedy so we don't have to look beyond the end.