Example #1
0
    def _request(self, token, method, url, data={}, headers={}, files={},
                 **kw):
        parameters = data_keys(data)
        parameters.update(kw)

        request = oauth.Request.from_consumer_and_token(
            self.get_consumer(), token, method, url, parameters)
        request.sign_request(self.signature_method, self.get_consumer(), token)

        headers = headers.copy()
        params = {}

        if method == 'GET':
            assert not (data or kw or files)
            url = request.to_url()

        elif method == 'POST':
            if files:
                headers.update(request.to_header())
                params.update({'files': files,
                               'params': parameters})
            elif False:
                headers.update(request.to_header())
                params['data'] = parameters
            else:
                headers['Content-Type'] = 'application/x-www-form-urlencoded'
                params['data'] = request.to_postdata()

        else:
            raise ValueError()

        return requests.request(method, url, headers=headers,
                                allow_redirects=False, **params)
Example #2
0
 def _request(self, token, method, url, data={}, headers={}, **kw):
     parameters = data_keys(data)
     parameters.update(kw)
     request = (oauth.Request
                     .from_consumer_and_token(self.get_consumer(), token,
                                              method, url, parameters))
     request.sign_request(self.signature_method, self.get_consumer(), token)
     client = httplib2.Http()
     if data and method in ['POST', 'PUT']:
         data = encode_multipart(boundary, data)
         headers.update({'Content-Type':
                         'multipart/form-data; boundary=%s' % boundary})
     else:
         data = urllib.urlencode(data)
     return client.request(request.to_url(), method=method,
                           headers=headers, body=data)
Example #3
0
    def _request(self,
                 token,
                 method,
                 url,
                 data={},
                 headers={},
                 files={},
                 **kw):
        parameters = data_keys(data)
        parameters.update(kw)

        request = oauth.Request.from_consumer_and_token(
            self.get_consumer(), token, method, url, parameters)
        request.sign_request(self.signature_method, self.get_consumer(), token)

        headers = headers.copy()
        params = {}

        if method == 'GET':
            assert not (data or kw or files)
            url = request.to_url()

        elif method == 'POST':
            if files:
                headers.update(request.to_header())
                params.update({'files': files, 'params': parameters})
            elif False:
                headers.update(request.to_header())
                params['data'] = parameters
            else:
                headers['Content-Type'] = 'application/x-www-form-urlencoded'
                params['data'] = request.to_postdata()

        else:
            raise ValueError()

        return requests.request(method,
                                url,
                                headers=headers,
                                allow_redirects=False,
                                **params)