Xqt has submitted this change and it was merged.
Change subject: api.PropertyGenerator: count queried items query and not only pages
......................................................................
api.PropertyGenerator: count queried items query and not only pages
Improvement of fix for:
https://sourceforge.net/support/tracker.php?aid=3569058
See also:
https://www.mediawiki.org/wiki/Special:Code/pywikipedia/10647
Change-Id: I80219732da947883f4b204c039d867996c26b37a
---
M pywikibot/data/api.py
M pywikibot/site.py
M tests/site_tests.py
3 files changed, 36 insertions(+), 3 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index a502d35..155a615 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -718,7 +718,16 @@
self.normalized = {}
for item in resultdata:
yield self.result(item)
- count += 1
+ if isinstance(item, dict) and set(self.continuekey) &
set(item.keys()):
+ # if we need to count elements contained in items in
+ # self.data["query"]["pages"], we want to
count
+ # item[self.continuekey] (e.g. 'revisions') and not
+ # self.resultkey (i.e. 'pages')
+ for key in set(self.continuekey) & set(item.keys()):
+ count += len(item[key])
+ # otherwise we proceed as usual
+ else:
+ count += 1
if self.limit > 0 and count >= self.limit:
return
if self.module == "random" and self.limit:
diff --git a/pywikibot/site.py b/pywikibot/site.py
index c5c9651..e3b505b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1943,7 +1943,6 @@
elif excludeuser:
rvgen.request[u"rvexcludeuser"] = excludeuser
# TODO if sysop: something
- rvgen.continuekey = "revisions"
for pagedata in rvgen:
if page is not None:
if not self.sametitle(pagedata['title'],
@@ -1956,7 +1955,6 @@
else:
page = pywikibot.Page(self, pagedata['title'])
api.update_page(page, pagedata)
- break
def pageinterwiki(self, page):
# No such function in the API (this method isn't called anywhere)
diff --git a/tests/site_tests.py b/tests/site_tests.py
index aed5620..8b8498e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -964,6 +964,26 @@
self.assertFalse(mysite.hasExtension('anything', False))
del mysite._extensions
+ def test_API_limits_with_site_methods(self):
+ # test step/total parameters for different sitemethods
+ mypage = pywikibot.Page(mysite, 'Albert Einstein')
+ mycat = pywikibot.Page(mysite, 'Category:1879 births')
+
+ cats = [c for c in mysite.pagecategories(mypage, step=5, total=12)]
+ self.assertEqual(len(cats), 12)
+
+ cat_members = [cm for cm in mysite.categorymembers(mycat, step=5, total=12)]
+ self.assertEqual(len(cat_members), 12)
+
+ images = [im for im in mysite.pageimages(mypage, step=3, total=5)]
+ self.assertEqual(len(images), 5)
+
+ templates = [tl for tl in mysite.pagetemplates(mypage, step=3, total=5)]
+ self.assertEqual(len(templates), 5)
+
+ mysite.loadrevisions(mypage, step=5, total=12)
+ self.assertEqual(len(mypage._revisions), 12)
+
class TestSiteLoadRevisions(PywikibotTestCase):
"""Test cases for Site.loadrevision() method."""
@@ -984,6 +1004,12 @@
self.assertTrue(self.mainpage._revid in self.mainpage._revisions)
self.assertEqual(len(self.mainpage._revisions), 15)
+ def testLoadRevisions_querycontinue(self):
+ """Test the site.loadrevisions() method with
query-continue"""
+
+ self.mysite.loadrevisions(self.mainpage, step=5, total=12)
+ self.assertEqual(len(self.mainpage._revisions), 12)
+
def testLoadRevisions_revdir(self):
"""Test the site.loadrevisions() method with
rvdir=True"""
--
To view, visit
https://gerrit.wikimedia.org/r/105522
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I80219732da947883f4b204c039d867996c26b37a
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Yurik <yurik(a)wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>