handle error page to avoid global crashes

This commit is contained in:
Romain Bignon 2015-06-05 18:40:07 +02:00 committed by Romain Bignon
commit 45b776913b
2 changed files with 28 additions and 6 deletions

View file

@ -23,7 +23,7 @@ import urllib
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword, BrokenPageError
from .pages import LoginPage, IndexPage, AccountsPage, AccountsFullPage, CardsPage, TransactionsPage, \
UnavailablePage, RedirectPage, HomePage, Login2Page, \
UnavailablePage, RedirectPage, HomePage, Login2Page, ErrorPage, \
LineboursePage, NatixisPage, InvestmentNatixisPage, InvestmentLineboursePage, MessagePage
@ -47,6 +47,7 @@ class BanquePopulaire(Browser):
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=CONTRAT.*': TransactionsPage,
'https://[^/]+/cyber/internet/Page.do\?.*': TransactionsPage,
'https://[^/]+/cyber/internet/Sort.do\?.*': TransactionsPage,
'https://[^/]+/cyber/internet/ContinueTask.do': ErrorPage,
'https://[^/]+/s3f-web/.*': UnavailablePage,
'https://[^/]+/portailinternet/_layouts/Ibp.Cyi.Layouts/RedirectSegment.aspx.*': RedirectPage,
'https://[^/]+/portailinternet/Catalogue/Segments/.*.aspx(\?vary=(?P<vary>.*))?': HomePage,
@ -160,7 +161,7 @@ class BanquePopulaire(Browser):
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(params))
if self.page.no_operations():
if not self.page or self.page.no_operations():
return
# Sort by values dates (see comment in TransactionsPage.get_history)
@ -183,10 +184,17 @@ class BanquePopulaire(Browser):
self.location(self.buildurl('/cyber/internet/Page.do', **next_params))
def get_investment(self, account):
if not account._invest_params:
raise NotImplementedError()
account = self.get_account(account.id)
params = account._params
params = account._invest_params
params['token'] = self.page.build_token(params['token'])
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(params))
if self.is_on_page(ErrorPage):
raise NotImplementedError()
url, params = self.page.get_investment_page_params()
if params:
self.location(url, urllib.urlencode(params))

View file

@ -64,6 +64,7 @@ class BasePage(_BasePage):
def on_loaded(self):
if not self.is_error():
self.browser.token = self.get_token()
self.logger.debug('Update token to %s', self.browser.token)
def is_error(self):
return False
@ -196,6 +197,17 @@ class RedirectPage(BasePage):
self.browser.submit(nologin=True)
class ErrorPage(BasePage):
def get_token(self):
try:
buf = self.document.xpath('//body/@onload')[0]
except IndexError:
return
else:
m = re.search("saveToken\('([^']+)'\)", buf)
if m:
return m.group(1)
class UnavailablePage(BasePage):
def on_loaded(self):
try:
@ -411,6 +423,7 @@ class AccountsPage(BasePage):
account._next_debit = None
account._params = None
account._coming_params = None
account._invest_params = None
if balance != u'' and len(tds[3].xpath('.//a')) > 0:
account._params = params.copy()
account._params['dialogActionPerformed'] = 'SOLDE'
@ -427,9 +440,9 @@ class AccountsPage(BasePage):
next_pages.append(_params)
if not account._params:
account._params = params.copy()
account._params['dialogActionPerformed'] = 'CONTRAT'
account._params['attribute($SEL_$%s)' % tr.attrib['id'].split('_')[0]] = tr.attrib['id'].split('_', 1)[1]
account._invest_params = params.copy()
account._invest_params['dialogActionPerformed'] = 'CONTRAT'
account._invest_params['attribute($SEL_$%s)' % tr.attrib['id'].split('_')[0]] = tr.attrib['id'].split('_', 1)[1]
yield account
@ -471,6 +484,7 @@ class CardsPage(BasePage):
account.label = u' '.join([self.parser.tocleanstring(cols[self.COL_TYPE]),
self.parser.tocleanstring(cols[self.COL_LABEL])])
account._params = None
account._invest_params = None
account._coming_params = params.copy()
account._coming_params['dialogActionPerformed'] = 'SELECTION_ENCOURS_CARTE'
account._coming_params['attribute($SEL_$%s)' % tr.attrib['id'].split('_')[0]] = tr.attrib['id'].split('_', 1)[1]