vendored oauthlib
authorKenneth Reitz <me@kennethreitz.com>
Fri, 29 Jun 2012 00:20:26 +0000 (17:20 -0700)
committerKenneth Reitz <me@kennethreitz.com>
Fri, 29 Jun 2012 00:20:26 +0000 (17:20 -0700)
requests/_oauth.py [new file with mode: 0644]
requests/auth.py

diff --git a/requests/_oauth.py b/requests/_oauth.py
new file mode 100644 (file)
index 0000000..8f44bf5
--- /dev/null
@@ -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
index 2ae2703156a03323847cbeb9af1287edca6fa704..0f98d28eed282149032c089f59257a4649e11376 100644 (file)
@@ -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