Skip to content

Commit ff44fbe

Browse files
committed
Remove unicode references
1 parent 7fb40e5 commit ff44fbe

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

requests_oauthlib/oauth1_auth.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
from oauthlib.common import extract_params
77
from oauthlib.oauth1 import Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER
88
from oauthlib.oauth1 import SIGNATURE_TYPE_BODY
9-
from requests.compat import is_py3
109
from requests.utils import to_native_string
1110
from requests.auth import AuthBase
1211

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

16-
if is_py3:
17-
unicode = str
1815

1916
log = logging.getLogger(__name__)
2017

@@ -83,7 +80,7 @@ def __call__(self, r):
8380
or self.client.signature_type == SIGNATURE_TYPE_BODY
8481
):
8582
content_type = CONTENT_TYPE_FORM_URLENCODED
86-
if not isinstance(content_type, unicode):
83+
if not isinstance(content_type, str):
8784
content_type = content_type.decode("utf-8")
8885

8986
is_form_encoded = CONTENT_TYPE_FORM_URLENCODED in content_type
@@ -96,17 +93,17 @@ def __call__(self, r):
9693
if is_form_encoded:
9794
r.headers["Content-Type"] = CONTENT_TYPE_FORM_URLENCODED
9895
r.url, headers, r.body = self.client.sign(
99-
unicode(r.url), unicode(r.method), r.body or "", r.headers
96+
str(r.url), str(r.method), r.body or "", r.headers
10097
)
10198
elif self.force_include_body:
10299
# To allow custom clients to work on non form encoded bodies.
103100
r.url, headers, r.body = self.client.sign(
104-
unicode(r.url), unicode(r.method), r.body or "", r.headers
101+
str(r.url), str(r.method), r.body or "", r.headers
105102
)
106103
else:
107104
# Omit body data in the signing of non form-encoded requests
108105
r.url, headers, _ = self.client.sign(
109-
unicode(r.url), unicode(r.method), None, r.headers
106+
str(r.url), str(r.method), None, r.headers
110107
)
111108

112109
r.prepare_headers(headers)

tests/test_oauth1_session.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import unicode_literals, print_function
22
import unittest
3-
import sys
43
import requests
54
from io import StringIO
65

@@ -23,11 +22,6 @@
2322
except ImportError:
2423
jwt = None
2524

26-
if sys.version[0] == "3":
27-
unicode_type = str
28-
else:
29-
unicode_type = unicode # noqa
30-
3125

3226
TEST_RSA_KEY = (
3327
"-----BEGIN RSA PRIVATE KEY-----\n"
@@ -165,17 +159,17 @@ def test_parse_response_url(self):
165159
self.assertEqual(resp["oauth_token"], "foo")
166160
self.assertEqual(resp["oauth_verifier"], "bar")
167161
for k, v in resp.items():
168-
self.assertIsInstance(k, unicode_type)
169-
self.assertIsInstance(v, unicode_type)
162+
self.assertIsInstance(k, str)
163+
self.assertIsInstance(v, str)
170164

171165
def test_fetch_request_token(self):
172166
auth = OAuth1Session("foo")
173167
auth.send = self.fake_body("oauth_token=foo")
174168
resp = auth.fetch_request_token("https://example.com/token")
175169
self.assertEqual(resp["oauth_token"], "foo")
176170
for k, v in resp.items():
177-
self.assertIsInstance(k, unicode_type)
178-
self.assertIsInstance(v, unicode_type)
171+
self.assertIsInstance(k, str)
172+
self.assertIsInstance(v, str)
179173

180174
def test_fetch_request_token_with_optional_arguments(self):
181175
auth = OAuth1Session("foo")
@@ -185,17 +179,17 @@ def test_fetch_request_token_with_optional_arguments(self):
185179
)
186180
self.assertEqual(resp["oauth_token"], "foo")
187181
for k, v in resp.items():
188-
self.assertIsInstance(k, unicode_type)
189-
self.assertIsInstance(v, unicode_type)
182+
self.assertIsInstance(k, str)
183+
self.assertIsInstance(v, str)
190184

191185
def test_fetch_access_token(self):
192186
auth = OAuth1Session("foo", verifier="bar")
193187
auth.send = self.fake_body("oauth_token=foo")
194188
resp = auth.fetch_access_token("https://example.com/token")
195189
self.assertEqual(resp["oauth_token"], "foo")
196190
for k, v in resp.items():
197-
self.assertIsInstance(k, unicode_type)
198-
self.assertIsInstance(v, unicode_type)
191+
self.assertIsInstance(k, str)
192+
self.assertIsInstance(v, str)
199193

200194
def test_fetch_access_token_with_optional_arguments(self):
201195
auth = OAuth1Session("foo", verifier="bar")
@@ -205,8 +199,8 @@ def test_fetch_access_token_with_optional_arguments(self):
205199
)
206200
self.assertEqual(resp["oauth_token"], "foo")
207201
for k, v in resp.items():
208-
self.assertIsInstance(k, unicode_type)
209-
self.assertIsInstance(v, unicode_type)
202+
self.assertIsInstance(k, str)
203+
self.assertIsInstance(v, str)
210204

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

0 commit comments

Comments
 (0)