jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/663573 )

Change subject: [bugfix] Do not attemp to login over and over again
......................................................................

[bugfix] Do not attemp to login over and over again

- do not retry to login inside login method; this could lead to an
  infinite loop.
- remove deprecated LoginManager.getCookie() method
- update documentation in api.LoginManager

Bug: T224712
Change-Id: I607d111ccde9cc1dbd7ed11be3fed7bc54443d6e
---
M pywikibot/data/api.py
M pywikibot/login.py
2 files changed, 15 insertions(+), 28 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 492bd61..be40d19 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2849,7 +2849,7 @@

 class LoginManager(login.LoginManager):

-    """Supply getCookie() method to use API interface."""
+    """Supply login_to_site method to use API interface."""

     # API login parameters mapping
     mapping = {
@@ -2867,14 +2867,11 @@
         """Get API keyword from mapping."""
         return self.mapping[key][self.action != 'login']

-    def login_to_site(self):
+    def login_to_site(self) -> None:
         """Login to the site.

-        Note, this doesn't actually return or do anything with cookies.
-        The http module takes care of all the cookie stuff, this just
-        has a legacy name for now and should be renamed in the future.
-
-        @return: empty string if successful, throws exception on failure
+        Note, this doesn't do anything with cookies. The http module
+        takes care of all the cookie stuff. Throws exception on failure.
         """
         if hasattr(self, '_waituntil'):
             if datetime.datetime.now() < self._waituntil:
@@ -2939,7 +2936,7 @@
             status = response[result_key]
             fail_reason = response.get(self.keyword('reason'), '')
             if status == self.keyword('success'):
-                return None
+                return

             if status in ('NeedToken', 'WrongToken', 'badtoken'):
                 token = response.get('token')
@@ -2976,8 +2973,8 @@

         if 'error' in login_result:
             raise APIError(**response)
-        info = fail_reason
-        raise APIError(code=status, info=info)
+
+        raise APIError(code=status, info=fail_reason)

     def get_login_token(self) -> str:
         """Fetch login token from action=query&meta=tokens.
diff --git a/pywikibot/login.py b/pywikibot/login.py
index 1143583..fd0b988 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -186,18 +186,6 @@
         # No bot policies on other sites
         return True

-    @deprecated('login_to_site', since='20201227', future_warning=True)
-    @remove_last_args(['remember', 'captcha'])
-    def getCookie(self):
-        """
-        Login to the site.
-
-        @see: U{https://www.mediawiki.org/wiki/API:Login}
-
-        @return: cookie data if successful, None otherwise.
-        """
-        self.login_to_site()
-
     def login_to_site(self):
         """Login to the site."""
         # THIS IS OVERRIDDEN IN data/api.py
@@ -336,12 +324,14 @@
             # TODO: investigate other unhandled API codes (bug T75539)
             if retry:
                 self.password = None
-                return self.login(retry=True)
-            else:
-                return False
-        self.storecookiedata()
-        pywikibot.log('Should be logged in now')
-        return True
+                return self.login(retry=False)
+
+        else:
+            self.storecookiedata()
+            pywikibot.log('Should be logged in now')
+            return True
+
+        return False


 class BotPassword:

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/663573
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I607d111ccde9cc1dbd7ed11be3fed7bc54443d6e
Gerrit-Change-Number: 663573
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to