jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/633805 )
Change subject: [bugfix] accept only valid names in generate_family_file.py
......................................................................
[bugfix] accept only valid names in generate_family_file.py
- check name validity in generate_family_file.py
- rephrase error and warning messages in family.py
Bug: T265328
Bug: T265353
Change-Id: I60bc76888a1ae338eaedbe31b3af28718043b18e
---
M generate_family_file.py
M pywikibot/family.py
2 files changed, 29 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_family_file.py b/generate_family_file.py
index 3c4e1e4..770adb8 100755
--- a/generate_family_file.py
+++ b/generate_family_file.py
@@ -8,11 +8,19 @@
#
import codecs
import os
+import string
import sys
from os import environ, getenv
from urllib.parse import urlparse
+# see pywikibot.family.py
+# Legal characters for Family name and Family langs keys
+NAME_CHARACTERS = string.ascii_letters + string.digits
+# nds_nl code alias requires "_"n
+# dash must be the last char to be reused as regex in update_linktrails
+CODE_CHARACTERS = string.ascii_lowercase + string.digits + '_-'
+
class FamilyFileGenerator:
@@ -30,6 +38,11 @@
url = input('Please insert URL to wiki: ')
if name is None:
name = input('Please insert a short name (eg: freeciv): ')
+
+ assert all(x in NAME_CHARACTERS for x in name), \
+ 'Name of family {} must be ASCII letters and digits' \
+ '[a-zA-Z0-9]'.format(name)
+
self.dointerwiki = dointerwiki
self.base_url = url
self.name = name
@@ -91,6 +104,12 @@
if wiki['prefix'] in do_langs
or wiki['url'] == w.iwpath]
+ for wiki in self.langs:
+ assert all(x in CODE_CHARACTERS for x in wiki['prefix']), \
+ 'Family {} code {} must be ASCII lowercase ' \
+ 'letters and digits [a-z0-9] or underscore/dash [_-]' \
+ .format(self.name, wiki['prefix'])
+
def getapis(self):
"""Load other language pages."""
print('Loading wikis... ')
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 8a6be39..3e46804 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -691,7 +691,8 @@
fam = config.family
assert all(x in NAME_CHARACTERS for x in fam), \
- 'Name of family %s must be ASCII characters and digits' % fam
+ 'Name of family {} must be ASCII letters and digits [a-zA-Z0-9]' \
+ .format(fam)
if fam in Family._families:
return Family._families[fam]
@@ -720,14 +721,18 @@
if cls.name != fam:
warnings.warn('Family name {} does not match family module name {}'
.format(cls.name, fam), FamilyMaintenanceWarning)
- # Family 'name' and the 'langs' codes must be ascii, and the
- # codes must be lower-case due to the Site loading algorithm.
+ # Family 'name' and the 'langs' codes must be ascii letters and digits,
+ # and codes must be lower-case due to the Site loading algorithm;
+ # codes can accept also underscore/dash.
if not all(x in NAME_CHARACTERS for x in cls.name):
- warnings.warn('Family name {} contains non-ascii characters'
+ warnings.warn('Name of family {} must be ASCII letters '
+ 'and digits [a-zA-Z0-9]'
.format(cls.name), FamilyMaintenanceWarning)
for code in cls.langs.keys():
if not all(x in CODE_CHARACTERS for x in code):
- warnings.warn('Family {} code {} contains non-ascii characters'
+ warnings.warn('Family {} code {} must be ASCII lowercase '
+ 'letters and digits [a-z0-9] or '
+ 'underscore/dash [_-]'
.format(cls.name, code),
FamilyMaintenanceWarning)
Family._families[fam] = cls
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/633805
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I60bc76888a1ae338eaedbe31b3af28718043b18e
Gerrit-Change-Number: 633805
Gerrit-PatchSet: 2
Gerrit-Owner: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits