jenkins-bot has submitted this change and it was merged.

Change subject: Normalize usernames in password file
......................................................................


Normalize usernames in password file

Capitalize the first letter of username in password file when used according to
Wikipedia username policy. Warn if the format of tuple in password file is not
correct.

Bug: T74974
Change-Id: I2035bf03bad62f6f505b2a9129758c2cc4f6b5ce
---
M pywikibot/exceptions.py
M pywikibot/login.py
2 files changed, 27 insertions(+), 5 deletions(-)

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



diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 3bb6a7a..2a8105f 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -57,6 +57,7 @@
 
 UserWarning: warnings targetted at users
   - config2._ConfigurationDeprecationWarning: user configuration file problems
+  - login._PasswordFileWarning: password file problems
   - ArgumentDeprecationWarning: command line argument problems
   - FamilyMaintenanceWarning: missing information in family definition
 """
diff --git a/pywikibot/login.py b/pywikibot/login.py
index db7be8f..816378f 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -3,18 +3,27 @@
 """Library to log the bot in to a wiki account."""
 #
 # (C) Rob W.W. Hooft, 2003
-# (C) Pywikibot team, 2003-2012
+# (C) Pywikibot team, 2003-2015
 #
 # Distributed under the terms of the MIT license.
 #
 __version__ = '$Id$'
 #
 import codecs
+from warnings import warn
 
 import pywikibot
 from pywikibot import config
 from pywikibot.tools import deprecated_args
 from pywikibot.exceptions import NoUsername
+
+
+class _PasswordFileWarning(UserWarning):
+
+    """The format of password file is incorrect."""
+
+    pass
+
 
 _logger = "wiki.login"
 
@@ -169,18 +178,30 @@
         for line in password_f:
             if not line.strip():
                 continue
-            entry = eval(line)
+            try:
+                entry = eval(line)
+            except SyntaxError:
+                entry = None
+            if type(entry) is not tuple:
+                warn('Invalid tuple', _PasswordFileWarning)
+                continue
+            if not 2 <= len(entry) <= 4:
+                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:]
             if len(entry) == 4:         # for userinfo included code and family
                 if entry[0] == self.site.code and \
                    entry[1] == self.site.family.name and \
-                   entry[2] == self.username:
+                   username == self.username:
                     self.password = entry[3]
             elif len(entry) == 3:       # for userinfo included family
                 if entry[0] == self.site.family.name and \
-                   entry[1] == self.username:
+                   username == self.username:
                     self.password = entry[2]
             elif len(entry) == 2:       # for default userinfo
-                if entry[0] == self.username:
+                if username == self.username:
                     self.password = entry[1]
         password_f.close()
 

-- 
To view, visit https://gerrit.wikimedia.org/r/190638
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2035bf03bad62f6f505b2a9129758c2cc4f6b5ce
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: VcamX <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: VcamX <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to