http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11600
Revision: 11600 Author: legoktm Date: 2013-05-31 03:30:35 +0000 (Fri, 31 May 2013) Log Message: ----------- Restructure ItemPage constructors: self.site is now always a DataSite object self.title() will always return the proper title on the site, which means it may require an API call
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 15:56:47 UTC (rev 11599) +++ branches/rewrite/pywikibot/page.py 2013-05-31 03:30:35 UTC (rev 11600) @@ -2220,13 +2220,16 @@ """ 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() - else: - self.repo = self.site.data_repository() + self.repo = self.site self._isredir = False # Wikibase pages cannot be a redirect
+ def title(self, **kwargs): + if self.namespace() == 0: + self._link._text = self.getID() + del self._link._title + return Page(self).title(**kwargs) + + def __defined_by(self, singular=False): """ returns the parameters needed by the API to identify an item. @@ -2251,14 +2254,13 @@ return params
#the rest only applies to ItemPages, but is still needed here. + if hasattr(self, '_site') and hasattr(self, '_title'): + params[site] = self._site.dbName() + params[title] = self._title + else: + quit() + params[id] = self.getID()
- if isinstance(self.site, pywikibot.site.DataSite): - params[id] = self.title(withNamespace=False) - elif isinstance(self.site, pywikibot.site.BaseSite): - params[site] = self.site.dbName() - params[title] = self.title() - else: - raise pywikibot.exceptions.BadTitle return params
def exists(self): @@ -2414,13 +2416,20 @@ site=pywikibot.Site & title=Main Page """ WikibasePage.__init__(self, site, title, ns=0) + self.id = title
@staticmethod def fromPage(page): """ Get the ItemPage based on a Page that links to it """ - return ItemPage(page.site, page.title()) + repo = page.site.data_repository() + i = ItemPage(repo, 'null') + del i.id + i._site = page.site + i._title = page.title() + return i + #return ItemPage(page.site, page.title())
def __make_site(self, dbname): """
Modified: branches/rewrite/tests/page_tests.py =================================================================== --- branches/rewrite/tests/page_tests.py 2013-05-30 15:56:47 UTC (rev 11599) +++ branches/rewrite/tests/page_tests.py 2013-05-31 03:30:35 UTC (rev 11600) @@ -281,12 +281,16 @@ repo = site.data_repository() item = pywikibot.ItemPage.fromPage(mainpage) self.assertType(item, pywikibot.ItemPage) - self.assertTrue(item.getID(), 'q5296') + self.assertEqual(item.getID(), 'q5296') + self.assertEqual(item.title(), 'Q5296') self.assertTrue('en' in item.labels) 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) + item2 = pywikibot.ItemPage(repo, 'q5296') + self.assertEqual(item2.getID(), 'q5296') + self.assertEqual(item.labels['en'], 'Main Page') prop = pywikibot.PropertyPage(repo, 'Property:P21') self.assertEqual(prop.getType(), 'wikibase-item') self.assertEqual(prop.namespace(), 120)
pywikipedia-svn@lists.wikimedia.org