diff options
author | Raphael Geissert <geissert@debian.org> | 2010-01-11 07:49:35 +0000 |
---|---|---|
committer | Raphael Geissert <geissert@debian.org> | 2010-01-11 07:49:35 +0000 |
commit | f214c5f0b1f123267ba43858a3641208b412a5ff (patch) | |
tree | e412e9afe8a950f7e7d3b4c60d5c45ba7d4cfa97 /lib/python/web_support.py | |
parent | f6ad690875aba0458605a87e5e3dcbf67d362357 (diff) |
"linkify" links in notes
it should later be extended to turn CVE- strings into links too
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@13784 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'lib/python/web_support.py')
-rw-r--r-- | lib/python/web_support.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/python/web_support.py b/lib/python/web_support.py index 0e68318c7b..ae2d852dc6 100644 --- a/lib/python/web_support.py +++ b/lib/python/web_support.py @@ -336,6 +336,11 @@ class Tag(HTMLBase): def __repr__(self): return "<websupport.Tag instance, name=%s>" % `self.__name` + def toString(self): + r = cStringIO.StringIO() + self.flatten(r.write) + return r.getvalue() + def tag(__name, __contents, **__attribs): """Creates a new tag object. @@ -402,6 +407,17 @@ def INPUT(*__contents, **__attribs): def LI(*__contents, **__attribs): return Tag('li', __contents, __attribs) +def _linkify(match): + extra = match.group(2) + if extra is None: + extra = "" + link = match.group(1) + return "%s%s" % (A(link).toString(), extra) + +def linkify(contents): + contents = re.sub(r'(httpS?://[\w.-]+/.*?)([,\s]|$)', _linkify, contents) + return contents + def make_table(contents, caption=None, replacement=None, introduction=None): rows = [] for row in contents: @@ -856,5 +872,9 @@ Location: http://localhost.localdomain/cgi-bin/test.cgi/123 assert pr.get("/a//xyz/123") == ("/a/**", ("xyz", "123")) assert pr.get("/abc") == ("/abc", ()) + assert linkify('foo bar moo') == 'foo bar moo' + assert linkify('http://domain.tld/foo.cgi?bar=moo&test') == A('http://domain.tld/foo.cgi?bar=moo&test').toString() + assert linkify('as seen in http://foo.tld/bar/moo.txt, ...') == 'as seen in %s, ...' % A('http://foo.tld/bar/moo.txt').toString() + if __name__ == "__main__": __test() |