jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/521026 )
Change subject: [IMPR] Simplify templateRegex in _MultiTemplateMatchBuilder ......................................................................
[IMPR] Simplify templateRegex in _MultiTemplateMatchBuilder
- re-use _ignore_case function - add magic word 'msg' to the namespaces list - use a dict for format string replacements
Change-Id: I51d77370808e79335002fa6843fb07de3bc4b69b --- M pywikibot/textlib.py 1 file changed, 6 insertions(+), 7 deletions(-)
Approvals: D3r1ck01: Looks good to me, but someone else must approve Huji: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 4c037ee..94f91f4 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -218,14 +218,13 @@ else: pattern = re.escape(old) # namespaces may be any mixed case - namespaces = [''.join('[{0}{1}]'.format(char.upper(), char.lower()) - for char in ns) - for ns in namespace] + namespaces = [_ignore_case(ns) for ns in namespace] + namespaces.append(_ignore_case('msg')) pattern = re.sub(r'_|\ ', r'[_ ]', pattern) - templateRegex = re.compile(r'{{ *(' + ':|'.join(namespaces) - + r':|[mM][sS][gG]:)?' + pattern - + r'(?P<parameters>\s*|.+?|) *}}', - flags) + templateRegex = re.compile( + r'{{ *(%(namespace)s:)?%(pattern)s(?P<parameters>\s*|.+?|) *}}' + % {'namespace': ':|'.join(namespaces), 'pattern': pattern}, + flags) return templateRegex
def search_any_predicate(self, templates):
pywikibot-commits@lists.wikimedia.org