Mercurial > kallithea
changeset 4745:4363158fb68e
helpers: refactor urlify_commit, extract urlify_issues function
A slight improvement of code, but also prepares for other wip changes.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Jan 2015 00:54:36 +0100 |
parents | 6678b977f859 |
children | cc1ab5ef6686 |
files | kallithea/lib/helpers.py |
diffstat | 1 files changed, 20 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Tue Jan 06 00:54:36 2015 +0100 +++ b/kallithea/lib/helpers.py Tue Jan 06 00:54:36 2015 +0100 @@ -1283,6 +1283,16 @@ return re.sub(r'(?:^|(?<=[\s(),]))([0-9a-fA-F]{12,40})(?=$|\s|[.,:()])', url_func, text_) +def linkify_others(t, l): + urls = re.compile(r'(\<a.*?\<\/a\>)',) + links = [] + for e in urls.split(t): + if not urls.match(e): + links.append('<a class="message-link" href="%s">%s</a>' % (l, e)) + else: + links.append(e) + + return ''.join(links) def urlify_commit(text_, repository, link_=None): """ @@ -1294,30 +1304,22 @@ :param repository: :param link_: changeset link """ - import traceback - from pylons import url # doh, we need to re-import url to mock it later - def escaper(string): return string.replace('<', '<').replace('>', '>') - def linkify_others(t, l): - urls = re.compile(r'(\<a.*?\<\/a\>)',) - links = [] - for e in urls.split(t): - if not urls.match(e): - links.append('<a class="message-link" href="%s">%s</a>' % (l, e)) - else: - links.append(e) - - return ''.join(links) - # urlify changesets - extract revisions and make link out of them newtext = urlify_changesets(escaper(text_), repository) # extract http/https links and make them real urls newtext = urlify_text(newtext, safe=False) + newtext = urlify_issues(newtext, repository, link_) + + return literal(newtext) + +def urlify_issues(newtext, repository, link_=None): try: + import traceback from kallithea import CONFIG conf = CONFIG @@ -1329,8 +1331,9 @@ and 'issue_prefix%s' % x.group(1) in conf ] - log.debug('found issue server suffixes `%s` during valuation of: %s' - % (','.join(valid_indices), newtext)) + if valid_indices: + log.debug('found issue server suffixes `%s` during valuation of: %s' + % (','.join(valid_indices), newtext)) for pattern_index in valid_indices: ISSUE_PATTERN = conf.get('issue_pat%s' % pattern_index) @@ -1377,8 +1380,7 @@ except Exception: log.error(traceback.format_exc()) pass - - return literal(newtext) + return newtext def rst(source):