Torrent provider cleanup

This commit is contained in:
Ruud
2012-07-05 22:13:29 +02:00
parent 8d1e343f7b
commit 566c4830de
6 changed files with 221 additions and 254 deletions
+6 -14
View File
@@ -95,7 +95,7 @@ class Plugin(object):
return False
# http request
def urlopen(self, url, timeout = 30, params = {}, headers = {}, multipart = False, show_error = True):
def urlopen(self, url, timeout = 30, params = {}, headers = {}, opener = None, multipart = False, show_error = True):
# Fill in some headers
if not headers.get('Referer'):
@@ -130,7 +130,10 @@ class Plugin(object):
data = tryUrlencode(params) if len(params) > 0 else None
request = urllib2.Request(url, data, headers)
data = urllib2.urlopen(request, timeout = timeout).read()
if opener:
data = opener.open(request, timeout = timeout).read()
else:
data = urllib2.urlopen(request, timeout = timeout).read()
self.http_failed_request[host] = 0
except IOError:
@@ -215,18 +218,7 @@ class Plugin(object):
cache_timeout = kwargs.get('cache_timeout')
del kwargs['cache_timeout']
opener = None
if kwargs.get('opener'):
opener = kwargs.get('opener')
del kwargs['opener']
if opener:
log.info('Opening url: %s', url)
f = opener.open(url)
data = f.read()
f.close()
else:
data = self.urlopen(url, **kwargs)
data = self.urlopen(url, **kwargs)
if data:
self.setCache(cache_key, data, timeout = cache_timeout)