jenkins-bot has submitted this change and it was merged.
Change subject: No KeyError when the family does not exist
......................................................................
No KeyError when the family does not exist
If the user has a username in user-config.py for a family
which does not exist, pywikibot will not load, failing in config2.py
with a KeyError.
This change silently accepts unknown values for the three dicts
which are pre-populated with family names:
- usernames
- sysopnames
- disambiguation_comment
Change-Id: I614096aa2396f8a0794225da4ffad891f20bf6ab
---
M pywikibot/config2.py
1 file changed, 10 insertions(+), 5 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index b021a05..0b04b5a 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -24,6 +24,7 @@
import os
import sys
+import collections
# Please keep _imported_modules in sync with the imports above
_imported_modules = ('os', 'sys')
@@ -71,9 +72,9 @@
# If you have a unique syop account for all languages of a family,
# you can use '*'
# sysopnames['myownwiki']['*'] = 'mySingleUsername'
-usernames = {}
-sysopnames = {}
-disambiguation_comment = {}
+usernames = collections.defaultdict(dict)
+sysopnames = collections.defaultdict(dict)
+disambiguation_comment = collections.defaultdict(dict)
# User agent format.
# For the meaning and more help in customization see:
@@ -220,6 +221,7 @@
if file_name.endswith("_family.py"):
family_name = file_name[:-len("_family.py")]
register_family_file(family_name, os.path.join(folder_path, file_name))
+
# Get the names of all known families, and initialize with empty dictionaries.
# ‘families/’ is a subdirectory of the directory in which config2.py is found.
@@ -722,8 +724,11 @@
_uc = {}
for _key, _val in _glv.items():
if isinstance(_val, dict):
- _uc[_key] = {}
- if len(_val.keys()) > 0:
+ if isinstance(_val, collections.defaultdict):
+ _uc[_key] = collections.defaultdict(dict)
+ else:
+ _uc[_key] = {}
+ if len(_val) > 0:
_uc[_key].update(_val)
else:
_uc[_key] = _val
--
To view, visit
https://gerrit.wikimedia.org/r/160203
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I614096aa2396f8a0794225da4ffad891f20bf6ab
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>