Created
September 25, 2015 07:18
-
-
Save nberger-git/77f1d8091987eaa19c53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- api-bak.py 2015-09-12 19:43:15.000000000 +0200 | |
+++ api.py 2015-09-25 09:16:10.602428225 +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 | |
@@ -79,10 +79,8 @@ class APIRequest: | |
self.encodeddata = self.encodeddata + singledata | |
else: | |
self.encodeddata = urlencode(self.data, 1) | |
- self.headers = { | |
- "Content-Type": "application/x-www-form-urlencoded", | |
- "Content-Length": str(len(self.encodeddata)) | |
- } | |
+ self.headers = { "Content-Type": "application/x-www-form-urlencoded" } | |
+ if not getrequest : self.headers["Content-Length"] = str(len(self.encodeddata)) | |
self.headers["User-agent"] = wiki.useragent | |
if gzip: | |
self.headers['Accept-Encoding'] = 'gzip' | |
@@ -95,8 +93,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: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment