Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1154265?usp=email )
Change subject: tests: Remove login attribute from RequireLoginMixin
......................................................................
tests: Remove login attribute from RequireLoginMixin
The login attribute is already given if the RequireLoginMixin is
added to the base class:
if dct.get('login'):
bases = cls.add_base(bases, RequireLoginMixin)
Change-Id: I26ac9271cf05270456f0a3af9a7adb9de913f33d
---
M tests/aspects.py
1 file changed, 0 insertions(+), 2 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/tests/aspects.py b/tests/aspects.py
index 0bca615..fe0f2df 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -559,8 +559,6 @@
"""Run tests against a specific site, with a login."""
- login = True
-
@classmethod
def require_site_user(cls, family, code):
"""Check the user config has a valid login to the site."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1154265?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I26ac9271cf05270456f0a3af9a7adb9de913f33d
Gerrit-Change-Number: 1154265
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152397?usp=email )
Change subject: IMPR: Enable EmailAuth with Pywikibot
......................................................................
IMPR: Enable EmailAuth with Pywikibot
Enable secondary authentication via email was enabled.
Also every other secondary authentication should work now.
- find the token key in response['requests']['fields']
- The label field is printed as input message
- the help field is printed it the first auth token was wrong
Bug: T395703
Change-Id: I6c420c2f1d21adda4eb5be46078420e91bd044b2
---
M pywikibot/login.py
1 file changed, 40 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/login.py b/pywikibot/login.py
index e4fcf84..0622488 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -12,6 +12,7 @@
import webbrowser
from enum import IntEnum
from pathlib import Path
+from textwrap import fill
from typing import Any
from warnings import warn
@@ -354,6 +355,11 @@
.. versionchanged:: 8.0
2FA login was enabled. LoginManager was moved from :mod:`data.api`
to :mod:`login` module and renamed to *ClientLoginManager*.
+ .. versionchanged:: 10.2
+ Secondary authentication via email was enabled.
+ .. seealso::
+ - https://www.mediawiki.org/wiki/Extension:OATHAuth
+ - https://www.mediawiki.org/wiki/Extension:EmailAuth
"""
# API login parameters mapping
@@ -406,7 +412,13 @@
takes care of all the cookie stuff. Throws exception on failure.
.. versionchanged:: 8.0
- 2FA login was enabled.
+ 2FA login was implemented.
+ .. versionchanged:: 10.2
+ Secondary authentication via email was implemented.
+
+ :raises RuntimeError: Unexpected API login response key or
+ unexpected API login requests response
+ :raises APIError: API login error
"""
if hasattr(self, '_waituntil') \
and datetime.datetime.now() < self._waituntil:
@@ -463,12 +475,34 @@
continue
if status == 'UI': # pragma: no cover
- oathtoken = pywikibot.input(response['message'], password=True)
- login_request['OATHToken'] = oathtoken
+ # find token key
+ token_key = None
+ for request in response['requests']:
+ if 'fields' in request:
+ fields = request['fields']
+ keys = list(fields)
+ if len(keys) == 1:
+ token_key = keys[0]
+ field = fields[token_key]
+ break
+
+ if not token_key:
+ raise RuntimeError('Unexpected API login requests response'
+ f':\n{response["requests"]}')
+
+ pywikibot.info(fill(response['message'], 77))
+ if fail := response['messagecode'].endswith(('-failure',
+ '-failed')):
+ pywikibot.info(fill(field['help'], 77))
+ token_val = pywikibot.input(field['label'], password=True)
+ login_request[token_key] = token_val
login_request['logincontinue'] = True
- del login_request['username']
- del login_request['password']
- del login_request['rememberMe']
+
+ if not fail:
+ del login_request['username']
+ del login_request['password']
+ del login_request['rememberMe']
+
continue
login_throttled = response.get('messagecode') == 'login-throttled'
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152397?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6c420c2f1d21adda4eb5be46078420e91bd044b2
Gerrit-Change-Number: 1152397
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Gergő Tisza <gtisza(a)wikimedia.org>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zache-tool <kimmo.virtanen(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152094?usp=email )
Change subject: IMPR: replace codecs.open() with open() or pathlib methods in interwiki.py
......................................................................
IMPR: replace codecs.open() with open() or pathlib methods in interwiki.py
Bug: T395187
Change-Id: Id8bf980a8f529907ffae8cd9798bc3844dd5fe18
---
M scripts/interwiki.py
1 file changed, 9 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index b19e0d1..eac17bd 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -343,18 +343,18 @@
``-continue`` next time.
"""
#
-# (C) Pywikibot team, 2003-2024
+# (C) Pywikibot team, 2003-2025
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
-import codecs
import os
import re
import sys
from collections import Counter, defaultdict
from contextlib import suppress
+from pathlib import Path
from textwrap import fill
import pywikibot
@@ -507,8 +507,8 @@
'Please enter the hint filename:')
# hint or title ends either before | or before ]]
R = re.compile(r'\[\[(.+?)(?:\]\]|\|)')
- with codecs.open(hintfilename, 'r', config.textfile_encoding) as f:
- self.hints += R.findall(f.read())
+ txt = Path(hintfilename).read_text(config.textfile_encoding)
+ self.hints += R.findall(txt)
elif arg == 'untranslatedonly':
self.untranslated = True
self.untranslatedonly = True
@@ -1009,9 +1009,8 @@
"""Report interwikiless page."""
self.conf.note(f'{self.origin} does not have any interwiki links')
if config.without_interwiki:
- with codecs.open(
- pywikibot.config.datafilepath('without_interwiki.txt'),
- 'a', 'utf-8') as f:
+ with open(pywikibot.config.datafilepath('without_interwiki.txt'),
+ 'a', encoding='utf-8') as f:
f.write(f'# {page} \n')
def askForHints(self, counter) -> None:
@@ -1189,9 +1188,9 @@
f'pages {duplicate} and {page} are found')
self.makeForcedStop(counter)
try:
- with codecs.open(
+ with open(
pywikibot.config.datafilepath('autonomous_problems.dat'),
- 'a', 'utf-8') as f:
+ 'a', encoding='utf-8') as f:
f.write(
f'* {self.origin} '
f'{{Found more than one link for {page.site}}}')
@@ -2227,7 +2226,7 @@
filename = os.path.join(self.path,
self.FILE_PATTERN.format(site=self.site))
mode = 'appended' if append else 'written'
- with codecs.open(filename, mode[0], 'utf-8') as f:
+ with open(filename, mode[0], encoding='utf-8') as f:
f.write('\r\n'.join(iterable))
f.write('\r\n')
pywikibot.info(
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152094?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id8bf980a8f529907ffae8cd9798bc3844dd5fe18
Gerrit-Change-Number: 1152094
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot