From 993a0f71afb89af79baf5db3e6f51f94dad9a740 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Thu, 12 Jan 2017 10:09:02 +0000 Subject: [PATCH] [UI] Fix usage of 'with Image.open' in tracker_icons * Revert changes made to fix 'too many files open' as Image.open does not return a file descriptor and generated the following error: exceptions.AttributeError: 'NoneType' object has no attribute 'startswith' --- deluge/ui/tracker_icons.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index e6694e73c..1875b4c7e 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -358,8 +358,7 @@ class TrackerIcons(Component): if PIL_INSTALLED: try: - with Image.open(icon_name): - pass + Image.open(icon_name) except IOError as ex: raise InvalidIconError(ex) else: @@ -380,8 +379,7 @@ class TrackerIcons(Component): :rtype: TrackerIcon """ log.debug('Successfully downloaded from %s: %s', host, icon_name) - icon = TrackerIcon(icon_name) - return icon + return TrackerIcon(icon_name) def on_download_icon_fail(self, f, host, icons=None): """ @@ -436,14 +434,14 @@ class TrackerIcons(Component): """ if icon: filename = icon.get_filename() - with Image.open(filename) as img: - if img.size > (16, 16): - new_filename = filename.rpartition('.')[0] + '.png' - img = img.resize((16, 16), Image.ANTIALIAS) - img.save(new_filename) - if new_filename != filename: - os.remove(filename) - icon = TrackerIcon(new_filename) + img = Image.open(filename) + if img.size > (16, 16): + new_filename = filename.rpartition('.')[0] + '.png' + img = img.resize((16, 16), Image.ANTIALIAS) + img.save(new_filename) + if new_filename != filename: + os.remove(filename) + icon = TrackerIcon(new_filename) return icon def store_icon(self, icon, host):