jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Normalize username
......................................................................
[FIX] Normalize username
This normalizes the username before site instantiation, so that the site
instances are all use the same username. It also further normalizes the
username for the password cache.
Bug: T73398
Change-Id: I4fd4cca7d65f07d83bf21659a8c10a52c54d7747
---
M pywikibot/__init__.py
M pywikibot/login.py
M pywikibot/site.py
M pywikibot/tools/__init__.py
4 files changed, 13 insertions(+), 14 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 53aaa13..d4b3081 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -598,6 +598,7 @@
if not issubclass(interface, pywikibot.site.BaseSite):
warning('Site called with interface=%s' % interface.__name__)
+ user = pywikibot.tools.normalize_username(user)
key = '%s:%s:%s:%s' % (interface.__name__, fam, code, user)
if key not in _sites or not isinstance(_sites[key], interface):
_sites[key] = interface(code=code, fam=fam, user=user, sysop=sysop)
diff --git a/pywikibot/login.py b/pywikibot/login.py
index 816378f..b2ace77 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -14,7 +14,7 @@
import pywikibot
from pywikibot import config
-from pywikibot.tools import deprecated_args
+from pywikibot.tools import deprecated_args, normalize_username
from pywikibot.exceptions import NoUsername
@@ -189,8 +189,7 @@
warn('The length of tuple should be 2 to 4 (%s given)'
% len(entry), _PasswordFileWarning)
continue
- username = entry[-2]
- username = username[0].upper() + username[1:]
+ username = normalize_username(entry[-2])
if len(entry) == 4: # for userinfo included code and family
if entry[0] == self.site.code and \
entry[1] == self.site.family.name and \
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 2f1cd0d..4bc67d7 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -32,7 +32,7 @@
from pywikibot.tools import (
itergroup, UnicodeMixin, ComparableMixin, SelfCallDict, SelfCallString,
deprecated, deprecate_arg, deprecated_args, remove_last_args,
- redirect_func, manage_wrapping, MediaWikiVersion,
+ redirect_func, manage_wrapping, MediaWikiVersion, normalize_username,
)
from pywikibot.throttle import Throttle
from pywikibot.data import api
@@ -536,16 +536,7 @@
% (self.__code, self.__family.name))
self.nocapitalize = self.code in self.family.nocapitalize
- if not self.nocapitalize:
- if user:
- user = user[0].upper() + user[1:]
- if sysop:
- sysop = sysop[0].upper() + sysop[1:]
- if user:
- user = user.replace('_', ' ')
- if sysop:
- sysop = sysop.replace('_', ' ')
- self._username = [user, sysop]
+ self._username = [normalize_username(user), normalize_username(sysop)]
self.use_hard_category_redirects = (
self.code in self.family.use_hard_category_redirects)
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 3a38dd5..1c879f2 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -241,6 +241,14 @@
raise AttributeError('%s.raw not set' % self.__class__.__name__)
+def normalize_username(username):
+ """Normalize the username."""
+ if not username:
+ return None
+ username = re.sub('[_ ]+', ' ', username).strip()
+ return username[0].upper() + username[1:]
+
+
class MediaWikiVersion(Version):
"""
--
To view, visit https://gerrit.wikimedia.org/r/190672
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4fd4cca7d65f07d83bf21659a8c10a52c54d7747
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits