summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Garland <johnnybg+deluge@gmail.com>2010-07-17 17:11:19 +1000
committerJohn Garland <johnnybg+deluge@gmail.com>2010-07-17 17:13:15 +1000
commit1ce480ff2390bb5a60dd5e32ee012051dac81f0d (patch)
tree54461582f651fb8ef00849f845948ed4eb35d47a
parent007a9912d26e549197c24977d5678bb7d5c9df2e (diff)
downloaddeluge-1ce480ff2390bb5a60dd5e32ee012051dac81f0d.tar.gz
deluge-1ce480ff2390bb5a60dd5e32ee012051dac81f0d.tar.bz2
deluge-1ce480ff2390bb5a60dd5e32ee012051dac81f0d.zip
Only use an icon if it passes some sanity checks
-rw-r--r--deluge/ui/tracker_icons.py27
-rw-r--r--tests/test_tracker_icons.py2
2 files changed, 28 insertions, 1 deletions
diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py
index 298e21cc0..91a02e46e 100644
--- a/deluge/ui/tracker_icons.py
+++ b/deluge/ui/tracker_icons.py
@@ -315,10 +315,34 @@ class TrackerIcons(Component):
(url, mimetype) = icons.pop(0)
d = download_file(url, os.path.join(self.dir, host_to_icon_name(host, mimetype)),
force_filename=True)
+ d.addCallback(self.check_icon_is_valid)
if icons:
d.addErrback(self.on_download_icon_fail, host, icons)
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):
"""
Runs any download cleanup functions
@@ -547,3 +571,6 @@ def extension_to_mimetype(extension):
class NoIconsError(Exception):
pass
+
+class InvalidIconError(Exception):
+ pass
diff --git a/tests/test_tracker_icons.py b/tests/test_tracker_icons.py
index 9e69f2fae..61a5565b9 100644
--- a/tests/test_tracker_icons.py
+++ b/tests/test_tracker_icons.py
@@ -62,5 +62,5 @@ class TrackerIconsTestCase(unittest.TestCase):
def test_get_empty_string_tracker(self):
d = icons.get("")
- d.addCallback(self.assertEquals, None)
+ d.addCallback(self.assertIdentical, None)
return d