Raise BrowserBanned if IP banned
This commit is contained in:
parent
7592dcb4ea
commit
fa214f5760
2 changed files with 17 additions and 6 deletions
|
|
@ -18,8 +18,8 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserBanned
|
||||||
from .pages import HomePage, LoginPage, HistoryPage, BillsPage
|
from .pages import HomePage, LoginPage, HistoryPage, BillsPage, ErrorPage
|
||||||
|
|
||||||
__all__ = ['PoivyBrowser']
|
__all__ = ['PoivyBrowser']
|
||||||
|
|
||||||
|
|
@ -31,7 +31,8 @@ class PoivyBrowser(BaseBrowser):
|
||||||
PAGES = {'.*login': LoginPage,
|
PAGES = {'.*login': LoginPage,
|
||||||
'.*buy_credit.*': HomePage,
|
'.*buy_credit.*': HomePage,
|
||||||
'.*/recent_calls': HistoryPage,
|
'.*/recent_calls': HistoryPage,
|
||||||
'.*purchases': BillsPage
|
'.*purchases': BillsPage,
|
||||||
|
'.*warning.*': ErrorPage
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
@ -50,9 +51,10 @@ class PoivyBrowser(BaseBrowser):
|
||||||
if not self.is_on_page(LoginPage):
|
if not self.is_on_page(LoginPage):
|
||||||
self.location('/login')
|
self.location('/login')
|
||||||
|
|
||||||
self.page.login(self.username, self.password)
|
if not self.page.login(self.username, self.password):
|
||||||
|
raise BrowserBanned('Too many connections from you IP address: captcha enabled')
|
||||||
|
|
||||||
if self.is_on_page(LoginPage):
|
if self.is_on_page(LoginPage) or self.is_on_page(ErrorPage):
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
||||||
def get_subscription_list(self):
|
def get_subscription_list(self):
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,12 @@ from datetime import datetime, date, time
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
__all__ = ['LoginPage', 'HomePage', 'HistoryPage', 'BillsPage']
|
__all__ = ['LoginPage', 'HomePage', 'HistoryPage', 'BillsPage', 'ErrorPage']
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorPage(BasePage):
|
||||||
|
def on_loaded(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LoginPage(BasePage):
|
class LoginPage(BasePage):
|
||||||
|
|
@ -39,12 +44,16 @@ class LoginPage(BasePage):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
|
captcha = self.document.xpath('label[@class="label_captcha_input"]')
|
||||||
|
if captcha is not None:
|
||||||
|
return False
|
||||||
# Form without name
|
# Form without name
|
||||||
self.browser.select_form(predicate=self._predicate_form)
|
self.browser.select_form(predicate=self._predicate_form)
|
||||||
self.browser.set_all_readonly(False)
|
self.browser.set_all_readonly(False)
|
||||||
self.browser['login[username]'] = login.encode('iso-8859-1')
|
self.browser['login[username]'] = login.encode('iso-8859-1')
|
||||||
self.browser['login[password]'] = password.encode('iso-8859-1')
|
self.browser['login[password]'] = password.encode('iso-8859-1')
|
||||||
self.browser.submit(nologin=True)
|
self.browser.submit(nologin=True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class HomePage(BasePage):
|
class HomePage(BasePage):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue