From 129c09c5a775ff7f673c611b6db14e3b499f26e9 Mon Sep 17 00:00:00 2001 From: John Garland Date: Sun, 16 Sep 2012 17:12:16 +1000 Subject: [PATCH] Don't use deprecated twisted imports (fixes #2164) Aliases have been removed in twisted 12.2.0. --- deluge/tests/test_httpdownloader.py | 6 +++++- deluge/ui/tracker_icons.py | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/deluge/tests/test_httpdownloader.py b/deluge/tests/test_httpdownloader.py index 6e9c677a0..a4a53fc13 100644 --- a/deluge/tests/test_httpdownloader.py +++ b/deluge/tests/test_httpdownloader.py @@ -5,7 +5,11 @@ from twisted.trial import unittest from twisted.internet import reactor from twisted.python.failure import Failure from twisted.web.http import FORBIDDEN, NOT_MODIFIED -from twisted.web.resource import Resource, ForbiddenResource +try: + from twisted.web.resource import Resource, ForbiddenResource +except ImportError: + # twisted 8 + from twisted.web.error import Resource, ForbiddenResource from twisted.web.server import Site from deluge.httpdownloader import download_file diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index 008783696..c475381f5 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -40,7 +40,12 @@ from urlparse import urljoin, urlparse from tempfile import mkstemp from twisted.internet import defer, threads -from twisted.web import error +from twisted.web.error import PageRedirect +try: + from twisted.web.resource import NoResource, ForbiddenResource +except ImportError: + # twisted 8 + from twisted.web.error import NoResource, ForbiddenResource from deluge.component import Component from deluge.configmanager import get_config_dir @@ -238,7 +243,7 @@ class TrackerIcons(Component): error_msg = f.getErrorMessage() log.debug("Error downloading page: %s", error_msg) d = f - if f.check(error.PageRedirect): + if f.check(PageRedirect): # Handle redirect errors location = urljoin(self.host_to_url(host), error_msg.split(" to ")[1]) self.redirects[host] = url_to_host(location) @@ -378,14 +383,14 @@ class TrackerIcons(Component): error_msg = f.getErrorMessage() log.debug("Error downloading icon: %s", error_msg) d = f - if f.check(error.PageRedirect): + if f.check(PageRedirect): # Handle redirect errors location = urljoin(self.host_to_url(host), error_msg.split(" to ")[1]) d = self.download_icon([(location, extension_to_mimetype(location.rpartition('.')[2]))] + icons, host) if not icons: d.addCallbacks(self.on_download_icon_complete, self.on_download_icon_fail, callbackArgs=(host,), errbackArgs=(host,)) - elif f.check(error.NoResource, error.ForbiddenResource) and icons: + elif f.check(NoResource, ForbiddenResource) and icons: d = self.download_icon(icons, host) elif f.check(NoIconsError, HTMLParseError): # No icons, try favicon.ico as an act of desperation