From 38475ddcbe080d3d5c0aa17bb7dd1af170e3a7dc Mon Sep 17 00:00:00 2001 From: Jason Skicewicz Date: Tue, 8 Mar 2011 11:50:06 -1000 Subject: [PATCH 1/3] Added a parameters keyword argument to the Client method request() so that the oauth_callback parameter can easily be added to the initial token request as required by OAuth 1.0a. This also let django-piston 0.3 work correctly with python-oauth2 sample clients. --- oauth2/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 835270e3..981d85f6 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -637,7 +637,7 @@ 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, parameters={}): DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded' if not isinstance(headers, dict): @@ -650,10 +650,9 @@ def request(self, uri, method="GET", body='', headers=None, is_form_encoded = \ headers.get('Content-Type') == 'application/x-www-form-urlencoded' + parameters = parameters or {} if is_form_encoded and body: - parameters = parse_qs(body) - else: - parameters = None + parameters.update(parse_qs(body)) req = Request.from_consumer_and_token(self.consumer, token=self.token, http_method=method, http_url=uri, From c9ab67b3de2102ad3485b0d0c14d8a3e49c71596 Mon Sep 17 00:00:00 2001 From: Jason Skicewicz Date: Tue, 8 Mar 2011 12:08:24 -1000 Subject: [PATCH 2/3] Protected the parameters input in Client.request() to default to a dectionary. Before, any object could be passed in and could bork the update() if is_form_encoded and body exists. --- oauth2/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 981d85f6..59cb9153 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -650,7 +650,9 @@ def request(self, uri, method="GET", body='', headers=None, is_form_encoded = \ headers.get('Content-Type') == 'application/x-www-form-urlencoded' - parameters = parameters or {} + if not isinstance(parameters, dict): + parameters = {} + if is_form_encoded and body: parameters.update(parse_qs(body)) From c9975d241f3359fd9a2eb28db1fb979b8c219a13 Mon Sep 17 00:00:00 2001 From: Jason Skicewicz Date: Tue, 8 Mar 2011 13:29:43 -1000 Subject: [PATCH 3/3] Fixed the unit tests so that all tests now pass. --- oauth2/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 59cb9153..a92083e2 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -637,7 +637,7 @@ 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, parameters={}): + redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None, extra_parameters={}): DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded' if not isinstance(headers, dict): @@ -650,11 +650,13 @@ def request(self, uri, method="GET", body='', headers=None, is_form_encoded = \ headers.get('Content-Type') == 'application/x-www-form-urlencoded' - if not isinstance(parameters, dict): + if is_form_encoded and body: + parameters = parse_qs(body) + else: parameters = {} - if is_form_encoded and body: - parameters.update(parse_qs(body)) + if extra_parameters and isinstance(extra_parameters, dict): + parameters.update(extra_parameters) req = Request.from_consumer_and_token(self.consumer, token=self.token, http_method=method, http_url=uri,