Module: deluge
Branch: master
Commit: d6c8b130411e3126426da58e2d8f10311a4edae2

Author: John Garland <[email protected]>
Date:   Wed May  5 03:19:54 2010 +1000

Handle trackers with incorrect / missing icon mimetypes

---

 deluge/ui/tracker_icons.py  |   11 +++++++++--
 tests/openbt.png            |  Bin 0 -> 673 bytes
 tests/test_tracker_icons.py |   14 +++++++++++---
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py
index 5a6aa3b..b079738 100644
--- a/deluge/ui/tracker_icons.py
+++ b/deluge/ui/tracker_icons.py
@@ -424,8 +424,15 @@ class FaviconParser(HTMLParser):
                     href = value
                 elif attr == "type":
                     type = value
-            if href and type:
-                self.icons.append((href, type))
+            if href:
+                try:
+                    mimetype = extension_to_mimetype(href.rpartition('.')[2])
+                except KeyError:
+                    pass
+                else:
+                    type = mimetype
+                if type:
+                    self.icons.append((href, type))
 
     def handle_endtag(self, tag):
         if tag == "head":
diff --git a/tests/openbt.png b/tests/openbt.png
new file mode 100644
index 0000000..270d617
Binary files /dev/null and b/tests/openbt.png differ
diff --git a/tests/test_tracker_icons.py b/tests/test_tracker_icons.py
index 702e648..5ff7241 100644
--- a/tests/test_tracker_icons.py
+++ b/tests/test_tracker_icons.py
@@ -12,7 +12,7 @@ common.set_tmp_config_dir()
 icons = TrackerIcons()
 
 class TrackerIconsTestCase(unittest.TestCase):
-    def test_get_png(self):
+    def test_get_deluge_png(self):
         # Deluge has a png favicon link
         icon = TrackerIcon("../deluge.png")
         d = icons.get("deluge-torrent.org")
@@ -20,7 +20,7 @@ class TrackerIconsTestCase(unittest.TestCase):
         d.addCallback(self.assertEquals, icon)
         return d
 
-    def test_get_ico(self):
+    def test_get_google_ico(self):
         # Google doesn't have any icon links
         # So instead we'll grab its favicon.ico
         icon = TrackerIcon("../google.ico")
@@ -29,7 +29,7 @@ class TrackerIconsTestCase(unittest.TestCase):
         d.addCallback(self.assertEquals, icon)
         return d
 
-    def test_get_ico_with_redirect(self):
+    def test_get_google_ico_with_redirect(self):
         # google.com redirects to www.google.com
         icon = TrackerIcon("../google.ico")
         d = icons.get("google.com")
@@ -44,3 +44,11 @@ class TrackerIconsTestCase(unittest.TestCase):
         d.addCallback(self.assertNotIdentical, None)
         d.addCallback(self.assertEquals, icon)
         return d
+
+    def test_get_openbt_png(self):
+        # openbittorrent.com has an incorrect type (image/gif)
+        icon = TrackerIcon("../openbt.png")
+        d = icons.get("openbittorrent.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