Support gzipped responses
This commit is contained in:
parent
aafcf1273b
commit
391783a8b6
1 changed files with 12 additions and 0 deletions
|
|
@ -32,6 +32,8 @@ import time
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
from contextlib import closing
|
||||||
|
from gzip import GzipFile
|
||||||
|
|
||||||
from weboob.tools.decorators import retry
|
from weboob.tools.decorators import retry
|
||||||
from weboob.tools.log import getLogger
|
from weboob.tools.log import getLogger
|
||||||
|
|
@ -530,6 +532,16 @@ class BaseBrowser(StandardBrowser):
|
||||||
# print time.time()
|
# print time.time()
|
||||||
# mechanize.Browser._set_response(self, response, *args, **kwargs)
|
# mechanize.Browser._set_response(self, response, *args, **kwargs)
|
||||||
|
|
||||||
|
def _set_response(self, response, *args, **kwargs):
|
||||||
|
# Support Gzip, because mechanize does not, and some websites always send gzip
|
||||||
|
if response and hasattr(response, 'set_data'):
|
||||||
|
headers = response.info()
|
||||||
|
if headers.get('Content-Encoding', '') == 'gzip':
|
||||||
|
with closing(GzipFile(fileobj=response, mode='rb')) as gz:
|
||||||
|
data = gz.read()
|
||||||
|
response.set_data(data)
|
||||||
|
mechanize.Browser._set_response(self, response, *args, **kwargs)
|
||||||
|
|
||||||
def _change_location(self, result, no_login=False):
|
def _change_location(self, result, no_login=False):
|
||||||
"""
|
"""
|
||||||
This function is called when we have moved to a page, to load a Page
|
This function is called when we have moved to a page, to load a Page
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue