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

Change subject: [IMPR] rename login.getCookie() to login.login_to_site()
......................................................................

[IMPR] rename login.getCookie() to login.login_to_site()

Do not overwrite login.storecookiedata() in api.py, instead
port the implementation in api.py to login.py.

Remove unused method parameters.

Change-Id: I10a6c2fe787d3a4c344b364a1b3c3f6564ff7306
---
M pywikibot/data/api.py
M pywikibot/login.py
2 files changed, 16 insertions(+), 22 deletions(-)

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



diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 9d644c2..cc29542 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -43,7 +43,6 @@
     issue_deprecation_warning,
     itergroup,
     PYTHON_VERSION,
-    remove_last_args,
 )
 from pywikibot.tools.formatter import color_format

@@ -2954,8 +2953,7 @@
         """Get API keyword from mapping."""
         return self.mapping[key][self.action != 'login']

-    @remove_last_args(arg_names=['remember, captchaId, captchaAnswer'])
-    def getCookie(self) -> str:
+    def login_to_site(self):
         """Login to the site.

         Note, this doesn't actually return or do anything with cookies.
@@ -3027,7 +3025,7 @@
             status = response[result_key]
             fail_reason = response.get(self.keyword('reason'), '')
             if status == self.keyword('success'):
-                return ''
+                return None

             if status in ('NeedToken', 'WrongToken', 'badtoken'):
                 token = response.get('token')
@@ -3067,10 +3065,6 @@
         info = fail_reason
         raise APIError(code=status, info=info)

-    def storecookiedata(self, data):
-        """Ignore data; cookies are set by http module."""
-        http.cookie_jar.save(ignore_discard=True)
-
     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 c923969..0a411e0 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -17,8 +17,10 @@
 import pywikibot

 from pywikibot import config, __url__
+from pywikibot.comms import http
 from pywikibot.exceptions import NoUsername
 from pywikibot.tools import (
+    deprecated,
     deprecated_args, file_mode_checker, normalize_username, remove_last_args,
 )

@@ -185,6 +187,7 @@
         # 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):
         """
@@ -194,20 +197,17 @@

         @return: cookie data if successful, None otherwise.
         """
-        # THIS IS OVERRIDDEN IN data/api.py
-        return None
+        self.login_to_site()

-    def storecookiedata(self, data: str) -> None:
-        """
-        Store cookie data.
-
-        @param data: The raw data as returned by getCookie()
-        """
+    def login_to_site(self):
+        """Login to the site."""
         # THIS IS OVERRIDDEN IN data/api.py
-        filename = config.datafilepath('pywikibot.lwp')
-        pywikibot.debug('Storing cookies to {}'.format(filename), _logger)
-        with open(filename, 'w') as f:
-            f.write(data)
+        raise NotImplementedError
+
+    @remove_last_args(['data'])
+    def storecookiedata(self) -> None:
+        """Store cookie data."""
+        http.cookie_jar.save(ignore_discard=True)

     def readPassword(self):
         """
@@ -323,7 +323,7 @@
         pywikibot.output('Logging in to {site} as {name}'
                          .format(name=self.login_name, site=self.site))
         try:
-            cookiedata = self.getCookie()
+            self.login_to_site()
         except pywikibot.data.api.APIError as e:
             error_code = e.code
             pywikibot.error('Login failed ({}).'.format(error_code))
@@ -340,7 +340,7 @@
                 return self.login(retry=True)
             else:
                 return False
-        self.storecookiedata(cookiedata)
+        self.storecookiedata()
         pywikibot.log('Should be logged in now')
         return True


--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/651994
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: I10a6c2fe787d3a4c344b364a1b3c3f6564ff7306
Gerrit-Change-Number: 651994
Gerrit-PatchSet: 2
Gerrit-Owner: 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