parameter 'no_login' to Browser.location() to don't check in we're logged
This commit is contained in:
parent
2b55ab7340
commit
150b07b306
2 changed files with 7 additions and 9 deletions
|
|
@ -37,8 +37,6 @@ class RedmineBrowser(BaseBrowser):
|
|||
'%s/projects/\w+/wiki/\w*': WikiPage,
|
||||
}
|
||||
|
||||
is_logging = False
|
||||
|
||||
def __init__(self, url, *args, **kwargs):
|
||||
v = urlsplit(url)
|
||||
self.PROTOCOL = v.scheme
|
||||
|
|
@ -55,19 +53,17 @@ class RedmineBrowser(BaseBrowser):
|
|||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
|
||||
def is_logged(self):
|
||||
return self.is_logging or (self.page and len(self.page.document.getroot().cssselect('a.my-account')) == 1)
|
||||
return self.page and len(self.page.document.getroot().cssselect('a.my-account')) == 1
|
||||
|
||||
def login(self):
|
||||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
|
||||
self.is_logging = True
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.location('%s/login' % self.BASEPATH)
|
||||
self.location('%s/login' % self.BASEPATH, no_login=True)
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
|
||||
self.is_logging = False
|
||||
if self.is_on_page(LoginPage):
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
|
|
|
|||
|
|
@ -330,8 +330,10 @@ class BaseBrowser(mechanize.Browser):
|
|||
keep_args = copy(args)
|
||||
keep_kwargs = kwargs.copy()
|
||||
|
||||
no_login = kwargs.pop('no_login', False)
|
||||
|
||||
try:
|
||||
self._change_location(mechanize.Browser.open(self, *args, **kwargs))
|
||||
self._change_location(mechanize.Browser.open(self, *args, **kwargs), no_login=no_login)
|
||||
except BrowserRetry:
|
||||
if not self.page or not args or self.page.url != args[0]:
|
||||
self.location(keep_args, keep_kwargs)
|
||||
|
|
@ -345,7 +347,7 @@ class BaseBrowser(mechanize.Browser):
|
|||
def get_document(self, result):
|
||||
return self.parser.parse(result, self.ENCODING)
|
||||
|
||||
def _change_location(self, result):
|
||||
def _change_location(self, result, no_login=False):
|
||||
"""
|
||||
This function is called when we have moved to a page, to load a Page
|
||||
object.
|
||||
|
|
@ -386,7 +388,7 @@ class BaseBrowser(mechanize.Browser):
|
|||
self.page = pageCls(self, document, result.geturl(), groups=page_groups, group_dict=page_group_dict, logger=self.logger)
|
||||
self.page.on_loaded()
|
||||
|
||||
if self.password is not None and not self.is_logged():
|
||||
if not no_login and self.password is not None and not self.is_logged():
|
||||
self.logger.debug('!! Relogin !!')
|
||||
self.login()
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue