From d6c8b130411e3126426da58e2d8f10311a4edae2 Mon Sep 17 00:00:00 2001 From: John Garland Date: Wed, 5 May 2010 03:19:54 +1000 Subject: [PATCH] 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(-) create mode 100644 tests/openbt.png diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index 5a6aa3b68..b079738f3 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 0000000000000000000000000000000000000000..270d617aec02a1f51da388ad978afe47022a11d6 GIT binary patch literal 673 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7BuiW)N`mv#O3D+9QW+dm z@{>{(JaZG%Q-e|yQz{EjrrIztFgbg=IEGZ*niK4sEgUFf`#yD&-?Eb&nx5So9W@@g z-Qj+8=>LO73KJK_MhG07${p)+fWRfcb5R{$ zlQHkl+?Z%0a)dko!QJwEmBr_Gh8un|&So(BvHwPxf=gdcbbBuIMv0bHOdl;Q?0Hm~ ze(9YkWXNZj=)<&Xl}5p?bw!_8gqHg!2K?^)_dB#=tGqy!)Pu(gG5lAuocx|nu&8D; znxB4$o#)#1Sd&STm+Ssb`gZ7dYS8br&R4%wBzHRPxMZ0Xzu)m)n(ZOW^Kk*rr)Olm znEdQq&ctu+Un^Q)WwpIJ$rIT>uV>DC5&b~t^D_;W_08&iW3n@Te{Vw+clgTEr?))z z{a@;J?1cpZ8>}ma%7BxN^a{yo8_eOl+M~*h;_MxzK&> zE!Uf;?ar284^=8m$78D}i`{VSK{ zP3<3+{L@Dgl9`*cOi!^(>|bNgaw?9~XtryQ^_j@ZQ&l%MXq}$$G2+6$vyW^heJ+kk z>oV1H=;?1)nPmH6?E*jb#pgs7Z}#2|k_@`c@UC=XNOM$e<3ZyGUu9%=ZST0ZJG3Nz zZ=zD}ZS@Qz5B^{GHaRtZ;}0_M`S;1`;LpZ{6-#n{s!G%xmdKI;Vst01?kM6aWAK literal 0 HcmV?d00001 diff --git a/tests/test_tracker_icons.py b/tests/test_tracker_icons.py index 702e648fe..5ff7241e6 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