mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-07 10:33:38 +00:00
9ac649444d
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.
24 lines
No EOL
791 B
Python
24 lines
No EOL
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) |