[MediaWiki-commits] [Gerrit] No KeyError when the family does not exist - change (pywikibot/core)
John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/160203 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, 9 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/03/160203/1 diff --git a/pywikibot/config2.py b/pywikibot/config2.py index b021a05..7b3c0e4 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. @@ -721,8 +723,11 @@ # we can detect modified config items easily. _uc = {} for _key, _val in _glv.items(): -if isinstance(_val, dict): +if isinstance(_val, collections.defaultdict): +_uc[_key] = collections.defaultdict(dict) +elif isinstance(_val, dict): _uc[_key] = {} +if isinstance(_val, dict): if len(_val.keys()) 0: _uc[_key].update(_val) else: -- To view, visit https://gerrit.wikimedia.org/r/160203 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I614096aa2396f8a0794225da4ffad891f20bf6ab Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg jay...@gmail.com ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] No KeyError when the family does not exist - change (pywikibot/core)
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 jay...@gmail.com Gerrit-Reviewer: John Vandenberg jay...@gmail.com Gerrit-Reviewer: Ladsgroup ladsgr...@gmail.com Gerrit-Reviewer: Merlijn van Deen valhall...@arctus.nl Gerrit-Reviewer: Mpaa mpaa.w...@gmail.com Gerrit-Reviewer: jenkins-bot ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits