+ def tester(self, api_url):
+ """
+ Attempts to fetch general information about the MediaWiki instance
+ in order to test whether the given URL will return JSON.
+ """
+ data = self._fetch_http(api_url, {'action': 'query',
+ 'meta': 'siteinfo',
+ 'siprop': 'general',
+ 'format': 'json'})
+ try:
+ data_json = json.loads(data)
+ # may as well set the version
+ try:
+ version_string = data_json['query']['general']['generator']
+ self._mediawiki_version = version_string.split(' ', 1)[1]
+ except KeyError:
+ pass
+ return (data, data_json)
+ except ValueError:
+ return (data, None)
+
+ data, data_json = tester(self, self._api_url)