Save cookies on save_responses and pave the way for more good stuff
We apparently can't override the class in the Response, even if it is changed in the Session. Still, it will be useful to have our own class.
This commit is contained in:
parent
95e71e329b
commit
6acfd75780
2 changed files with 46 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Laurent Bachelier
|
||||
# Copyright(C) 2012-2014 Laurent Bachelier
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
|
|
@ -36,8 +36,7 @@ except ImportError:
|
|||
|
||||
from weboob.tools.log import getLogger
|
||||
|
||||
|
||||
# TODO define __all__
|
||||
from .cookies import WeboobCookieJar
|
||||
|
||||
|
||||
class Profile(object):
|
||||
|
|
@ -137,7 +136,7 @@ class BaseBrowser(object):
|
|||
self.response = None
|
||||
|
||||
self.responses_dirname = responses_dirname
|
||||
self.responses_count = 0
|
||||
self.responses_count = 1
|
||||
|
||||
def _save(self, response, warning=False, **kwargs):
|
||||
if self.responses_dirname is None:
|
||||
|
|
@ -162,8 +161,12 @@ class BaseBrowser(object):
|
|||
(self.responses_count, response.status_code, '-' if path else '', path, ext)
|
||||
|
||||
response_filepath = os.path.join(self.responses_dirname, filename)
|
||||
|
||||
with open(response_filepath, 'w') as f:
|
||||
f.write(response.content)
|
||||
if response.cookies and len(response.cookies):
|
||||
WeboobCookieJar.from_cookiejar(response.cookies).export(response_filepath + '-cookies.txt')
|
||||
|
||||
match_filepath = os.path.join(self.responses_dirname, 'url_response_match.txt')
|
||||
with open(match_filepath, 'a') as f:
|
||||
f.write('# %d %s %s\n' % (response.status_code, response.reason, response.headers.get('Content-Type', '')))
|
||||
|
|
@ -195,6 +198,9 @@ class BaseBrowser(object):
|
|||
|
||||
self.session = session
|
||||
|
||||
cj = WeboobCookieJar()
|
||||
session.cookies = cj
|
||||
|
||||
def location(self, url, **kwargs):
|
||||
"""
|
||||
Like open() but also changes the current URL and response.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue