John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/172103

Change subject: api.py support for watchlistraw and v1.11 userinfo
......................................................................

api.py support for watchlistraw and v1.11 userinfo

list=watchlistraw and v1.11 meta=userinfo results are placed
in a different location in the JSON.  In order that QueryGenerator
and other clients of api.py Request can find the result without
replicating special handling, Request copies the data into the
expected location within the result dict.

Change-Id: Icaf01bd514b6f96a0f306d6ca2d46eb4d03cbcad
---
M pywikibot/data/api.py
1 file changed, 28 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/03/172103/1

diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index a685848..9d640a2 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -633,6 +633,34 @@
                                % type(result),
                                data=result)
             if self.action == 'query':
+                has_query = "query" in result
+                if not has_query:
+                    # This happens quite often, but is usually worth noticing.
+                    pywikibot.debug(
+                        u"%s: 'query' missing in api response of action=query."
+                        % self.__class__.__name__, _logger)
+
+                # There are two keys which can occur in the base of the result
+                # for a action=query result.
+                # 1. meta 'userinfo' appeared in v1.11 and only in that version
+                #    does the data optionally appear in the base of the query,
+                #    only if no other query data is in the response.
+                # 2. list 'watchlistraw' added v1.14 is the only remaining
+                #    instance of this issue in the API. (bug 34356)
+                #
+                # This class automatically copies these oddballs into the 
correct place
+                # in the query result dictionary, in order that tools like 
QueryGenerator
+                # do not need to look in two places.
+                for key in set(['userinfo', 'watchlistraw']) & set(result):
+                    pywikibot.debug(
+                        "%s: result key '%s' copied into result['query']."
+                        % (self.__class__.__name__, key), _logger)
+                    if has_query and key in result['query']:
+                        pywikibot.error(
+                            "Duplicate key '%s' found in query result." % key)
+                    else:
+                        result.setdefault('query', {})[key] = result[key]
+
                 if 'userinfo' in result.get('query', ()):
                     if hasattr(self.site, '_userinfo'):
                         self.site._userinfo.update(result['query']['userinfo'])

-- 
To view, visit https://gerrit.wikimedia.org/r/172103
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icaf01bd514b6f96a0f306d6ca2d46eb4d03cbcad
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to