http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11279
Revision: 11279 Author: legoktm Date: 2013-03-28 10:18:54 +0000 (Thu, 28 Mar 2013) Log Message: ----------- Add in type validation to claims, set Wikibase.isRedirectPage() to false by default.
Modified Paths: -------------- branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2013-03-28 03:06:53 UTC (rev 11278) +++ branches/rewrite/pywikibot/page.py 2013-03-28 10:18:54 UTC (rev 11279) @@ -2197,6 +2197,7 @@ self.id = self.title(withNamespace=False).lower() else: self.repo = self.site.data_repository() + self._isredir = False # Wikibase pages cannot be a redirect
def __defined_by(self): """ @@ -2586,6 +2587,14 @@ Sets the target to the passed value. There should be checks to ensure type compliance """ + types = {'wikibase-item': ItemPage, + 'string': basestring, + 'commonsMedia': ImagePage, + } + if self.getType() in types: + if not isinstance(value, types[self.getType()]): + raise ValueError("%s is not type %s." + % (value, str(types[self.getType()]))) self.target = value
def changeTarget(self, value=None, snaktype='value', **kwargs): @@ -2593,7 +2602,7 @@ This actually saves the new target. """ if value: - self.target = value + self.setTarget(value)
data = self.repo.changeClaimTarget(self, snaktype=snaktype, **kwargs)
pywikipedia-svn@lists.wikimedia.org