Module: deluge
Branch: master
Commit: e4ef17975c4d670099e50da7c232b427ef0c3c05

Author: Damien Churchill <[email protected]>
Date:   Mon May  3 21:28:16 2010 +0100

stop parsing the html page once the parser has left the <head> of the page

---

 deluge/ui/tracker_icons.py  |    7 +++++++
 tests/test_tracker_icons.py |    8 ++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py
index eb6f00c..9c8a368 100644
--- a/deluge/ui/tracker_icons.py
+++ b/deluge/ui/tracker_icons.py
@@ -256,6 +256,8 @@ class TrackerIcons(Component):
         parser = FaviconParser()
         for line in f:
             parser.feed(line)
+            if parser.left_head:
+                break
         parser.close()
         f.close()
         os.remove(page)
@@ -410,6 +412,7 @@ class FaviconParser(HTMLParser):
     """
     def __init__(self):
         self.icons = []
+        self.left_head = False
         HTMLParser.__init__(self)
 
     def handle_starttag(self, tag, attrs):
@@ -424,6 +427,10 @@ class FaviconParser(HTMLParser):
             if href and type:
                 self.icons.append((href, type))
 
+    def handle_endtag(self, tag):
+        if tag == "head":
+            self.left_head = True
+
     def get_icons(self):
         """
         Returns a list of favicons extracted from the HTML page
diff --git a/tests/test_tracker_icons.py b/tests/test_tracker_icons.py
index 9a68dc9..702e648 100644
--- a/tests/test_tracker_icons.py
+++ b/tests/test_tracker_icons.py
@@ -36,3 +36,11 @@ class TrackerIconsTestCase(unittest.TestCase):
         d.addCallback(self.assertNotIdentical, None)
         d.addCallback(self.assertEquals, icon)
         return d
+
+    def test_get_ubuntu_ico(self):
+        # ubuntu.com has inline css which causes HTMLParser issues
+        icon = TrackerIcon("../ubuntu.png")
+        d = icons.get("www.ubuntu.com")
+        d.addCallback(self.assertNotIdentical, None)
+        d.addCallback(self.assertEquals, icon)
+        return d

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to