[Secure-testing-commits] r13784 - bin lib/python

Raphael Geissert geissert at alioth.debian.org
Mon Jan 11 07:49:36 UTC 2010


Author: geissert
Date: 2010-01-11 07:49:35 +0000 (Mon, 11 Jan 2010)
New Revision: 13784

Modified:
   bin/tracker_service.py
   lib/python/web_support.py
Log:
"linkify" links in notes
it should later be extended to turn CVE- strings into links too


Modified: bin/tracker_service.py
===================================================================
--- bin/tracker_service.py	2010-01-11 05:53:28 UTC (rev 13783)
+++ bin/tracker_service.py	2010-01-11 07:49:35 UTC (rev 13784)
@@ -447,7 +447,7 @@
             def gen_comments():
                 for (t, c) in bug.comments:
                     yield c
-            page.append(make_pre(gen_comments()))
+            page.append(make_pre(linkify(gen_comments())))
 
         return self.create_page(url, bug.name, page)
 

Modified: lib/python/web_support.py
===================================================================
--- lib/python/web_support.py	2010-01-11 05:53:28 UTC (rev 13783)
+++ lib/python/web_support.py	2010-01-11 07:49:35 UTC (rev 13784)
@@ -336,6 +336,11 @@
     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 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 @@
     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()




More information about the Secure-testing-commits mailing list