Skip to content

Commit

Permalink
Remove unicode references
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Mar 1, 2024
1 parent 7fb40e5 commit ff44fbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
11 changes: 4 additions & 7 deletions requests_oauthlib/oauth1_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
from oauthlib.common import extract_params
from oauthlib.oauth1 import Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER
from oauthlib.oauth1 import SIGNATURE_TYPE_BODY
from requests.compat import is_py3
from requests.utils import to_native_string
from requests.auth import AuthBase

CONTENT_TYPE_FORM_URLENCODED = "application/x-www-form-urlencoded"
CONTENT_TYPE_MULTI_PART = "multipart/form-data"

if is_py3:
unicode = str

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -83,7 +80,7 @@ def __call__(self, r):
or self.client.signature_type == SIGNATURE_TYPE_BODY
):
content_type = CONTENT_TYPE_FORM_URLENCODED
if not isinstance(content_type, unicode):
if not isinstance(content_type, str):
content_type = content_type.decode("utf-8")

is_form_encoded = CONTENT_TYPE_FORM_URLENCODED in content_type
Expand All @@ -96,17 +93,17 @@ def __call__(self, r):
if is_form_encoded:
r.headers["Content-Type"] = CONTENT_TYPE_FORM_URLENCODED
r.url, headers, r.body = self.client.sign(
unicode(r.url), unicode(r.method), r.body or "", r.headers
str(r.url), str(r.method), r.body or "", r.headers
)
elif self.force_include_body:
# To allow custom clients to work on non form encoded bodies.
r.url, headers, r.body = self.client.sign(
unicode(r.url), unicode(r.method), r.body or "", r.headers
str(r.url), str(r.method), r.body or "", r.headers
)
else:
# Omit body data in the signing of non form-encoded requests
r.url, headers, _ = self.client.sign(
unicode(r.url), unicode(r.method), None, r.headers
str(r.url), str(r.method), None, r.headers
)

r.prepare_headers(headers)
Expand Down
26 changes: 10 additions & 16 deletions tests/test_oauth1_session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import unicode_literals, print_function
import unittest
import sys
import requests
from io import StringIO

Expand All @@ -23,11 +22,6 @@
except ImportError:
jwt = None

if sys.version[0] == "3":
unicode_type = str
else:
unicode_type = unicode # noqa


TEST_RSA_KEY = (
"-----BEGIN RSA PRIVATE KEY-----\n"
Expand Down Expand Up @@ -165,17 +159,17 @@ def test_parse_response_url(self):
self.assertEqual(resp["oauth_token"], "foo")
self.assertEqual(resp["oauth_verifier"], "bar")
for k, v in resp.items():
self.assertIsInstance(k, unicode_type)
self.assertIsInstance(v, unicode_type)
self.assertIsInstance(k, str)
self.assertIsInstance(v, str)

def test_fetch_request_token(self):
auth = OAuth1Session("foo")
auth.send = self.fake_body("oauth_token=foo")
resp = auth.fetch_request_token("https://example.com/token")
self.assertEqual(resp["oauth_token"], "foo")
for k, v in resp.items():
self.assertIsInstance(k, unicode_type)
self.assertIsInstance(v, unicode_type)
self.assertIsInstance(k, str)
self.assertIsInstance(v, str)

def test_fetch_request_token_with_optional_arguments(self):
auth = OAuth1Session("foo")
Expand All @@ -185,17 +179,17 @@ def test_fetch_request_token_with_optional_arguments(self):
)
self.assertEqual(resp["oauth_token"], "foo")
for k, v in resp.items():
self.assertIsInstance(k, unicode_type)
self.assertIsInstance(v, unicode_type)
self.assertIsInstance(k, str)
self.assertIsInstance(v, str)

def test_fetch_access_token(self):
auth = OAuth1Session("foo", verifier="bar")
auth.send = self.fake_body("oauth_token=foo")
resp = auth.fetch_access_token("https://example.com/token")
self.assertEqual(resp["oauth_token"], "foo")
for k, v in resp.items():
self.assertIsInstance(k, unicode_type)
self.assertIsInstance(v, unicode_type)
self.assertIsInstance(k, str)
self.assertIsInstance(v, str)

def test_fetch_access_token_with_optional_arguments(self):
auth = OAuth1Session("foo", verifier="bar")
Expand All @@ -205,8 +199,8 @@ def test_fetch_access_token_with_optional_arguments(self):
)
self.assertEqual(resp["oauth_token"], "foo")
for k, v in resp.items():
self.assertIsInstance(k, unicode_type)
self.assertIsInstance(v, unicode_type)
self.assertIsInstance(k, str)
self.assertIsInstance(v, str)

def _test_fetch_access_token_raises_error(self, auth):
"""Assert that an error is being raised whenever there's no verifier
Expand Down

0 comments on commit ff44fbe

Please sign in to comment.