1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-08-13 16:53:54 -04:00
SickRage/lib/cachecontrol/session.py
echel0n 9ac649444d Added cache_auto, cache_urls, and cache_max_age features to our cache handler.
Added session handler to our cache handler so that we can pass in paramaters at the request level and use them for our cache handler to process features.
2014-03-28 21:23:55 -07:00

24 lines
791 B
Python

import datetime
from requests.sessions import Session
class CacheControlSession(Session):
def __init__(self, *args, **kw):
super(CacheControlSession, self).__init__(*args, **kw)
def request(self, *args, **kw):
# auto-cache response
self.cache_auto = False
if kw.has_key('cache_auto'):
self.cache_auto = kw.pop('cache_auto')
# urls allowed to cache
self.cache_urls = []
if kw.has_key('cache_urls'):
self.cache_urls = [str(args[1])] + kw.pop('cache_urls')
# timeout for cacheed responses
self.cache_max_age = None
if kw.has_key('cache_max_age'):
self.cache_max_age = int(kw.pop('cache_max_age'))
return super(CacheControlSession, self).request(*args, **kw)