From f0daee669b35e4b3f625de45d5c2803aeeb7b9f8 Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 6 Jun 2014 10:53:08 +0200 Subject: [PATCH] Add opener to env --- couchpotato/core/plugins/base.py | 3 +-- couchpotato/environment.py | 3 +-- couchpotato/runner.py | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 5198b46..de6af55 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -40,7 +40,6 @@ class Plugin(object): http_time_between_calls = 0 http_failed_request = {} http_failed_disabled = {} - http_opener = requests.Session() def __new__(cls, *args, **kwargs): new_plugin = super(Plugin, cls).__new__(cls) @@ -184,7 +183,7 @@ class Plugin(object): headers['Connection'] = headers.get('Connection', 'keep-alive') headers['Cache-Control'] = headers.get('Cache-Control', 'max-age=0') - r = self.http_opener + r = Env.get('http_opener') # Don't try for failed requests if self.http_failed_disabled.get(host, 0) > 0: diff --git a/couchpotato/environment.py b/couchpotato/environment.py index 8c1ee17..658b744 100644 --- a/couchpotato/environment.py +++ b/couchpotato/environment.py @@ -24,8 +24,7 @@ class Env(object): _quiet = False _daemonized = False _desktop = None - _engine = None - _session = None + _http_opener = None ''' Data paths and directories ''' _app_dir = "" diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 060b7ad..b2b918a 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -18,6 +18,7 @@ from couchpotato.api import NonBlockHandler, ApiHandler from couchpotato.core.event import fireEventAsync, fireEvent from couchpotato.core.helpers.encoding import sp from couchpotato.core.helpers.variable import getDataDir, tryInt +import requests from tornado.httpserver import HTTPServer from tornado.web import Application, StaticFileHandler, RedirectHandler @@ -141,6 +142,7 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En Env.set('data_dir', sp(data_dir)) Env.set('log_path', sp(os.path.join(log_dir, 'CouchPotato.log'))) Env.set('db', db) + Env.set('http_opener', requests.Session()) Env.set('cache_dir', cache_dir) Env.set('cache', FileSystemCache(python_cache)) Env.set('console_log', options.console_log)