Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/906740 )
Change subject: [IMPR] Guess the last needed token key if the token is not found
......................................................................
[IMPR] Guess the last needed token key if the token is not found
Bug: T334288
Change-Id: I0514f460384a736d583849078f813c14c72bc129
---
M pywikibot/site/_tokenwallet.py
1 file changed, 14 insertions(+), 1 deletion(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/site/_tokenwallet.py b/pywikibot/site/_tokenwallet.py
index 5ffd72f..0d7ec5a 100644
--- a/pywikibot/site/_tokenwallet.py
+++ b/pywikibot/site/_tokenwallet.py
@@ -29,6 +29,8 @@
self.site: APISite = site
self._tokens: Dict[str, str] = {}
self._currentuser: Optional[str] = site.user()
+ # guess the needed token in update_tokens
+ self._last_token_key: Optional[str] = None
def __getitem__(self, key: str) -> str:
"""Get token value for the given key."""
@@ -58,6 +60,7 @@
f'Invalid token {key!r} for user {self._currentuser!r} on '
f'{self.site} wiki.') from None
+ self._last_token_key = key
return token
def __contains__(self, key) -> bool:
@@ -119,7 +122,7 @@
# find the token types
types = [key
for key, value in self._tokens.items() for token in tokens
- if value == token]
+ if value == token] or [self._last_token_key]
self.clear() # clear the cache
return [self[token_type] for token_type in types]
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/906740
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: I0514f460384a736d583849078f813c14c72bc129
Gerrit-Change-Number: 906740
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/906547 )
Change subject: [bugfix] No longer lazy load cookies
......................................................................
[bugfix] No longer lazy load cookies
Lazy load of cookies was introduced with ba56084 when cookie files for
each user was introduced because the username was needed first load the
cookie. But this change needs an explicit login() call and was a
regression against Pywikibot 7.6.
- always make a cookie-only login when a Site was initialzed
- try to login if API response is 'notloggedin'; this is the
same behaviour as for 'readapidenied'
Bug: T331315
Bug: T330488
Bug: T329132
Bug: T326779
Bug: T271858
Change-Id: I34caa567b883a5d0ae81eea5250fae01fcb29554
---
M tests/utils.py
M pywikibot/site/_apisite.py
M pywikibot/data/api/_requests.py
3 files changed, 67 insertions(+), 23 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index bbd5744..3c7bbc6 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -938,8 +938,11 @@
return True
def submit(self) -> dict:
- """
- Submit a query and parse the response.
+ """Submit a query and parse the response.
+
+ .. versionchanged:: 8.1
+ in addition to *readapidenied* also try to login when API
+ response is *notloggedin*.
:return: a dict containing data retrieved from api.php
"""
@@ -1033,8 +1036,8 @@
self._ratelimited()
continue
- # If readapidenied is returned try to login
- if code == 'readapidenied' \
+ # If notloggedin or readapidenied is returned try to login
+ if code in ('notloggedin', 'readapidenied') \
and self.site._loginstatus in (LoginStatus.NOT_ATTEMPTED,
LoginStatus.NOT_LOGGED_IN):
self.site.login()
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index ae8bb42..673d619 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -118,11 +118,13 @@
super().__init__(code, fam, user)
self._globaluserinfo: Dict[Union[int, str], Any] = {}
self._interwikimap = _InterwikiMap(self)
- self._loginstatus = login.LoginStatus.NOT_ATTEMPTED
self._msgcache: Dict[str, str] = {}
self._paraminfo = api.ParamInfo(self)
self._siteinfo = Siteinfo(self)
self._tokens = TokenWallet(self)
+ self._loginstatus = login.LoginStatus.NOT_ATTEMPTED
+ with suppress(SiteDefinitionError):
+ self.login(cookie_only=True)
def __getstate__(self) -> Dict[str, Any]:
"""Remove TokenWallet before pickling, for security reasons."""
@@ -324,12 +326,17 @@
def login(
self,
autocreate: bool = False,
- user: Optional[str] = None
+ user: Optional[str] = None,
+ *,
+ cookie_only: bool = False
) -> None:
"""Log the user in if not already logged in.
.. versionchanged:: 8.0
- lazy load cookies when logging in.
+ lazy load cookies when logging in. This was dropped in 8.1
+ .. versionchanged:: 8.1
+ the *cookie_only* parameter was added and cookies are loaded
+ whenever the site is initialized.
.. seealso:: :api:`Login`
@@ -337,6 +344,8 @@
using unified login
:param user: bot user name. Overrides the username set by
BaseSite initializer parameter or user config setting
+ :param cookie_only: Only try to login from cookie but do not
+ force to login with username/password settings.
:raises pywikibot.exceptions.NoUsernameError: Username is not
recognised by the site.
@@ -404,23 +413,22 @@
raise NoUsernameError(error_msg)
- login_manager = login.ClientLoginManager(site=self,
- user=self.username())
- if login_manager.login(retry=True, autocreate=autocreate):
- self._username = login_manager.username
- del self.userinfo # force reloading
+ if not cookie_only:
+ login_manager = login.ClientLoginManager(site=self,
+ user=self.username())
+ if login_manager.login(retry=True, autocreate=autocreate):
+ self._username = login_manager.username
+ del self.userinfo # force reloading
- # load userinfo
- if self.userinfo['name'] == self.username():
- self._loginstatus = login.LoginStatus.AS_USER
- return
+ # load userinfo
+ if self.userinfo['name'] == self.username():
+ self._loginstatus = login.LoginStatus.AS_USER
+ return
- pywikibot.error('{} != {} after {}.login() and successful '
- '{}.login()'
- .format(self.userinfo['name'],
- self.username(),
- type(self).__name__,
- type(login_manager).__name__))
+ pywikibot.error(
+ f"{self.userinfo['name']} != {self.username()} after "
+ f'{type(self).__name__}.login() and successful '
+ f'{type(login_manager).__name__}.login()')
self._loginstatus = login.LoginStatus.NOT_LOGGED_IN # failure
@@ -538,7 +546,8 @@
assert 'userinfo' in uidata['query'], \
"API userinfo response lacks 'userinfo' key"
self._userinfo = uidata['query']['userinfo']
- if 'anon' in self._userinfo or not self._userinfo.get('id'):
+ if self._loginstatus != login.LoginStatus.IN_PROGRESS \
+ and ('anon' in self._userinfo or not self._userinfo.get('id')):
pywikibot.warning('No user is logged in on site {}'
.format(self))
return self._userinfo
diff --git a/tests/utils.py b/tests/utils.py
index c71658d..38c4105 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -400,6 +400,15 @@
interface=DryDataSite)
return None
+ def login(self, *args, cookie_only=False, **kwargs):
+ """Overwrite login which is called when a site is initialized.
+
+ .. versionadded: 8.1
+ """
+ if cookie_only:
+ return
+ raise Exception(f'Attempting to login with {type(self).__name__}')
+
class DryDataSite(DrySite, pywikibot.site.DataSite):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/906547
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: I34caa567b883a5d0ae81eea5250fae01fcb29554
Gerrit-Change-Number: 906547
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Amire80 <amir.aharoni(a)mail.huji.ac.il>
Gerrit-Reviewer: Bináris <wikiposta(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/906549 )
Change subject: Localisation updates from https://translatewiki.net.
......................................................................
Localisation updates from https://translatewiki.net.
Change-Id: I145f9c1302c2e45f07647ff9ec2098ea2b5d5e62
---
M pywikibot/bn.json
M delinker/bn.json
M unprotect/de.json
M archivebot/gsw.json
M delinker/ca.json
M welcome/de.json
M protect/ca.json
M delinker/fr.json
M pywikibot/pdc.json
M checkimages/de.json
M unprotect/he.json
11 files changed, 31 insertions(+), 14 deletions(-)
Approvals:
L10n-bot: Looks good to me, approved
jenkins-bot: Verified
diff --git a/archivebot/gsw.json b/archivebot/gsw.json
index 12d999e..ed2a601 100644
--- a/archivebot/gsw.json
+++ b/archivebot/gsw.json
@@ -7,6 +7,6 @@
},
"archivebot-archive-full": "(ARCHIVE FULL)",
"archivebot-archive-summary": "Bötli: Due %(count)d {{PLURAL:count|Abschnitt|Abschnitte}} vo [[%(from)s]] archiviere",
- "archivebot-older-than": "elter wie",
+ "archivebot-older-than": "{{PLURAL:%(count)d|elter}} wie %(duration)s",
"archivebot-page-summary": "Bötli: Due %(count)d {{PLURAL:count|Abschnitt|Abschnitte}} (%(why)s) uff %(archives)s archiviere"
}
diff --git a/checkimages/de.json b/checkimages/de.json
index d12c4c2..07f0541 100644
--- a/checkimages/de.json
+++ b/checkimages/de.json
@@ -7,10 +7,10 @@
]
},
"checkimages-deletion-comment": "Bot: Füge %(adding)s hinzu",
- "checkimages-doubles-file-comment": "Bot: Datei liegt auf Commons",
+ "checkimages-doubles-file-comment": "Bot: Datei liegt bereits auf Commons, kann gelöscht werden",
"checkimages-doubles-head": "Datei-Duplikat",
"checkimages-doubles-talk-comment": "Bot: Benachrichtigung, dass die Datei bereits auf Commons vorhanden ist",
- "checkimages-log-comment": "Bot: schreibe Log",
+ "checkimages-log-comment": "Bot: Aktualisiere das Log",
"checkimages-no-license-head": "Bild ohne Lizenz",
"checkimages-source-tag-comment": "Bot: Markiere zur Dateiüberprüfung, da keine Lizenzvorlage gefunden.",
"checkimages-source-notice-comment": "Bot: Benachrichtigung über Lizenzprobleme.",
diff --git a/delinker/bn.json b/delinker/bn.json
index c71d56a..931e88a 100644
--- a/delinker/bn.json
+++ b/delinker/bn.json
@@ -4,5 +4,5 @@
"আফতাবুজ্জামান"
]
},
- "delinker-delink": "বট: [[%(title)s]] ফাইলটি সরানো হল, কারণ এটি [[:User:%(user)s]] কর্তৃক অপসারিত হয়েছে: ''%(comment)s''।"
+ "delinker-delink": "বট: [[%(title)s]] ফাইলটি সরানো হল, কারণ এটি [[:User:%(user)s]] কর্তৃক অপসারিত হয়েছে: ''%(comment)s''"
}
diff --git a/delinker/ca.json b/delinker/ca.json
index cdfde97..018670f 100644
--- a/delinker/ca.json
+++ b/delinker/ca.json
@@ -1,8 +1,9 @@
{
"@metadata": {
"authors": [
+ "Mguix",
"Robertgarrigos"
]
},
- "delinker-delink": "Bot: el fitxer [[%(title)s]] s'ha eliminat, ja que l'ha suprimit [[:User:%(user)s]]: ''%(comment)s''."
+ "delinker-delink": "Bot: el fitxer [[%(title)s]] s'ha eliminat, ja que l'ha suprimit [[:User:%(user)s]]: ''%(comment)s''"
}
diff --git a/delinker/fr.json b/delinker/fr.json
index 5d3da4f..1ab82e1 100644
--- a/delinker/fr.json
+++ b/delinker/fr.json
@@ -4,5 +4,5 @@
"Verdy p"
]
},
- "delinker-delink": "Robot : le fichier [[%(title)s]] a été supprimé, comme demandé par [[:User:%(user)s]] : ''%(comment)s''."
+ "delinker-delink": "Robot : le fichier [[%(title)s]] a été retiré car il a été supprimé par [[:User:%(user)s]] : ''%(comment)s''."
}
diff --git a/protect/ca.json b/protect/ca.json
index cecb1b0..9e14e03 100644
--- a/protect/ca.json
+++ b/protect/ca.json
@@ -8,6 +8,6 @@
"protect-category": "Bot: Protegint totes les pàgines de la categoria %(cat)s",
"protect-images": "Bot: Protegint totes les imatges de la pàgina %(page)s",
"protect-links": "Bot: Protegint totes les pàgines que s'enllacen des de %(page)s",
- "protect-ref": "Bot: Protegint totes les pàgines amb referència des de %(page)s",
+ "protect-ref": "Bot: Protegint totes les pàgines amb referència cap a %(page)s",
"protect-simple": "Bot: Protegint una llista de fitxers."
}
diff --git a/pywikibot/bn.json b/pywikibot/bn.json
index 09ba89e..4c4033e 100644
--- a/pywikibot/bn.json
+++ b/pywikibot/bn.json
@@ -10,6 +10,7 @@
"আফতাবুজ্জামান"
]
},
+ "pywikibot-bot-prefix": "বট:",
"pywikibot-cosmetic-changes": "; সজ্জা পরিবর্তন",
"pywikibot-enter-category-name": "বিষয়শ্রেণীর নাম প্রবেশ করান:",
"pywikibot-enter-new-text": "দয়া করে নতুন বাক্য লিখুন:",
diff --git a/pywikibot/pdc.json b/pywikibot/pdc.json
index 359faa8..41af2b5 100644
--- a/pywikibot/pdc.json
+++ b/pywikibot/pdc.json
@@ -1,6 +1,9 @@
{
"@metadata": {
- "authors": []
+ "authors": [
+ "Xqt"
+ ]
},
+ "pywikibot-bot-prefix": "Waddefresser:",
"pywikibot-cosmetic-changes": "; gleenere Enneringe"
}
diff --git a/unprotect/de.json b/unprotect/de.json
index 261bc2f..c7cf4e1 100644
--- a/unprotect/de.json
+++ b/unprotect/de.json
@@ -1,11 +1,12 @@
{
"@metadata": {
"authors": [
- "Metalhead64"
+ "Metalhead64",
+ "Xqt"
]
},
- "unprotect-category": "Bot: Gebe alle Seiten aus der Kategorie %(cat)s frei",
- "unprotect-images": "Bot: Gebe alle Bilder auf der Seite %(page)s frei",
+ "unprotect-category": "Bot: Hebe den Schutz aller Seiten aus der Kategorie %(cat)s auf",
+ "unprotect-images": "Bot: Hebe den Schutz aller Dateien auf der Seite %(page)s auf",
"unprotect-links": "Bot: Gebe alle Seiten frei, die von %(page)s verlinkt sind",
"unprotect-ref": "Bot: Gebe alle Seiten frei, die von %(page)s verweisen",
"unprotect-simple": "Bot: Gebe eine Liste mit Dateien frei"
diff --git a/unprotect/he.json b/unprotect/he.json
index 303c908..afd4b91 100644
--- a/unprotect/he.json
+++ b/unprotect/he.json
@@ -7,6 +7,6 @@
"unprotect-category": "בוט: מסיר הגנה מהקטגוריה %(cat)s",
"unprotect-images": "בוט: מסיר הגנה מכל התמונות בדף %(page)s",
"unprotect-links": "בוט: מסיר הכנה מכל הדפים שמקושרים מהדף %(page)s",
- "unprotect-ref": "בוט: מסיר הגנה מכל הדפים שמקשרים על %(page)s",
+ "unprotect-ref": "בוט: מסיר הגנה מכל הדפים שמקשרים לדף %(page)s",
"unprotect-simple": "בוט: מסיר הגנה מרשימת קבצים"
}
diff --git a/welcome/de.json b/welcome/de.json
index 0a2fb99..7d169c1 100644
--- a/welcome/de.json
+++ b/welcome/de.json
@@ -1,8 +1,10 @@
{
"@metadata": {
- "authors": []
+ "authors": [
+ "Xqt"
+ ]
},
- "welcome-bad_username": "Bot: Ergänze zu überprüfenden Benutzernamen",
+ "welcome-bad_username": "Bot: Ergänze einen zu überprüfenden Benutzernamen",
"welcome-updating": "Bot: Aktualisiere Logdatei",
"welcome-welcome": "Herzlich willkommen!"
}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/i18n/+/906549
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/i18n
Gerrit-Branch: master
Gerrit-Change-Id: I145f9c1302c2e45f07647ff9ec2098ea2b5d5e62
Gerrit-Change-Number: 906549
Gerrit-PatchSet: 1
Gerrit-Owner: L10n-bot <l10n-bot(a)translatewiki.net>
Gerrit-Reviewer: L10n-bot <l10n-bot(a)translatewiki.net>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged