jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1319950?usp=email )
Change subject: APISite.blocks: Add show filters
......................................................................
APISite.blocks: Add show filters
Add account, ip, ip_range and temp keyword-only filters for the Blocks
API bkshow parameter. Use api.OptionSet to validate and serialize
positive and negative criteria.
Add regression coverage for empty, enabled and disabled filter values,
and add mahveotm to AUTHORS.rst.
Bug: T433531
Change-Id: Icb3037fe2266165e6d5cb9503c21ffe307051d12
---
M AUTHORS.rst
M pywikibot/site/_generators.py
M tests/site_generators_tests.py
3 files changed, 40 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/AUTHORS.rst b/AUTHORS.rst
index b85b625..a9f69ad 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -210,6 +210,7 @@
m4tx
Maarten Dammers
+ mahveotm
Marcin Cieslak
Matanya
marineznovo
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 4888478..7277e62 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -1264,6 +1264,11 @@
users: str | Iterable[str] | None = None,
iprange: str | None = None,
total: int | None = None,
+ *,
+ account: bool | None = None,
+ ip: bool | None = None,
+ ip_range: bool | None = None,
+ temp: bool | None = None,
) -> Iterable[dict[str, Any]]:
"""Iterate all current blocks, in order of creation.
@@ -1278,6 +1283,9 @@
.. warning::
``iprange`` parameter cannot be used together with ``users``.
+ .. version-changed:: 11.7
+ The *account*, *ip*, *ip_range* and *temp* parameters were added.
+
:param starttime: Start iterating at this Timestamp
:param endtime: Stop iterating at this Timestamp
:param reverse: If True, iterate oldest blocks first (default: newest)
@@ -1287,6 +1295,14 @@
:param iprange: A single IP or an IP range. Ranges broader than
IPv4/16 or IPv6/19 are not accepted.
:param total: Total amount of block entries
+ :param account: If ``True``, only iterate account blocks; if ``False``,
+ only iterate non-account blocks; if ``None``, iterate both.
+ :param ip: If ``True``, only iterate IP blocks; if ``False``, only
+ iterate non-IP blocks; if ``None``, iterate both.
+ :param ip_range: If ``True``, only iterate range blocks; if ``False``,
+ only iterate non-range blocks; if ``None``, iterate both.
+ :param temp: If ``True``, only iterate temporary blocks; if ``False``,
+ only iterate permanent blocks; if ``None``, iterate both.
"""
if starttime and endtime:
self.assert_valid_iter_params('blocks', starttime, endtime,
@@ -1314,6 +1330,14 @@
bkgen.request['bkusers'] = users
elif iprange:
bkgen.request['bkip'] = iprange
+ filters = {
+ 'account': account,
+ 'ip': ip,
+ 'range': ip_range,
+ 'temp': temp,
+ }
+ bkgen.request['bkshow'] = api.OptionSet(self, 'blocks', 'show',
+ filters)
return bkgen
def exturlusage(
diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py
index 0ef2ff6..7ea52ee 100755
--- a/tests/site_generators_tests.py
+++ b/tests/site_generators_tests.py
@@ -596,6 +596,21 @@
self.assertRaises(ValueError):
mysite.blocks(total=5, starttime=high, endtime=low, reverse=True)
+ def test_blocks_show(self) -> None:
+ """Test the site.blocks() show filter."""
+ mysite = self.get_site()
+
+ for filters, expected in (
+ ({}, []),
+ ({'ip': True, 'temp': False}, ['ip', '!temp']),
+ ({'account': False, 'ip_range': True}, ['!account', 'range']),
+ ):
+ with self.subTest(filters=filters):
+ generator = mysite.blocks(**filters)
+ options = generator.request['bkshow']
+ self.assertIsInstance(options, api.OptionSet)
+ self.assertCountEqual(options.api_iter(), expected)
+
def test_exturlusage(self) -> None:
"""Test the site.exturlusage() method."""
mysite = self.get_site()
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1319950?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icb3037fe2266165e6d5cb9503c21ffe307051d12
Gerrit-Change-Number: 1319950
Gerrit-PatchSet: 6
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]