jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] exclude expressions from parsed template in mwparserfromhell

- If using mwparserfromhell for textlib.extract_templates_and_params
function exclude expressions from parsed template
- Use ifilter_templates instead of creating a list
- Also require mwparserfromhell => 0.5 due to
fixed Wikicode.matches()'s behavior on iterables

Bug: T71384
Change-Id: I9fe9b80694db71a05a28e22a743a343b853ec1d7
---
M pywikibot/textlib.py
M requirements.txt
M setup.py
3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index c7e7fb6..204bd68 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1637,7 +1637,9 @@
code = mwparserfromhell.parse(text)
result = []

- for template in code.filter_templates(recursive=True):
+ for template in code.ifilter_templates(
+ matches=lambda x: not x.name.lstrip().startswith('#'),
+ recursive=True):
params = OrderedDict()
for param in template.params:
if strip:
diff --git a/requirements.txt b/requirements.txt
index de654f8..a1c915e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -34,15 +34,15 @@

# GUI
Pillow >= 6.2.2, < 8.0.0 ; python_version < '3.6'
-Pillow >= 6.2.2 ; python_version >= '3.6' and python_version < '3.9'
+Pillow >= 6.2.2 ; python_version >= '3.6' and python_version < '3.9'
Pillow >= 8.0.0 ; python_version >= '3.9'

# core pagegenerators
google >= 1.7
sseclient >= 0.0.18,!=0.0.23,!=0.0.24

-# textlib.py and patrol.py
-mwparserfromhell>=0.3.3
+# textlib.py
+mwparserfromhell>=0.5.0

# The mysql generator in pagegenerators depends on PyMySQL
PyMySQL
diff --git a/setup.py b/setup.py
index a8378f4..0aff894 100644
--- a/setup.py
+++ b/setup.py
@@ -60,7 +60,7 @@
'eventstreams': ['sseclient!=0.0.23,!=0.0.24,>=0.0.18'],
'isbn': ['python-stdnum>=1.16'],
'Google': ['google>=1.7'],
- 'mwparserfromhell': ['mwparserfromhell>=0.3.3'],
+ 'mwparserfromhell': ['mwparserfromhell>=0.5.0'],
'Tkinter': [ # vulnerability found in Pillow<6.2.2
'Pillow>=6.2.2,<8.0.0;python_version<"3.6"',
'Pillow>=6.2.2;python_version>="3.6" and python_version<"3.9"',

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9fe9b80694db71a05a28e22a743a343b853ec1d7
Gerrit-Change-Number: 675309
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: BenKurtovic <wikipedia.earwig@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Jean-Frédéric <jeanfrederic.wiki@gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa@wikimedia.se>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged