jenkins-bot merged this change.

View Change

Approvals: D3r1ck01: Looks good to me, but someone else must approve Huji: Looks good to me, approved jenkins-bot: Verified
[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(-)

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):

To view, visit change 521026. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I51d77370808e79335002fa6843fb07de3bc4b69b
Gerrit-Change-Number: 521026
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Huji <huji.huji@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)