mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Raise IconsError instead of IndexError (fixes infinite looping)
This commit is contained in:
parent
f08e5176c3
commit
ca7f009e74
1 changed files with 8 additions and 1 deletions
|
@ -306,6 +306,8 @@ class TrackerIcons(Component):
|
||||||
:returns: a Deferred which fires with the downloaded icon's filename
|
:returns: a Deferred which fires with the downloaded icon's filename
|
||||||
:rtype: Deferred
|
:rtype: Deferred
|
||||||
"""
|
"""
|
||||||
|
if len(icons) == 0:
|
||||||
|
raise NoIconsError, "empty icons list"
|
||||||
(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)
|
||||||
|
@ -354,7 +356,7 @@ class TrackerIcons(Component):
|
||||||
callbackArgs=(host,), errbackArgs=(host,))
|
callbackArgs=(host,), errbackArgs=(host,))
|
||||||
elif f.check(error.NoResource, error.ForbiddenResource) and icons:
|
elif f.check(error.NoResource, error.ForbiddenResource) and icons:
|
||||||
d = self.download_icon(icons, host)
|
d = self.download_icon(icons, host)
|
||||||
elif f.check(IndexError, HTMLParseError):
|
elif f.check(NoIconsError, HTMLParseError):
|
||||||
# No icons, try favicon.ico as an act of desperation
|
# No icons, try favicon.ico as an act of desperation
|
||||||
d = self.download_icon([(urljoin(self.host_to_url(host), "favicon.ico"), extension_to_mimetype("ico"))], host)
|
d = self.download_icon([(urljoin(self.host_to_url(host), "favicon.ico"), extension_to_mimetype("ico"))], host)
|
||||||
d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail,
|
d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail,
|
||||||
|
@ -536,3 +538,8 @@ def extension_to_mimetype(extension):
|
||||||
:raises KeyError: if given an invalid filename extension
|
:raises KeyError: if given an invalid filename extension
|
||||||
"""
|
"""
|
||||||
return MIME_MAP[extension.lower()]
|
return MIME_MAP[extension.lower()]
|
||||||
|
|
||||||
|
################################## EXCEPTIONS #################################
|
||||||
|
|
||||||
|
class NoIconsError(Exception):
|
||||||
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue