Skip to content
Myr

vendored oauthlib

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 78d6d31 · Browse files · 2 files+30 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+30 added−9 removed

  • other:+30 added−9 removed

2 files+30 added−9 removed

added:requests/_oauth.py+23 added
1# -*- coding: utf-8 -*-23"""4requests._oauth5~~~~~~~~~~~~~~~67This module comtains the path hack neccesary for oauthlib to be vendored into requests8while allowing upstream changes.9"""1011import os12import sys1314try:15 from oauthlib.oauth1 import rfc584916 from oauthlib.common import extract_params17 from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)18except ImportError:19 path = os.path.abspath('/'.join(__file__.split('/')[:-1]+['packages']))20 sys.path.insert(0, path)21 from oauthlib.oauth1 import rfc584922 from oauthlib.common import extract_params23 from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)
modified:requests/auth.py+7 added-9 removed
15 unmodified lines
16from .compat import urlparse, str17from .utils import parse_dict_header1819try:20 from oauthlib.oauth1.rfc5849 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)21 from oauthlib.common import extract_params22 # hush pyflakes:23 SIGNATURE_HMAC; SIGNATURE_TYPE_AUTH_HEADER20 from ._oauth import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER, extract_params)2122except (ImportError, SyntaxError):23 SIGNATURE_HMAC = None24 SIGNATURE_TYPE_AUTH_HEADER = None25
40 unmodified lines
66 """67 contenttype = r.headers.get('Content-Type', None)68 # extract_params will not give params unless the body is a properly69 # formatted string, a dictionary or a list of 2-tuples.72 decoded_body = extract_params(r.data) 70 decoded_body = extract_params(r.data)71 if contenttype == None and decoded_body != None:72 # extract_params can only check the present r.data and does not know75 # of r.files, thus an extra check is performed. We know that 76 # if files are present the request will not have 73 # of r.files, thus an extra check is performed. We know that74 # if files are present the request will not have75 # Content-type: x-www-form-urlencoded. We guess it will have76 # a mimetype of multipart/form-encoded and if this is not the case77 # we assume the correct header will be set later.78 if r.files:79 # Omit body data in the signing and since it will always80 # be empty (cant add paras to body if multipart) and we wish83 # to preserve body. 81 # to preserve body.82 r.headers['Content-Type'] = 'multipart/form-encoded'83 r.url, r.headers, _ = self.client.sign(84 unicode(r.full_url), unicode(r.method), None, r.headers)85 else:
11 unmodified lines
97 # >>> d['a'] = 'foo'98 # >>> d99 # { u'a' : 'foo' }100 u_header = unicode('Authorization')103 if u_header in r.headers: 101 if u_header in r.headers:102 auth_header = r.headers[u_header].encode('utf-8')103 del r.headers[u_header]104 r.headers['Authorization'] = auth_header105
122 unmodified lines