From 66f024b515c435ccb9985f0528e34d6b06cec267 Mon Sep 17 00:00:00 2001 From: lann <lann@lannbox.com> Date: Thu, 10 Feb 2011 13:53:02 -0700 Subject: [PATCH] Add parameter_method argument to Client.__init__ and Client.request which forces a parameter transmission method --- oauth2/__init__.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index e5bd03de..1a846aba 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -597,7 +597,7 @@ class Client(httplib2.Http): """OAuthClient is a worker to attempt to execute a request.""" def __init__(self, consumer, token=None, cache=None, timeout=None, - proxy_info=None): + proxy_info=None, parameter_method=None): if consumer is not None and not isinstance(consumer, Consumer): raise ValueError("Invalid consumer.") @@ -608,6 +608,7 @@ def __init__(self, consumer, token=None, cache=None, timeout=None, self.consumer = consumer self.token = token self.method = SignatureMethod_HMAC_SHA1() + self.parameter_method = parameter_method httplib2.Http.__init__(self, cache=cache, timeout=timeout, proxy_info=proxy_info) @@ -618,7 +619,8 @@ def set_signature_method(self, method): self.method = method def request(self, uri, method="GET", body='', headers=None, - redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None): + redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None, + parameter_method=None): DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded' if not isinstance(headers, dict): @@ -651,12 +653,24 @@ def request(self, uri, method="GET", body='', headers=None, realm = schema + ':' + hierpart + host - if is_form_encoded: + parameter_method = parameter_method or self.parameter_method + + if parameter_method is None: + if is_form_encoded: + parameter_method = 'body' + elif method == "GET": + parameter_method = 'query' + else: + parameter_method = 'header' + + if parameter_method == 'header': + headers.update(req.to_header(realm=realm)) + elif parameter_method == 'body': body = req.to_postdata() - elif method == "GET": + elif parameter_method == 'query': uri = req.to_url() else: - headers.update(req.to_header(realm=realm)) + raise ValueError('Invalid parameter_method: %s' % parameter_method) return httplib2.Http.request(self, uri, method=method, body=body, headers=headers, redirections=redirections,