Handle trackers with incorrect / missing icon mimetypes

This commit is contained in:
John Garland 2010-05-05 03:19:54 +10:00
parent ba03356151
commit d6c8b13041
3 changed files with 20 additions and 5 deletions

View File

@ -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":

BIN
tests/openbt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

View File

@ -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