http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11582
Revision: 11582 Author: valhallasw Date: 2013-05-25 14:23:14 +0000 (Sat, 25 May 2013) Log Message: ----------- Add caching to Page.expand_text. Patch by David E. Narv?\195?\161ez ( dmaggot )
Modified Paths: -------------- branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2013-05-25 14:12:30 UTC (rev 11581) +++ branches/rewrite/pywikibot/page.py 2013-05-25 14:23:14 UTC (rev 11582) @@ -365,14 +365,16 @@ if hasattr(self, "_text"): del self._text
- def expand_text(self): + def expand_text(self, refresh=False): """Return the page text with all templates expanded.""" - req = pywikibot.data.api.Request(action="expandtemplates", - text=self.text, - title=self.title(withSection=False), - site=self.site) - result = req.submit() - return result["expandtemplates"]["*"] + if not hasattr(self, "_expanded_text") or (self._expanded_text is None) or refresh: + req = pywikibot.data.api.Request(action="expandtemplates", + text=self.text, + title=self.title(withSection=False), + site=self.site) + self._expanded_text = req.submit()["expandtemplates"]["*"] + + return self._expanded_text
def userName(self): """Return name or IP address of last user to edit page.
pywikipedia-svn@lists.wikimedia.org