http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11201

Revision: 11201
Author:   legoktm
Date:     2013-03-09 16:37:12 +0000 (Sat, 09 Mar 2013)
Log Message:
-----------
Move API call in WikibasePage.get to DataSite.loadcontent
since API calls should be in site per comments on r11182.

Modified Paths:
--------------
    branches/rewrite/pywikibot/page.py
    branches/rewrite/pywikibot/site.py

Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py  2013-03-09 11:43:52 UTC (rev 11200)
+++ branches/rewrite/pywikibot/page.py  2013-03-09 16:37:12 UTC (rev 11201)
@@ -2227,17 +2227,9 @@
         args can be used to specify custom props.
         """
         if force or not hasattr(self, '_content'):
-            params = dict(**self.__defined_by())
-            params['action'] = 'wbgetentities'
-            if args:
-                params['props'] = '|'.join(args)
-                #print params
-            req = pywikibot.data.api.Request(site=self.repo, **params)
-            data = req.submit()
-            if not 'success' in data:
-                raise pywikibot.data.api.APIError, data['errors']
-            self.id = data['entities'].keys()[0]
-            self._content = data['entities'][self.id]
+            data = self.repo.loadcontent(self.__defined_by(), *args)
+            self.id = data.keys()[0]
+            self._content = data[self.id]
             self.lastrevid = self._content['lastrevid']
         #aliases
         self.aliases = {}

Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py  2013-03-09 11:43:52 UTC (rev 11200)
+++ branches/rewrite/pywikibot/site.py  2013-03-09 16:37:12 UTC (rev 11201)
@@ -3312,6 +3312,27 @@
             # not implemented yet
             raise NotImplementedError
 
+    def loadcontent(self, identification, *props):
+        """
+        This is called loadcontent since
+        wbgetentities does not support fetching old
+        revisions. Eventually this will get replaced by
+        an actual loadrevisions.
+        @param identification Parameters used to identify the page(s)
+        @type identification dict
+        @param props the optional properties to fetch.
+        """
+        params = dict(**identification)
+        params['action'] = 'wbgetentities'
+        if props:
+            params['props'] = '|'.join(props)
+        req = api.Request(site=self, **params)
+        data = req.submit()
+        if not 'success' in data:
+            raise pywikibot.data.api.APIError, data['errors']
+        return data['entities']
+
+
     # deprecated BaseSite methods
     def fam(self):
         raise NotImplementedError


_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to