Handle trackers with incorrect / missing icon mimetypes
This commit is contained in:
parent
ba03356151
commit
d6c8b13041
@ -424,8 +424,15 @@ class FaviconParser(HTMLParser):
|
|||||||
href = value
|
href = value
|
||||||
elif attr == "type":
|
elif attr == "type":
|
||||||
type = value
|
type = value
|
||||||
if href and type:
|
if href:
|
||||||
self.icons.append((href, type))
|
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):
|
def handle_endtag(self, tag):
|
||||||
if tag == "head":
|
if tag == "head":
|
||||||
|
|||||||
BIN
tests/openbt.png
Normal file
BIN
tests/openbt.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 673 B |
@ -12,7 +12,7 @@ common.set_tmp_config_dir()
|
|||||||
icons = TrackerIcons()
|
icons = TrackerIcons()
|
||||||
|
|
||||||
class TrackerIconsTestCase(unittest.TestCase):
|
class TrackerIconsTestCase(unittest.TestCase):
|
||||||
def test_get_png(self):
|
def test_get_deluge_png(self):
|
||||||
# Deluge has a png favicon link
|
# Deluge has a png favicon link
|
||||||
icon = TrackerIcon("../deluge.png")
|
icon = TrackerIcon("../deluge.png")
|
||||||
d = icons.get("deluge-torrent.org")
|
d = icons.get("deluge-torrent.org")
|
||||||
@ -20,7 +20,7 @@ class TrackerIconsTestCase(unittest.TestCase):
|
|||||||
d.addCallback(self.assertEquals, icon)
|
d.addCallback(self.assertEquals, icon)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_get_ico(self):
|
def test_get_google_ico(self):
|
||||||
# Google doesn't have any icon links
|
# Google doesn't have any icon links
|
||||||
# So instead we'll grab its favicon.ico
|
# So instead we'll grab its favicon.ico
|
||||||
icon = TrackerIcon("../google.ico")
|
icon = TrackerIcon("../google.ico")
|
||||||
@ -29,7 +29,7 @@ class TrackerIconsTestCase(unittest.TestCase):
|
|||||||
d.addCallback(self.assertEquals, icon)
|
d.addCallback(self.assertEquals, icon)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_get_ico_with_redirect(self):
|
def test_get_google_ico_with_redirect(self):
|
||||||
# google.com redirects to www.google.com
|
# google.com redirects to www.google.com
|
||||||
icon = TrackerIcon("../google.ico")
|
icon = TrackerIcon("../google.ico")
|
||||||
d = icons.get("google.com")
|
d = icons.get("google.com")
|
||||||
@ -44,3 +44,11 @@ class TrackerIconsTestCase(unittest.TestCase):
|
|||||||
d.addCallback(self.assertNotIdentical, None)
|
d.addCallback(self.assertNotIdentical, None)
|
||||||
d.addCallback(self.assertEquals, icon)
|
d.addCallback(self.assertEquals, icon)
|
||||||
return d
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user