mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
05410e2aa0
Replaced urllib2 with requests for both TVDB and TVRage. Updated cache cleanup code to process both TVDB and TVRage cache folders.
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
import requests
|
|
|
|
from requests import models
|
|
from requests.packages.urllib3.response import HTTPResponse
|
|
|
|
__attrs__ = [
|
|
'_content',
|
|
'status_code',
|
|
'headers',
|
|
'url',
|
|
'history',
|
|
'encoding',
|
|
'reason',
|
|
'cookies',
|
|
'elapsed',
|
|
]
|
|
|
|
|
|
def response_getstate(self):
|
|
# consume everything
|
|
if not self._content_consumed:
|
|
self.content
|
|
|
|
state = dict(
|
|
(attr, getattr(self, attr, None))
|
|
for attr in __attrs__
|
|
)
|
|
|
|
# deal with our raw content b/c we need it for our cookie jar
|
|
state['raw_original_response'] = self.raw._original_response
|
|
return state
|
|
|
|
|
|
def response_setstate(self, state):
|
|
for name, value in state.items():
|
|
if name != 'raw_original_response':
|
|
setattr(self, name, value)
|
|
|
|
setattr(self, 'raw', HTTPResponse())
|
|
self.raw._original_response = state['raw_original_response']
|
|
|
|
|
|
def make_responses_pickleable():
|
|
try:
|
|
version_parts = [int(part) for part in requests.__version__.split('.')]
|
|
|
|
# must be >= 2.2.x
|
|
if not version_parts[0] >= 2 or not version_parts[1] >= 2:
|
|
models.Response.__getstate__ = response_getstate
|
|
models.Response.__setstate__ = response_setstate
|
|
except:
|
|
raise
|
|
pass
|
|
|
|
|
|
make_responses_pickleable()
|