handle general errors when website is unavailable
This commit is contained in:
parent
59dfe3083a
commit
06eb33ec59
3 changed files with 41 additions and 4 deletions
34
weboob/backends/gazelle/pages/base.py
Normal file
34
weboob/backends/gazelle/pages/base.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Romain Bignon
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
# weboob is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# weboob is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.browser import BrowserUnavailable, BasePage as _BasePage
|
||||
|
||||
|
||||
__all__ = ['BasePage']
|
||||
|
||||
|
||||
class BasePage(_BasePage):
|
||||
def on_loaded(self):
|
||||
errors = []
|
||||
for div in self.parser.select(self.document.getroot(), 'div.poetry'):
|
||||
errors.append(self.parser.tocleanstring(div))
|
||||
|
||||
if len(errors) > 0:
|
||||
raise BrowserUnavailable(', '.join(errors))
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.browser import BasePage, BrowserIncorrectPassword, BrowserBanned
|
||||
from weboob.tools.misc import remove_html_tags
|
||||
from weboob.tools.browser import BrowserIncorrectPassword, BrowserBanned
|
||||
from .base import BasePage
|
||||
|
||||
|
||||
__all__ = ['IndexPage', 'LoginPage']
|
||||
|
|
@ -32,9 +32,11 @@ class IndexPage(BasePage):
|
|||
|
||||
class LoginPage(BasePage):
|
||||
def on_loaded(self):
|
||||
BasePage.on_loaded(self)
|
||||
|
||||
warns = self.parser.select(self.document.getroot(), 'span.warning')
|
||||
for warn in warns:
|
||||
text = remove_html_tags(self.parser.tostring(warn)).strip()
|
||||
text = self.parser.tocleanstring(warn)
|
||||
if text.startswith('Your username'):
|
||||
raise BrowserIncorrectPassword(text)
|
||||
if text.startswith('You are banned'):
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ import urlparse
|
|||
from logging import warning, debug
|
||||
|
||||
from weboob.tools.misc import html2text, get_bytes_size
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.torrent import Torrent
|
||||
from weboob.capabilities.base import NotLoaded
|
||||
|
||||
from .base import BasePage
|
||||
|
||||
|
||||
__all__ = ['TorrentsPage']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue