http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11625
Revision: 11625 Author: valhallasw Date: 2013-06-08 19:55:59 +0000 (Sat, 08 Jun 2013) Log Message: ----------- Improved extensionability of ItemPage
* fromPage now returns the most specialised form in the class hieriarchy, e.g. MyItemPage.fromPage will return MyItemPage objects instead of ItemPage objects. (includes test)
* instead of using ParentClass.function, use super(ThisClass, self).function
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-06-07 23:51:26 UTC (rev 11624) +++ branches/rewrite/pywikibot/page.py 2013-06-08 19:55:59 UTC (rev 11625) @@ -2415,21 +2415,20 @@ site=pywikibot.DataSite & title=Q42 site=pywikibot.Site & title=Main Page """ - WikibasePage.__init__(self, site, title, ns=0) + super(ItemPage, self).__init__(site, title, ns=0) self.id = title
- @staticmethod - def fromPage(page): + @classmethod + def fromPage(cls, page): """ Get the ItemPage based on a Page that links to it """ repo = page.site.data_repository() - i = ItemPage(repo, 'null') + i = cls(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): """ @@ -2447,7 +2446,7 @@ args are the values of props """ if force or not hasattr(self, '_content'): - WikibasePage.get(self, force=force, *args) + super(ItemPage, self).get(force=force, *args)
#claims self.claims = {}
Modified: branches/rewrite/tests/page_tests.py =================================================================== --- branches/rewrite/tests/page_tests.py 2013-06-07 23:51:26 UTC (rev 11624) +++ branches/rewrite/tests/page_tests.py 2013-06-08 19:55:59 UTC (rev 11625) @@ -311,8 +311,11 @@ self.assertEqual(prop.getType(), 'wikibase-item') self.assertEqual(prop.namespace(), 120)
+ def testItemPageExtensionability(self): + class MyItemPage(pywikibot.ItemPage): + pass + self.assertIsInstance(MyItemPage.fromPage(mainpage), MyItemPage)
- # methods that still need tests implemented or expanded:
## def autoFormat(self):
pywikipedia-svn@lists.wikimedia.org