mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 12:04:10 +00:00
Only use an icon if it passes some sanity checks
This commit is contained in:
parent
722a5cd9e1
commit
22a1448372
@ -315,10 +315,34 @@ class TrackerIcons(Component):
|
|||||||
(url, mimetype) = icons.pop(0)
|
(url, mimetype) = icons.pop(0)
|
||||||
d = download_file(url, os.path.join(self.dir, host_to_icon_name(host, mimetype)),
|
d = download_file(url, os.path.join(self.dir, host_to_icon_name(host, mimetype)),
|
||||||
force_filename=True)
|
force_filename=True)
|
||||||
|
d.addCallback(self.check_icon_is_valid)
|
||||||
if icons:
|
if icons:
|
||||||
d.addErrback(self.on_download_icon_fail, host, icons)
|
d.addErrback(self.on_download_icon_fail, host, icons)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@proxy(threads.deferToThread)
|
||||||
|
def check_icon_is_valid(self, icon_name):
|
||||||
|
"""
|
||||||
|
Performs a sanity check on icon_name
|
||||||
|
|
||||||
|
:param icon_name: the name of the icon to check
|
||||||
|
:type icon_name: string
|
||||||
|
:returns: the name of the validated icon
|
||||||
|
:rtype: string
|
||||||
|
:raises: InvalidIconError
|
||||||
|
"""
|
||||||
|
|
||||||
|
if PIL_INSTALLED:
|
||||||
|
try:
|
||||||
|
Image.open(icon_name)
|
||||||
|
except IOError, e:
|
||||||
|
raise InvalidIconError(e)
|
||||||
|
else:
|
||||||
|
if os.stat(icon_name).st_size == 0L:
|
||||||
|
raise InvalidIconError, "empty icon"
|
||||||
|
|
||||||
|
return icon_name
|
||||||
|
|
||||||
def on_download_icon_complete(self, icon_name, host):
|
def on_download_icon_complete(self, icon_name, host):
|
||||||
"""
|
"""
|
||||||
Runs any download cleanup functions
|
Runs any download cleanup functions
|
||||||
@ -547,3 +571,6 @@ def extension_to_mimetype(extension):
|
|||||||
|
|
||||||
class NoIconsError(Exception):
|
class NoIconsError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class InvalidIconError(Exception):
|
||||||
|
pass
|
||||||
|
@ -63,5 +63,5 @@ class TrackerIconsTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_empty_string_tracker(self):
|
def test_get_empty_string_tracker(self):
|
||||||
d = icons.get("")
|
d = icons.get("")
|
||||||
d.addCallback(self.assertEquals, None)
|
d.addCallback(self.assertIdentical, None)
|
||||||
return d
|
return d
|
||||||
|
Loading…
x
Reference in New Issue
Block a user