http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10328
Revision: 10328 Author: xqt Date: 2012-06-08 14:03:58 +0000 (Fri, 08 Jun 2012) Log Message: ----------- use getter, setter, deleter properties enable None assignment to Page.text which is a bit similar to discard changes (as well as del does) and not to assign "None" text. python 2.6 is needed for the properties
Modified Paths: -------------- branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2012-06-08 12:39:36 UTC (rev 10327) +++ branches/rewrite/pywikibot/page.py 2012-06-08 14:03:58 UTC (rev 10328) @@ -3,7 +3,7 @@ Objects representing various types of MediaWiki pages. """ # -# (C) Pywikipedia bot team, 2008-2011 +# (C) Pywikipedia bot team, 2008-2012 # # Distributed under the terms of the MIT license. # @@ -329,7 +329,8 @@ self.site.loadrevisions(self) return self._revid
- def _textgetter(self): + @property + def text(self): """Return the current (edited) wikitext, loading it if necessary.""" if not hasattr(self, '_text') or self._text is None: try: @@ -339,18 +340,17 @@ self._text = u"" return self._text
- def _textsetter(self, value): + @text.setter + def text(self, value): """Update the edited wikitext""" - self._text = unicode(value) + self._text = None if value is None else unicode(value)
- def _cleartext(self): + @text.deleter + def text(self): """Delete the edited wikitext""" if hasattr(self, "_text"): del self._text
- text = property(_textgetter, _textsetter, _cleartext, - "The edited wikitext (unicode) of this Page") - def expand_text(self): """Return the page text with all templates expanded.""" req = pywikibot.data.api.Request(action="expandtemplates",