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)
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11276
Revision: 11276
Author: xqt
Date: 2013-03-25 23:55:40 +0000 (Mon, 25 Mar 2013)
Log Message:
-----------
Override _sites cache if instance does not match. This will solve the following:
>>> import pwb
>>> import pywikibot as wp
>>> s = wp.Site('wikidata', 'wikidata')
>>> s
Site("wikidata", "wikidata")
>>> s = wp.Site('wikidata', 'wikidata', interface='DataSite')
>>> s
DataSite("wikidata", "wikidata")
>>>
here the second instantation returns the right class whereas the previous cached object would be Site("wikidata", "wikidata")
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2013-03-25 19:09:07 UTC (rev 11275)
+++ branches/rewrite/pywikibot/__init__.py 2013-03-25 23:55:40 UTC (rev 11276)
@@ -168,7 +168,7 @@
except ImportError:
raise ValueError("Invalid interface name '%(interface)s'" % locals())
key = '%s:%s:%s' % (fam, code, user)
- if not key in _sites:
+ if not key in _sites or not isinstance(_sites[key], __Site):
_sites[key] = __Site(code=code, fam=fam, user=user, sysop=sysop)
pywikibot.debug(u"Instantiating Site object '%(site)s'"
% {'site': _sites[key]}, _logger)