Skip to content

Commit eee74a2

Browse files
authored
Merge pull request #529 from dosisod/drop-python2-support
Drop python2 support
2 parents ed578f1 + 416d738 commit eee74a2

19 files changed

+30
-92
lines changed

requests_oauthlib/compliance_fixes/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# ruff: noqa: F401
2-
from __future__ import absolute_import
3-
42
from .facebook import facebook_compliance_fix
53
from .fitbit import fitbit_compliance_fix
64
from .slack import slack_compliance_fix

requests_oauthlib/compliance_fixes/douban.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import json
22

3-
from oauthlib.common import to_unicode
4-
53

64
def douban_compliance_fix(session):
75
def fix_token_type(r):
86
token = json.loads(r.text)
97
token.setdefault("token_type", "Bearer")
108
fixed_token = json.dumps(token)
11-
r._content = to_unicode(fixed_token).encode("utf-8")
9+
r._content = fixed_token.encode()
1210
return r
1311

1412
session._client_default_token_placement = "query"

requests_oauthlib/compliance_fixes/ebay.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from oauthlib.common import to_unicode
32

43

54
def ebay_compliance_fix(session):
@@ -13,7 +12,7 @@ def _compliance_fix(response):
1312
if token.get("token_type") in ["Application Access Token", "User Access Token"]:
1413
token["token_type"] = "Bearer"
1514
fixed_token = json.dumps(token)
16-
response._content = to_unicode(fixed_token).encode("utf-8")
15+
response._content = fixed_token.encode()
1716

1817
return response
1918

requests_oauthlib/compliance_fixes/facebook.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
from json import dumps
2-
3-
try:
4-
from urlparse import parse_qsl
5-
except ImportError:
6-
from urllib.parse import parse_qsl
7-
8-
from oauthlib.common import to_unicode
2+
from urllib.parse import parse_qsl
93

104

115
def facebook_compliance_fix(session):
@@ -26,7 +20,7 @@ def _compliance_fix(r):
2620
if expires is not None:
2721
token["expires_in"] = expires
2822
token["token_type"] = "Bearer"
29-
r._content = to_unicode(dumps(token)).encode("UTF-8")
23+
r._content = dumps(token).encode()
3024
return r
3125

3226
session.register_compliance_hook("access_token_response", _compliance_fix)

requests_oauthlib/compliance_fixes/fitbit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88

99
from json import loads, dumps
1010

11-
from oauthlib.common import to_unicode
12-
1311

1412
def fitbit_compliance_fix(session):
1513
def _missing_error(r):
1614
token = loads(r.text)
1715
if "errors" in token:
1816
# Set the error to the first one we have
1917
token["error"] = token["errors"][0]["errorType"]
20-
r._content = to_unicode(dumps(token)).encode("UTF-8")
18+
r._content = dumps(token).encode()
2119
return r
2220

2321
session.register_compliance_hook("access_token_response", _missing_error)

requests_oauthlib/compliance_fixes/instagram.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
try:
2-
from urlparse import urlparse, parse_qs
3-
except ImportError:
4-
from urllib.parse import urlparse, parse_qs
1+
from urllib.parse import urlparse, parse_qs
52

63
from oauthlib.common import add_params_to_uri
74

requests_oauthlib/compliance_fixes/mailchimp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import json
22

3-
from oauthlib.common import to_unicode
4-
53

64
def mailchimp_compliance_fix(session):
75
def _null_scope(r):
86
token = json.loads(r.text)
97
if "scope" in token and token["scope"] is None:
108
token.pop("scope")
11-
r._content = to_unicode(json.dumps(token)).encode("utf-8")
9+
r._content = json.dumps(token).encode()
1210
return r
1311

1412
def _non_zero_expiration(r):
1513
token = json.loads(r.text)
1614
if "expires_in" in token and token["expires_in"] == 0:
1715
token["expires_in"] = 3600
18-
r._content = to_unicode(json.dumps(token)).encode("utf-8")
16+
r._content = json.dumps(token).encode()
1917
return r
2018

2119
session.register_compliance_hook("access_token_response", _null_scope)

requests_oauthlib/compliance_fixes/plentymarkets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from json import dumps, loads
22
import re
33

4-
from oauthlib.common import to_unicode
5-
64

75
def plentymarkets_compliance_fix(session):
86
def _to_snake_case(n):
@@ -22,7 +20,7 @@ def _compliance_fix(r):
2220
for k, v in token.items():
2321
fixed_token[_to_snake_case(k)] = v
2422

25-
r._content = to_unicode(dumps(fixed_token)).encode("UTF-8")
23+
r._content = dumps(fixed_token).encode()
2624
return r
2725

2826
session.register_compliance_hook("access_token_response", _compliance_fix)

requests_oauthlib/compliance_fixes/slack.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
try:
2-
from urlparse import urlparse, parse_qs
3-
except ImportError:
4-
from urllib.parse import urlparse, parse_qs
1+
from urllib.parse import urlparse, parse_qs
52

63
from oauthlib.common import add_params_to_uri
74

requests_oauthlib/compliance_fixes/weibo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from json import loads, dumps
22

3-
from oauthlib.common import to_unicode
4-
53

64
def weibo_compliance_fix(session):
75
def _missing_token_type(r):
86
token = loads(r.text)
97
token["token_type"] = "Bearer"
10-
r._content = to_unicode(dumps(token)).encode("UTF-8")
8+
r._content = dumps(token).encode()
119
return r
1210

1311
session._client.default_token_placement = "query"

requests_oauthlib/oauth1_auth.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
42
import logging
53

64
from oauthlib.common import extract_params
75
from oauthlib.oauth1 import Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER
86
from oauthlib.oauth1 import SIGNATURE_TYPE_BODY
9-
from requests.compat import is_py3
107
from requests.utils import to_native_string
118
from requests.auth import AuthBase
129

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

16-
if is_py3:
17-
unicode = str
1813

1914
log = logging.getLogger(__name__)
2015

@@ -83,7 +78,7 @@ def __call__(self, r):
8378
or self.client.signature_type == SIGNATURE_TYPE_BODY
8479
):
8580
content_type = CONTENT_TYPE_FORM_URLENCODED
86-
if not isinstance(content_type, unicode):
81+
if not isinstance(content_type, str):
8782
content_type = content_type.decode("utf-8")
8883

8984
is_form_encoded = CONTENT_TYPE_FORM_URLENCODED in content_type
@@ -96,17 +91,17 @@ def __call__(self, r):
9691
if is_form_encoded:
9792
r.headers["Content-Type"] = CONTENT_TYPE_FORM_URLENCODED
9893
r.url, headers, r.body = self.client.sign(
99-
unicode(r.url), unicode(r.method), r.body or "", r.headers
94+
str(r.url), str(r.method), r.body or "", r.headers
10095
)
10196
elif self.force_include_body:
10297
# To allow custom clients to work on non form encoded bodies.
10398
r.url, headers, r.body = self.client.sign(
104-
unicode(r.url), unicode(r.method), r.body or "", r.headers
99+
str(r.url), str(r.method), r.body or "", r.headers
105100
)
106101
else:
107102
# Omit body data in the signing of non form-encoded requests
108103
r.url, headers, _ = self.client.sign(
109-
unicode(r.url), unicode(r.method), None, r.headers
104+
str(r.url), str(r.method), None, r.headers
110105
)
111106

112107
r.prepare_headers(headers)

requests_oauthlib/oauth1_session.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
from __future__ import unicode_literals
2-
3-
try:
4-
from urlparse import urlparse
5-
except ImportError:
6-
from urllib.parse import urlparse
1+
from urllib.parse import urlparse
72

83
import logging
94

requests_oauthlib/oauth2_auth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
from oauthlib.oauth2 import WebApplicationClient, InsecureTransportError
32
from oauthlib.oauth2 import is_secure_transport
43
from requests.auth import AuthBase

requests_oauthlib/oauth2_session.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import logging
42

53
from oauthlib.common import generate_token, urldecode

tests/test_compliance_fixes.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
from __future__ import unicode_literals
21
from unittest import TestCase
32

43
import requests
54
import requests_mock
65
import time
76

8-
try:
9-
from urlparse import urlparse, parse_qs
10-
except ImportError:
11-
from urllib.parse import urlparse, parse_qs
7+
from urllib.parse import urlparse, parse_qs
128

139
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
1410
from requests_oauthlib import OAuth2Session

tests/test_core.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
32
import requests
43
import requests_oauthlib
54
import oauthlib
65
import os.path
76
from io import StringIO
87
import unittest
98

10-
try:
11-
from unittest import mock
12-
except ImportError:
13-
import mock
9+
from unittest import mock
1410

1511

1612
@mock.patch("oauthlib.oauth1.rfc5849.generate_timestamp")

tests/test_oauth1_session.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
from __future__ import unicode_literals, print_function
21
import unittest
3-
import sys
42
import requests
53
from io import StringIO
4+
from unittest import mock
65

76
from oauthlib.oauth1 import SIGNATURE_TYPE_QUERY, SIGNATURE_TYPE_BODY
87
from oauthlib.oauth1 import SIGNATURE_RSA, SIGNATURE_PLAINTEXT
98
from requests_oauthlib import OAuth1Session
109

11-
try:
12-
from unittest import mock
13-
except ImportError:
14-
import mock
15-
1610
try:
1711
import cryptography
1812
except ImportError:
@@ -23,11 +17,6 @@
2317
except ImportError:
2418
jwt = None
2519

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

3221
TEST_RSA_KEY = (
3322
"-----BEGIN RSA PRIVATE KEY-----\n"
@@ -165,17 +154,17 @@ def test_parse_response_url(self):
165154
self.assertEqual(resp["oauth_token"], "foo")
166155
self.assertEqual(resp["oauth_verifier"], "bar")
167156
for k, v in resp.items():
168-
self.assertIsInstance(k, unicode_type)
169-
self.assertIsInstance(v, unicode_type)
157+
self.assertIsInstance(k, str)
158+
self.assertIsInstance(v, str)
170159

171160
def test_fetch_request_token(self):
172161
auth = OAuth1Session("foo")
173162
auth.send = self.fake_body("oauth_token=foo")
174163
resp = auth.fetch_request_token("https://example.com/token")
175164
self.assertEqual(resp["oauth_token"], "foo")
176165
for k, v in resp.items():
177-
self.assertIsInstance(k, unicode_type)
178-
self.assertIsInstance(v, unicode_type)
166+
self.assertIsInstance(k, str)
167+
self.assertIsInstance(v, str)
179168

180169
def test_fetch_request_token_with_optional_arguments(self):
181170
auth = OAuth1Session("foo")
@@ -185,17 +174,17 @@ def test_fetch_request_token_with_optional_arguments(self):
185174
)
186175
self.assertEqual(resp["oauth_token"], "foo")
187176
for k, v in resp.items():
188-
self.assertIsInstance(k, unicode_type)
189-
self.assertIsInstance(v, unicode_type)
177+
self.assertIsInstance(k, str)
178+
self.assertIsInstance(v, str)
190179

191180
def test_fetch_access_token(self):
192181
auth = OAuth1Session("foo", verifier="bar")
193182
auth.send = self.fake_body("oauth_token=foo")
194183
resp = auth.fetch_access_token("https://example.com/token")
195184
self.assertEqual(resp["oauth_token"], "foo")
196185
for k, v in resp.items():
197-
self.assertIsInstance(k, unicode_type)
198-
self.assertIsInstance(v, unicode_type)
186+
self.assertIsInstance(k, str)
187+
self.assertIsInstance(v, str)
199188

200189
def test_fetch_access_token_with_optional_arguments(self):
201190
auth = OAuth1Session("foo", verifier="bar")
@@ -205,8 +194,8 @@ def test_fetch_access_token_with_optional_arguments(self):
205194
)
206195
self.assertEqual(resp["oauth_token"], "foo")
207196
for k, v in resp.items():
208-
self.assertIsInstance(k, unicode_type)
209-
self.assertIsInstance(v, unicode_type)
197+
self.assertIsInstance(k, str)
198+
self.assertIsInstance(v, str)
210199

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

tests/test_oauth2_auth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
import unittest
32

43
from oauthlib.oauth2 import WebApplicationClient, MobileApplicationClient

tests/test_oauth2_session.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
import json
32
import time
43
import tempfile
@@ -8,10 +7,7 @@
87
from copy import deepcopy
98
from unittest import TestCase
109

11-
try:
12-
from unittest import mock
13-
except ImportError:
14-
import mock
10+
from unittest import mock
1511

1612
from oauthlib.common import urlencode
1713
from oauthlib.oauth2 import TokenExpiredError, OAuth2Error

0 commit comments

Comments
 (0)