jenkins-bot has submitted this change and it was merged.
Change subject: add new methods for purging pages ......................................................................
add new methods for purging pages
Page.purge() and APISite.purgepages() also added a test
Change-Id: I5ee059907684440491ef4e675ffe231cbe100929 --- M pywikibot/page.py M pywikibot/site.py M tests/page_tests.py 3 files changed, 33 insertions(+), 0 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index f95b39b..539f4f6 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -944,6 +944,12 @@ """ return self.site.watchpage(self, unwatch)
+ def purge(self, **kwargs): + """Purge the server's cache for this page. + + """ + return self.site.purgepages([self], **kwargs) + def linkedPages(self, namespaces=None, step=None, total=None, content=False): """Iterate Pages that this Page links to. diff --git a/pywikibot/site.py b/pywikibot/site.py index 78196a5..93fce2f 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3196,6 +3196,32 @@ return ((unwatch and "unwatched" in watched) or (not unwatch and "watched" in result))
+ def purgepages(self, pages, **kwargs): + """Purge the server's cache for one or multiple pages. + + @param pages: list of Page objects + @return: True if API returned expected response; False otherwise + + """ + req = api.Request(site=self, action='purge') + req['titles'] = [page.title(withSection=False) for page in set(pages)] + linkupdate = False + linkupdate_args = ['forcelinkupdate', 'forcerecursivelinkupdate'] + for arg in kwargs: + if arg in linkupdate_args + ['redirects', 'converttitles']: + req[arg] = kwargs[arg] + if arg in linkupdate_args: + linkupdate = True + result = req.submit() + if 'purge' not in result: + pywikibot.error(u'purgepages: Unexpected API response:\n%s' % result) + return False + result = result['purge'] + purged = ['purged' in page for page in result] + if linkupdate: + purged += ['linkupdate' in page for page in result] + return all(purged) + @deprecated("Site().exturlusage") def linksearch(self, siteurl, limit=None): """Backwards-compatible interface to exturlusage()""" diff --git a/tests/page_tests.py b/tests/page_tests.py index d764f68..78740cf 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -243,6 +243,7 @@ self.assertType(mainpage.editTime(), pywikibot.Timestamp) self.assertType(mainpage.previousRevision(), int) self.assertType(mainpage.permalink(), basestring) + self.assertType(mainpage.purge(), bool)
def testIsDisambig(self): """
pywikibot-commits@lists.wikimedia.org