Mercurial > kallithea
comparison rhodecode/lib/helpers.py @ 3399:5ff79fad209c beta
don't use double literal() calls on urlify functions
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 25 Feb 2013 20:48:52 +0100 |
parents | 1ca82b6a6349 |
children | a9adca4ba3c9 |
comparison
equal
deleted
inserted
replaced
3398:1ca82b6a6349 | 3399:5ff79fad209c |
---|---|
975 cgen('d', a_v, d_v), d_p, d_v | 975 cgen('d', a_v, d_v), d_p, d_v |
976 ) | 976 ) |
977 return literal('<div style="width:%spx">%s%s</div>' % (width, d_a, d_d)) | 977 return literal('<div style="width:%spx">%s%s</div>' % (width, d_a, d_d)) |
978 | 978 |
979 | 979 |
980 def urlify_text(text_): | 980 def urlify_text(text_, safe=True): |
981 """ | 981 """ |
982 Extrac urls from text and make html links out of them | 982 Extrac urls from text and make html links out of them |
983 | 983 |
984 :param text_: | 984 :param text_: |
985 """ | 985 """ |
988 '''|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)''') | 988 '''|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)''') |
989 | 989 |
990 def url_func(match_obj): | 990 def url_func(match_obj): |
991 url_full = match_obj.groups()[0] | 991 url_full = match_obj.groups()[0] |
992 return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full}) | 992 return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full}) |
993 | 993 _newtext = url_pat.sub(url_func, text_) |
994 return literal(url_pat.sub(url_func, text_)) | 994 if safe: |
995 return literal(_newtext) | |
996 return _newtext | |
995 | 997 |
996 | 998 |
997 def urlify_changesets(text_, repository): | 999 def urlify_changesets(text_, repository): |
998 """ | 1000 """ |
999 Extract revision ids from changeset and make link from them | 1001 Extract revision ids from changeset and make link from them |
1060 | 1062 |
1061 # urlify changesets - extrac revisions and make link out of them | 1063 # urlify changesets - extrac revisions and make link out of them |
1062 newtext = urlify_changesets(escaper(text_), repository) | 1064 newtext = urlify_changesets(escaper(text_), repository) |
1063 | 1065 |
1064 # extract http/https links and make them real urls | 1066 # extract http/https links and make them real urls |
1065 newtext = urlify_text(newtext) | 1067 newtext = urlify_text(newtext, safe=False) |
1066 | 1068 |
1067 try: | 1069 try: |
1068 from rhodecode import CONFIG | 1070 from rhodecode import CONFIG |
1069 conf = CONFIG | 1071 conf = CONFIG |
1070 | 1072 |