fix unfinite loop on fail login, and fix error message lookup

This commit is contained in:
Romain Bignon 2014-10-11 14:03:05 +02:00
commit ce7e019e9a
2 changed files with 11 additions and 5 deletions

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.deprecated.browser import Browser
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
from .pages.index import IndexPage, LoginPage
from .pages.torrents import TorrentsPage
@ -29,7 +29,7 @@ __all__ = ['GazelleBrowser']
class GazelleBrowser(Browser):
PAGES = {'https?://[^/]+/?(index.php)?': IndexPage,
'https?://[^/]+/login.php': LoginPage,
'https?://[^/]+/login.php.*': LoginPage,
'https?://[^/]+/torrents.php.*': TorrentsPage,
}
@ -43,6 +43,12 @@ class GazelleBrowser(Browser):
self.location('/login.php', no_login=True)
self.page.login(self.username, self.password)
# If we are not logged, the on_loaded event on LoginPage has probably
# raised the exception, but to be sure, check here to prevent an
# unfinite loop if we can't find the error message.
if self.is_on_page(LoginPage):
raise BrowserIncorrectPassword()
def is_logged(self):
if not self.page or self.is_on_page(LoginPage):
return False

View file

@ -31,10 +31,10 @@ class LoginPage(BasePage):
def on_loaded(self):
BasePage.on_loaded(self)
warns = self.parser.select(self.document.getroot(), 'span.warning')
warns = self.parser.select(self.document.getroot(), '.warning')
for warn in warns:
text = self.parser.tocleanstring(warn)
if text.startswith('Your username'):
if text.startswith('Your '):
raise BrowserIncorrectPassword(text)
if text.startswith('You are banned'):
raise BrowserBanned(text)
@ -43,4 +43,4 @@ class LoginPage(BasePage):
self.browser.select_form(nr=0)
self.browser['username'] = login
self.browser['password'] = password
self.browser.submit()
self.browser.submit(no_login=True)