From a1fd038d2cc5ffe9a9a68bf37deec65ff5de64b3 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 28 Jun 2012 17:20:26 -0700 Subject: [PATCH] vendored oauthlib --- requests/_oauth.py | 23 +++++++++++++++++++++++ requests/auth.py | 16 +++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 requests/_oauth.py diff --git a/requests/_oauth.py b/requests/_oauth.py new file mode 100644 index 0000000..8f44bf5 --- /dev/null +++ b/requests/_oauth.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +""" +requests._oauth +~~~~~~~~~~~~~~~ + +This module comtains the path hack neccesary for oauthlib to be vendored into requests +while allowing upstream changes. +""" + +import os +import sys + +try: + from oauthlib.oauth1 import rfc5849 + from oauthlib.common import extract_params + from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER) +except ImportError: + path = os.path.abspath('/'.join(__file__.split('/')[:-1]+['packages'])) + sys.path.insert(0, path) + from oauthlib.oauth1 import rfc5849 + from oauthlib.common import extract_params + from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER) \ No newline at end of file diff --git a/requests/auth.py b/requests/auth.py index 2ae2703..0f98d28 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -17,10 +17,8 @@ from .compat import urlparse, str from .utils import parse_dict_header try: - from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER) - from oauthlib.common import extract_params - # hush pyflakes: - SIGNATURE_HMAC; SIGNATURE_TYPE_AUTH_HEADER + from ._oauth import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER, extract_params) + except (ImportError, SyntaxError): SIGNATURE_HMAC = None SIGNATURE_TYPE_AUTH_HEADER = None @@ -69,18 +67,18 @@ class OAuth1(AuthBase): contenttype = r.headers.get('Content-Type', None) # extract_params will not give params unless the body is a properly # formatted string, a dictionary or a list of 2-tuples. - decoded_body = extract_params(r.data) + decoded_body = extract_params(r.data) if contenttype == None and decoded_body != None: # extract_params can only check the present r.data and does not know - # of r.files, thus an extra check is performed. We know that - # if files are present the request will not have + # of r.files, thus an extra check is performed. We know that + # if files are present the request will not have # Content-type: x-www-form-urlencoded. We guess it will have # a mimetype of multipart/form-encoded and if this is not the case # we assume the correct header will be set later. if r.files: # Omit body data in the signing and since it will always # be empty (cant add paras to body if multipart) and we wish - # to preserve body. + # to preserve body. r.headers['Content-Type'] = 'multipart/form-encoded' r.url, r.headers, _ = self.client.sign( unicode(r.full_url), unicode(r.method), None, r.headers) @@ -100,7 +98,7 @@ class OAuth1(AuthBase): # >>> d # { u'a' : 'foo' } u_header = unicode('Authorization') - if u_header in r.headers: + if u_header in r.headers: auth_header = r.headers[u_header].encode('utf-8') del r.headers[u_header] r.headers['Authorization'] = auth_header -- 2.34.1