http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11596
Revision: 11596 Author: legoktm Date: 2013-05-30 07:43:34 +0000 (Thu, 30 May 2013) Log Message: ----------- Fix namespaces for Wikibase objects
Modified Paths: -------------- branches/rewrite/pywikibot/page.py branches/rewrite/tests/page_tests.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2013-05-30 07:29:04 UTC (rev 11595) +++ branches/rewrite/pywikibot/page.py 2013-05-30 07:43:34 UTC (rev 11596) @@ -2218,8 +2218,8 @@ The base page for the Wikibase extension. There really should be no need to call this directly """ - def __init__(self, site, title=u""): - Page.__init__(self, site, title) + def __init__(self, site, title=u"", **kwargs): + Page.__init__(self, site, title, **kwargs) if isinstance(self.site, pywikibot.site.DataSite): self.repo = self.site self.id = self.title(withNamespace=False).lower() @@ -2413,7 +2413,7 @@ site=pywikibot.DataSite & title=Q42 site=pywikibot.Site & title=Main Page """ - WikibasePage.__init__(self, site, title) + WikibasePage.__init__(self, site, title, ns=0)
@staticmethod def fromPage(page): @@ -2549,7 +2549,7 @@ PropertyPage(DataSite, 'Property:P21') """ def __init__(self, source, title=u""): - WikibasePage.__init__(self, source, title) + WikibasePage.__init__(self, source, title, ns=120) self.id = self.title(withNamespace=False).lower() if not self.id.startswith(u'p'): raise ValueError(u"'%s' is not a property page!" % self.title()) @@ -2574,7 +2574,7 @@ For future usage, not implemented yet """ def __init__(self, site, title): - WikibasePage.__init__(self, site, title) + WikibasePage.__init__(self, site, title, ns=122) self.id = self.title(withNamespace=False).lower() if not self.id.startswith(u'u'): raise ValueError(u"'%s' is not a query page!" % self.title())
Modified: branches/rewrite/tests/page_tests.py =================================================================== --- branches/rewrite/tests/page_tests.py 2013-05-30 07:29:04 UTC (rev 11595) +++ branches/rewrite/tests/page_tests.py 2013-05-30 07:43:34 UTC (rev 11596) @@ -286,8 +286,10 @@ self.assertEqual(item.labels['en'], 'Main Page') self.assertTrue('en' in item.aliases) self.assertTrue('HomePage' in item.aliases['en']) + self.assertEqual(item.namespace(), 0) prop = pywikibot.PropertyPage(repo, 'Property:P21') self.assertEqual(prop.getType(), 'wikibase-item') + self.assertEqual(prop.namespace(), 120)
pywikipedia-svn@lists.wikimedia.org