Skip to content

Instantly share code, notes, and snippets.

@nberger-git
Created September 21, 2015 17:27
Show Gist options
  • Save nberger-git/7fa9bc527c21a11caba2 to your computer and use it in GitHub Desktop.
Save nberger-git/7fa9bc527c21a11caba2 to your computer and use it in GitHub Desktop.
--- api-bak.py 2015-09-12 19:43:15.000000000 +0200
+++ api.py 2015-09-21 19:08:16.262108348 +0200
@@ -50,7 +50,7 @@ class APIDisabled(APIError):
class APIRequest:
"""A request to the site's API"""
- def __init__(self, wiki, data, write=False, multipart=False):
+ def __init__(self, wiki, data, write=False, multipart=False, getrequest=False):
"""
wiki - A Wiki object
data - API parameters in the form of a dict
@@ -95,8 +95,13 @@ class APIRequest:
self.opener = urllib2.build_opener(urllib2.HTTPDigestAuthHandler(wiki.passman), urllib2.HTTPCookieProcessor(wiki.cookies))
else:
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(wiki.cookies))
- self.request = urllib2.Request(self.wiki.apibase, self.encodeddata, self.headers)
-
+ if getrequest:
+ self.request = urllib2.Request(self.wiki.apibase + '?' + self.encodeddata, None, self.headers)
+ else:
+ self.request = urllib2.Request(self.wiki.apibase, self.encodeddata, self.headers)
+ print 'xxx', self.request.get_type(), self.request.get_method(), self.request.get_host(), self.request.get_data()
+ print 'xx2', self.request.get_full_url()
+
def setMultipart(self, multipart=True):
"""Enable multipart data transfer, required for file uploads."""
if not canupload and multipart:
--- page-bak.py 2015-09-12 19:43:15.000000000 +0200
+++ page.py 2015-09-21 19:06:49.246895155 +0200
@@ -307,7 +307,7 @@ class Page(object):
newname = pagename
return Page(self.site, newname, check, followRedir)
- def getWikiText(self, expandtemplates=False, force=False):
+ def getWikiText(self, expandtemplates=False, force=False, getrequest=False):
"""Gets the Wikitext of the page
expandtemplates - expand the templates to wikitext instead of transclusions
@@ -335,7 +335,7 @@ class Page(object):
params['rvexpandtemplates'] = '1'
if self.section is not False:
params['rvsection'] = self.section
- req = api.APIRequest(self.site, params)
+ req = api.APIRequest(self.site, params, getrequest=getrequest)
response = req.query(False)
if self.pageid == 0:
self.pageid = int(response['query']['pages'].keys()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment