From 907334f82ce7e41e0e78cc41c2817b3c40f9fe29 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Fri, 13 Feb 2015 00:01:49 +0000 Subject: [PATCH] Add catch exceptions when unable to cache a requests response. --- CHANGES.md | 1 + lib/cachecontrol/adapter.py | 9 +++++++-- lib/cachecontrol/controller.py | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1a4ec646..81ac0da4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -51,6 +51,7 @@ * Fix SSL authentication on Synology stations * Change IPT urls to reduce 301 redirection * Add detection of file-system having no support for link creation (e.g. Unraid shares) +* Add catch exceptions when unable to cache a requests response [develop changelog] * Change uT params from unicode to str.format as magnet URLs worked but sending files in POST bodies failed diff --git a/lib/cachecontrol/adapter.py b/lib/cachecontrol/adapter.py index d2ca7e87..03313f5e 100644 --- a/lib/cachecontrol/adapter.py +++ b/lib/cachecontrol/adapter.py @@ -1,8 +1,9 @@ -from requests.adapters import HTTPAdapter +from lib.requests.adapters import HTTPAdapter from .controller import CacheController from .cache import DictCache + class CacheControlAdapter(HTTPAdapter): invalidating_methods = set(['PUT', 'DELETE']) @@ -58,7 +59,11 @@ class CacheControlAdapter(HTTPAdapter): response = cached_response else: # try to cache the response - self.controller.cache_response(request, response) + try: + self.controller.cache_response(request, response) + except Exception as e: + # Failed to cache the results + pass resp = super(CacheControlAdapter, self).build_response( request, response diff --git a/lib/cachecontrol/controller.py b/lib/cachecontrol/controller.py index 9bf9186c..3d208be0 100644 --- a/lib/cachecontrol/controller.py +++ b/lib/cachecontrol/controller.py @@ -6,7 +6,7 @@ import calendar import time import datetime -from requests.structures import CaseInsensitiveDict +from lib.requests.structures import CaseInsensitiveDict from .cache import DictCache from .compat import parsedate_tz @@ -21,7 +21,7 @@ def parse_uri(uri): (scheme, authority, path, query, fragment) = parse_uri(uri) """ groups = URI.match(uri).groups() - return (groups[1], groups[3], groups[4], groups[6], groups[8]) + return groups[1], groups[3], groups[4], groups[6], groups[8] class CacheController(object):