From 3db51ef268198c161a413731d370f749656f6d11 Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 27 Mar 2014 15:39:54 -0700 Subject: [PATCH] Fixed typo in TVDB Api code Updated cache handler code --- lib/cachecontrol/controller.py | 15 ++++++++++----- lib/tvdb_api/tvdb_api.py | 8 +++++--- lib/tvrage_api/tvrage_api.py | 6 ++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/cachecontrol/controller.py b/lib/cachecontrol/controller.py index 8aa2f985..bb27fbaf 100644 --- a/lib/cachecontrol/controller.py +++ b/lib/cachecontrol/controller.py @@ -200,12 +200,17 @@ class CacheController(object): self.cache.set(cache_url, resp) # If we want to cache sites not setup with cache headers then add the proper headers and keep the response - if self.cache_all: - expires = datetime.datetime.utcnow() + datetime.timedelta(days=(25 * 365)) - expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") - headers = {'Cache-Control': 'public,max-age=%d' % int(3600), - 'Expires': expires} + elif self.cache_all and getattr(resp.headers, 'cache-control', None) is None: + headers = {'Cache-Control': 'public,max-age=%d' % int(3600)} resp.headers.update(headers) + + if getattr(resp.headers, 'expires', None) is None: + expires = datetime.datetime.utcnow() + datetime.timedelta(days=(25 * 365)) + expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") + headers = {'Expires': expires} + resp.headers.update(headers) + + # Add resp to cache self.cache.set(cache_url, resp) # Add to the cache if the response headers demand it. If there diff --git a/lib/tvdb_api/tvdb_api.py b/lib/tvdb_api/tvdb_api.py index 85301294..fcb7e2b2 100644 --- a/lib/tvdb_api/tvdb_api.py +++ b/lib/tvdb_api/tvdb_api.py @@ -428,13 +428,15 @@ class Tvdb: if cache is True: self.config['cache_enabled'] = True self.sess = cachecontrol.CacheControl(requests.Session(), - cache=caches.FileCache(self._getTempDir()), cache_all=True) + cache_all=True, + cache=caches.FileCache(self._getTempDir())) elif cache is False: self.config['cache_enabled'] = False elif isinstance(cache, basestring): self.config['cache_enabled'] = True self.sess = cachecontrol.CacheControl(requests.Session(), - cache=caches.FileCache(cache), cache_all=True) + cache_all=True, + cache=caches.FileCache(cache)) else: raise ValueError("Invalid value for Cache %r (type was %s)" % (cache, type(cache))) @@ -537,7 +539,7 @@ class Tvdb: # get response from TVDB if self.config['cache_enabled']: - resp = self.sess.get(url, params=sorted(params)) + resp = self.sess.get(url, params=params) else: resp = requests.get(url, params=params) diff --git a/lib/tvrage_api/tvrage_api.py b/lib/tvrage_api/tvrage_api.py index 35d9ceb9..0144df84 100644 --- a/lib/tvrage_api/tvrage_api.py +++ b/lib/tvrage_api/tvrage_api.py @@ -271,13 +271,15 @@ class TVRage: if cache is True: self.config['cache_enabled'] = True self.sess = cachecontrol.CacheControl(requests.Session(), - cache=caches.FileCache(self._getTempDir()), cache_all=True) + cache_all=True, + cache=caches.FileCache(self._getTempDir())) elif cache is False: self.config['cache_enabled'] = False elif isinstance(cache, basestring): self.config['cache_enabled'] = True self.sess = cachecontrol.CacheControl(requests.Session(), - cache=caches.FileCache(cache), cache_all=True) + cache_all=True, + cache=caches.FileCache(cache)) else: raise ValueError("Invalid value for Cache %r (type was %s)" % (cache, type(cache)))