summaryrefslogtreecommitdiff
path: root/oauthlib
diff options
context:
space:
mode:
authorDavid Gouldin <david@gould.in>2012-03-13 21:20:05 -0700
committerDavid Gouldin <david@gould.in>2012-03-13 21:20:05 -0700
commitdef8c87c7e41b9d83acf672387feb31cb37285e6 (patch)
tree0450d3e86aa6bed6f4dc8e07d9b569c09014230f /oauthlib
parent547b6095fb51f055d333310af96f8eb61de29807 (diff)
downloadoauthlib-def8c87c7e41b9d83acf672387feb31cb37285e6.tar.gz
Passing body to _contribute_parameters and prepare_form_encoded_body, normalizing utils import between modules, cleaning up parameters module 'prepare' functions a bit.
Diffstat (limited to 'oauthlib')
-rw-r--r--oauthlib/oauth.py10
-rw-r--r--oauthlib/parameters.py31
2 files changed, 21 insertions, 20 deletions
diff --git a/oauthlib/oauth.py b/oauthlib/oauth.py
index d4ae857..e0304f2 100644
--- a/oauthlib/oauth.py
+++ b/oauthlib/oauth.py
@@ -84,7 +84,7 @@ class OAuth1aClient(object):
return params
- def _contribute_parameters(self, uri, params):
+ def _contribute_parameters(self, uri, params, body=None):
if self.signature_type not in (SIGNATURE_TYPE_BODY,
SIGNATURE_TYPE_QUERY,
SIGNATURE_TYPE_AUTH_HEADER):
@@ -93,14 +93,14 @@ class OAuth1aClient(object):
# defaults
authorization_header = None
complete_uri = uri
- body = None
+ body = body
# Sign with the specified signature type
if self.signature_type == SIGNATURE_TYPE_AUTH_HEADER:
authorization_header = parameters.prepare_authorization_header(
params)
elif self.signature_type == SIGNATURE_TYPE_BODY:
- body = parameters.prepare_form_encoded_body(params)
+ body = parameters.prepare_form_encoded_body(params, body)
else: # self.signature_type == SIGNATURE_TYPE_QUERY:
complete_uri = parameters.prepare_request_uri_query(params, uri)
@@ -113,8 +113,8 @@ class OAuth1aClient(object):
# get the OAuth params and contribute them to either the uri or
# authorization header
params = self.get_oauth_params()
- complete_uri, authorization_header = self._contribute_parameters(uri,
- params)
+ complete_uri, authorization_header, body = self._contribute_parameters(uri,
+ params, body=body)
# use the new uri and authorization header to generate a signature and
# contribute that signature to the OAuth parameters
diff --git a/oauthlib/parameters.py b/oauthlib/parameters.py
index 721a910..27f7ccf 100644
--- a/oauthlib/parameters.py
+++ b/oauthlib/parameters.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
"""
oauthlib.parameters
@@ -10,8 +11,7 @@ This module contains methods related to `section 3.5`_ of the OAuth 1.0a spec.
"""
from urlparse import urlparse, urlunparse, parse_qsl
-from utils import filter_params, urlencode
-
+from . import utils
def order_params(target):
"""Decorator which reorders params contents to start with oauth_* params
@@ -48,7 +48,7 @@ def order_oauth_parameters(params):
return ordered
-@filter_params
+@utils.filter_params
def prepare_authorization_header(params, realm=None):
"""Prepare the Authorization header.
@@ -66,8 +66,14 @@ def prepare_authorization_header(params, realm=None):
return 'OAuth ' + ','.join(['='.join([k, v]) for k, v in params])
+def _add_params_to_qs(query, params):
+ queryparams = parse_qsl(query, True)
+ queryparams.extend(params)
+ queryparams.sort(key=lambda i: i[0].startswith('oauth_'))
+ return utils.urlencode(queryparams)
+
@order_params
-def prepare_form_encoded_body(params):
+def prepare_form_encoded_body(params, body):
"""Prepare the Form-Encoded Body.
Per `section 3.5.2`_ of the spec.
@@ -77,11 +83,12 @@ def prepare_form_encoded_body(params):
.. _`section 3.5.2`: http://tools.ietf.org/html/rfc5849#section-3.5.2
"""
- return urlencode(params)
+ # append OAuth params to the existing body
+ return _add_params_to_qs(body, params)
@order_params
-def prepare_request_uri_query(params, url):
+def prepare_request_uri_query(params, uri):
"""Prepare the Request URI Query.
Per `section 3.5.3`_ of the spec.
@@ -92,14 +99,8 @@ def prepare_request_uri_query(params, url):
.. _`section 3.5.3`: http://tools.ietf.org/html/rfc5849#section-3.5.3
"""
- # convert dict to list of tuples
- if isinstance(params, dict):
- params = params.items()
-
# append OAuth params to the existing set of query components
- sch, net, path, par, query, fra = urlparse(url)
- queryparams = parse_qsl(query, True)
- queryparams.extend(params)
- queryparams.sort(key=lambda i: i[0].startswith('oauth_'))
- query = urlencode(queryparams)
+ sch, net, path, par, query, fra = urlparse(uri)
+ query = _add_params_to_qs(query, params)
return urlunparse((sch, net, path, par, query, fra))
+