jenkins-bot merged this change.
[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.