summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Huot <JonathanHuot@users.noreply.github.com>2019-08-30 11:56:43 +0200
committerGitHub <noreply@github.com>2019-08-30 11:56:43 +0200
commitca57b0bcae835493d9db8f9bf1f1228b71b8e3f8 (patch)
tree71f3d2ecee2ffd32da6f030558d0eed91d953895
parent1f3fc4bfd4fd51711798186591bf3e3ba5a894be (diff)
parent11bf0eca2857f5330237e574630dd916d53cd573 (diff)
downloadoauthlib-ca57b0bcae835493d9db8f9bf1f1228b71b8e3f8.tar.gz
Merge pull request #700 from hugovk/rm-2.7
Drop support for Python 2.7
-rw-r--r--.travis.yml3
-rw-r--r--README.rst2
-rw-r--r--bandit.json2
-rw-r--r--docs/conf.py16
-rw-r--r--docs/contributing.rst7
-rw-r--r--oauthlib/common.py76
-rw-r--r--oauthlib/oauth1/__init__.py2
-rw-r--r--oauthlib/oauth1/rfc5849/__init__.py27
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/__init__.py2
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/access_token.py2
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/authorization.py8
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/base.py6
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/pre_configured.py2
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/request_token.py4
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/resource.py2
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/signature_only.py2
-rw-r--r--oauthlib/oauth1/rfc5849/errors.py6
-rw-r--r--oauthlib/oauth1/rfc5849/parameters.py9
-rw-r--r--oauthlib/oauth1/rfc5849/request_validator.py6
-rw-r--r--oauthlib/oauth1/rfc5849/signature.py18
-rw-r--r--oauthlib/oauth1/rfc5849/utils.py15
-rw-r--r--oauthlib/oauth2/__init__.py2
-rw-r--r--oauthlib/oauth2/rfc6749/__init__.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/__init__.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/backend_application.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/base.py8
-rw-r--r--oauthlib/oauth2/rfc6749/clients/legacy_application.py4
-rw-r--r--oauthlib/oauth2/rfc6749/clients/mobile_application.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/service_application.py4
-rw-r--r--oauthlib/oauth2/rfc6749/clients/web_application.py4
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/__init__.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/authorization.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/base.py4
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/introspect.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/metadata.py5
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/pre_configured.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/resource.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/revocation.py4
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/token.py2
-rw-r--r--oauthlib/oauth2/rfc6749/errors.py8
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/__init__.py2
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/authorization_code.py2
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/base.py6
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/client_credentials.py2
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/implicit.py2
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/refresh_token.py6
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py2
-rw-r--r--oauthlib/oauth2/rfc6749/parameters.py20
-rw-r--r--oauthlib/oauth2/rfc6749/request_validator.py4
-rw-r--r--oauthlib/oauth2/rfc6749/tokens.py17
-rw-r--r--oauthlib/oauth2/rfc6749/utils.py25
-rw-r--r--oauthlib/openid/__init__.py2
-rw-r--r--oauthlib/openid/connect/core/endpoints/__init__.py2
-rw-r--r--oauthlib/openid/connect/core/endpoints/pre_configured.py2
-rw-r--r--oauthlib/openid/connect/core/endpoints/userinfo.py5
-rw-r--r--oauthlib/openid/connect/core/exceptions.py2
-rw-r--r--oauthlib/openid/connect/core/grant_types/__init__.py2
-rw-r--r--oauthlib/openid/connect/core/grant_types/authorization_code.py4
-rw-r--r--oauthlib/openid/connect/core/grant_types/base.py4
-rw-r--r--oauthlib/openid/connect/core/grant_types/dispatchers.py2
-rw-r--r--oauthlib/openid/connect/core/grant_types/exceptions.py2
-rw-r--r--oauthlib/openid/connect/core/grant_types/hybrid.py4
-rw-r--r--oauthlib/openid/connect/core/grant_types/implicit.py6
-rw-r--r--oauthlib/openid/connect/core/request_validator.py2
-rw-r--r--oauthlib/openid/connect/core/tokens.py3
-rw-r--r--oauthlib/signals.py4
-rw-r--r--oauthlib/uri_validate.py2
-rwxr-xr-xsetup.py6
-rw-r--r--tests/oauth1/rfc5849/endpoints/test_access_token.py2
-rw-r--r--tests/oauth1/rfc5849/endpoints/test_authorization.py2
-rw-r--r--tests/oauth1/rfc5849/endpoints/test_base.py2
-rw-r--r--tests/oauth1/rfc5849/endpoints/test_request_token.py2
-rw-r--r--tests/oauth1/rfc5849/endpoints/test_resource.py2
-rw-r--r--tests/oauth1/rfc5849/endpoints/test_signature_only.py2
-rw-r--r--tests/oauth1/rfc5849/test_client.py4
-rw-r--r--tests/oauth1/rfc5849/test_parameters.py2
-rw-r--r--tests/oauth1/rfc5849/test_request_validator.py2
-rw-r--r--tests/oauth1/rfc5849/test_signatures.py10
-rw-r--r--tests/oauth1/rfc5849/test_utils.py11
-rw-r--r--tests/oauth2/rfc6749/clients/test_backend_application.py2
-rw-r--r--tests/oauth2/rfc6749/clients/test_base.py6
-rw-r--r--tests/oauth2/rfc6749/clients/test_legacy_application.py14
-rw-r--r--tests/oauth2/rfc6749/clients/test_mobile_application.py2
-rw-r--r--tests/oauth2/rfc6749/clients/test_service_application.py2
-rw-r--r--tests/oauth2/rfc6749/clients/test_web_application.py11
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_base_endpoint.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_client_authentication.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_error_responses.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_extra_credentials.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_metadata.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_scope_handling.py8
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_utils.py5
-rw-r--r--tests/oauth2/rfc6749/grant_types/test_authorization_code.py2
-rw-r--r--tests/oauth2/rfc6749/grant_types/test_client_credentials.py2
-rw-r--r--tests/oauth2/rfc6749/grant_types/test_implicit.py2
-rw-r--r--tests/oauth2/rfc6749/grant_types/test_refresh_token.py2
-rw-r--r--tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py2
-rw-r--r--tests/oauth2/rfc6749/test_parameters.py12
-rw-r--r--tests/oauth2/rfc6749/test_request_validator.py2
-rw-r--r--tests/oauth2/rfc6749/test_server.py6
-rw-r--r--tests/oauth2/rfc6749/test_tokens.py2
-rw-r--r--tests/oauth2/rfc6749/test_utils.py11
-rw-r--r--tests/openid/connect/core/endpoints/test_claims_handling.py2
-rw-r--r--tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py10
-rw-r--r--tests/openid/connect/core/endpoints/test_userinfo_endpoint.py2
-rw-r--r--tests/openid/connect/core/grant_types/test_authorization_code.py12
-rw-r--r--tests/openid/connect/core/grant_types/test_dispatchers.py7
-rw-r--r--tests/openid/connect/core/grant_types/test_hybrid.py16
-rw-r--r--tests/openid/connect/core/grant_types/test_implicit.py16
-rw-r--r--tests/openid/connect/core/test_request_validator.py2
-rw-r--r--tests/openid/connect/core/test_server.py6
-rw-r--r--tests/openid/connect/core/test_tokens.py2
-rw-r--r--tests/test_common.py66
-rw-r--r--tests/unittest/__init__.py21
-rw-r--r--tox.ini6
119 files changed, 212 insertions, 530 deletions
diff --git a/.travis.yml b/.travis.yml
index 5241b81..fbf676b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,9 @@
language: python
python: 3.7
dist: xenial
-sudo: false
cache: pip
matrix:
include:
- - python: 2.7
- env: TOXENV=py27
- python: 3.5
env: TOXENV=py35
- python: 3.6
diff --git a/README.rst b/README.rst
index 96871b6..0b42133 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,7 @@ OAuthLib - Python Framework for OAuth1 & OAuth2
===============================================
*A generic, spec-compliant, thorough implementation of the OAuth request-signing
-logic for Python 2.7 and 3.5+.*
+logic for Python 3.5+.
.. image:: https://travis-ci.org/oauthlib/oauthlib.svg?branch=master
:target: https://travis-ci.org/oauthlib/oauthlib
diff --git a/bandit.json b/bandit.json
index 4d3bfe1..7161f00 100644
--- a/bandit.json
+++ b/bandit.json
@@ -1133,7 +1133,7 @@
"test_name": "hardcoded_password_funcarg"
},
{
- "code": "164 \n165 def prepare_token_revocation_request(url, token, token_type_hint=\"access_token\",\n166 callback=None, body='', **kwargs):\n167 \"\"\"Prepare a token revocation request.\n168 \n169 The client constructs the request by including the following parameters\n170 using the \"application/x-www-form-urlencoded\" format in the HTTP request\n171 entity-body:\n172 \n173 :param token: REQUIRED. The token that the client wants to get revoked.\n174 \n175 :param token_type_hint: OPTIONAL. A hint about the type of the token\n176 submitted for revocation. Clients MAY pass this\n177 parameter in order to help the authorization server\n178 to optimize the token lookup. If the server is\n179 unable to locate the token using the given hint, it\n180 MUST extend its search across all of its supported\n181 token types. An authorization server MAY ignore\n182 this parameter, particularly if it is able to detect\n183 the token type automatically.\n184 \n185 This specification defines two values for `token_type_hint`:\n186 \n187 * access_token: An access token as defined in [RFC6749],\n188 `Section 1.4`_\n189 \n190 * refresh_token: A refresh token as defined in [RFC6749],\n191 `Section 1.5`_\n192 \n193 Specific implementations, profiles, and extensions of this\n194 specification MAY define other values for this parameter using the\n195 registry defined in `Section 4.1.2`_.\n196 \n197 .. _`Section 1.4`: https://tools.ietf.org/html/rfc6749#section-1.4\n198 .. _`Section 1.5`: https://tools.ietf.org/html/rfc6749#section-1.5\n199 .. _`Section 4.1.2`: https://tools.ietf.org/html/rfc7009#section-4.1.2\n200 \n201 \"\"\"\n202 if not is_secure_transport(url):\n203 raise InsecureTransportError()\n204 \n205 params = [('token', token)]\n206 \n207 if token_type_hint:\n208 params.append(('token_type_hint', token_type_hint))\n209 \n210 for k in kwargs:\n211 if kwargs[k]:\n212 params.append((unicode_type(k), kwargs[k]))\n213 \n214 headers = {'Content-Type': 'application/x-www-form-urlencoded'}\n215 \n216 if callback:\n217 params.append(('callback', callback))\n218 return add_params_to_uri(url, params), headers, body\n219 else:\n220 return url, headers, add_params_to_qs(body, params)\n221 \n222 \n223 def parse_authorization_code_response(uri, state=None):\n",
+ "code": "164 \n165 def prepare_token_revocation_request(url, token, token_type_hint=\"access_token\",\n166 callback=None, body='', **kwargs):\n167 \"\"\"Prepare a token revocation request.\n168 \n169 The client constructs the request by including the following parameters\n170 using the \"application/x-www-form-urlencoded\" format in the HTTP request\n171 entity-body:\n172 \n173 :param token: REQUIRED. The token that the client wants to get revoked.\n174 \n175 :param token_type_hint: OPTIONAL. A hint about the type of the token\n176 submitted for revocation. Clients MAY pass this\n177 parameter in order to help the authorization server\n178 to optimize the token lookup. If the server is\n179 unable to locate the token using the given hint, it\n180 MUST extend its search across all of its supported\n181 token types. An authorization server MAY ignore\n182 this parameter, particularly if it is able to detect\n183 the token type automatically.\n184 \n185 This specification defines two values for `token_type_hint`:\n186 \n187 * access_token: An access token as defined in [RFC6749],\n188 `Section 1.4`_\n189 \n190 * refresh_token: A refresh token as defined in [RFC6749],\n191 `Section 1.5`_\n192 \n193 Specific implementations, profiles, and extensions of this\n194 specification MAY define other values for this parameter using the\n195 registry defined in `Section 4.1.2`_.\n196 \n197 .. _`Section 1.4`: https://tools.ietf.org/html/rfc6749#section-1.4\n198 .. _`Section 1.5`: https://tools.ietf.org/html/rfc6749#section-1.5\n199 .. _`Section 4.1.2`: https://tools.ietf.org/html/rfc7009#section-4.1.2\n200 \n201 \"\"\"\n202 if not is_secure_transport(url):\n203 raise InsecureTransportError()\n204 \n205 params = [('token', token)]\n206 \n207 if token_type_hint:\n208 params.append(('token_type_hint', token_type_hint))\n209 \n210 for k in kwargs:\n211 if kwargs[k]:\n212 params.append((str(k), kwargs[k]))\n213 \n214 headers = {'Content-Type': 'application/x-www-form-urlencoded'}\n215 \n216 if callback:\n217 params.append(('callback', callback))\n218 return add_params_to_uri(url, params), headers, body\n219 else:\n220 return url, headers, add_params_to_qs(body, params)\n221 \n222 \n223 def parse_authorization_code_response(uri, state=None):\n",
"filename": "oauthlib/oauth2/rfc6749/parameters.py",
"issue_confidence": "MEDIUM",
"issue_severity": "LOW",
diff --git a/docs/conf.py b/docs/conf.py
index 3388de6..91b5de4 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -45,8 +45,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
-project = u'OAuthLib'
-copyright = u'2019, The OAuthlib Community'
+project = 'OAuthLib'
+copyright = '2019, The OAuthlib Community'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -190,8 +190,8 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'OAuthLib.tex', u'OAuthLib Documentation',
- u'The OAuhthlib Community', 'manual'),
+ ('index', 'OAuthLib.tex', 'OAuthLib Documentation',
+ 'The OAuhthlib Community', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -220,8 +220,8 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
- ('index', 'oauthlib', u'OAuthLib Documentation',
- [u'The OAuthlib Community'], 1)
+ ('index', 'oauthlib', 'OAuthLib Documentation',
+ ['The OAuthlib Community'], 1)
]
# If true, show URL addresses after external links.
@@ -234,8 +234,8 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- ('index', 'OAuthLib', u'OAuthLib Documentation',
- u'The OAuthlib Community', 'OAuthLib', 'One line description of project.',
+ ('index', 'OAuthLib', 'OAuthLib Documentation',
+ 'The OAuthlib Community', 'OAuthLib', 'One line description of project.',
'Miscellaneous'),
]
diff --git a/docs/contributing.rst b/docs/contributing.rst
index 5473aab..4a46e3b 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -144,7 +144,7 @@ the project root via:
.. sourcecode:: bash
- $ py.test
+ $ pytest
The first thing the core committers will do is run this command. Any pull
request that fails this test suite will be **rejected**.
@@ -152,7 +152,7 @@ request that fails this test suite will be **rejected**.
Testing multiple versions of Python
-----------------------------------
-OAuthLib supports Python 2.7, 3.5, 3.6, 3.7 and PyPy 2.7 & PyPy 3. Testing
+OAuthLib supports Python 3.5, 3.6, 3.7 and PyPy 2.7 & PyPy 3. Testing
all versions conveniently can be done using `Tox`_.
.. sourcecode:: bash
@@ -167,7 +167,6 @@ The versions beloew may not be up to date.
.. sourcecode:: bash
- $ pyenv install 2.7.16
$ pyenv install 3.5.7
$ pyenv install 3.6.9
$ pyenv install 3.7.4
@@ -304,7 +303,7 @@ First we pull the code into a local branch::
Then we run the tests::
- py.test
+ pytest
We finish with a non-fastforward merge (to preserve the branch history) and push
to GitHub::
diff --git a/oauthlib/common.py b/oauthlib/common.py
index 5aeb015..e7131df 100644
--- a/oauthlib/common.py
+++ b/oauthlib/common.py
@@ -6,15 +6,16 @@ oauthlib.common
This module provides data structures and utilities common
to all implementations of OAuth.
"""
-from __future__ import absolute_import, unicode_literals
-
import collections
import datetime
import logging
import re
-import sys
import time
+import urllib.parse as urlparse
from . import get_debug
+from urllib.parse import quote as _quote
+from urllib.parse import unquote as _unquote
+from urllib.parse import urlencode as _urlencode
try:
from secrets import randbits
@@ -22,18 +23,6 @@ try:
except ImportError:
from random import getrandbits as randbits
from random import SystemRandom
-try:
- from urllib import quote as _quote
- from urllib import unquote as _unquote
- from urllib import urlencode as _urlencode
-except ImportError:
- from urllib.parse import quote as _quote
- from urllib.parse import unquote as _unquote
- from urllib.parse import urlencode as _urlencode
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
UNICODE_ASCII_CHARACTER_SET = ('abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -51,17 +40,10 @@ always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
log = logging.getLogger('oauthlib')
-PY3 = sys.version_info[0] == 3
-
-if PY3:
- unicode_type = str
-else:
- unicode_type = unicode
-
# 'safe' must be bytes (Python 2.6 requires bytes, other versions allow either)
def quote(s, safe=b'/'):
- s = s.encode('utf-8') if isinstance(s, unicode_type) else s
+ s = s.encode('utf-8') if isinstance(s, str) else s
s = _quote(s, safe)
# PY3 always returns unicode. PY2 may return either, depending on whether
# it had to modify the string.
@@ -83,7 +65,7 @@ def unquote(s):
def urlencode(params):
utf8_params = encode_params_utf8(params)
urlencoded = _urlencode(utf8_params)
- if isinstance(urlencoded, unicode_type): # PY3 returns unicode
+ if isinstance(urlencoded, str):
return urlencoded
else:
return urlencoded.decode("utf-8")
@@ -96,8 +78,8 @@ def encode_params_utf8(params):
encoded = []
for k, v in params:
encoded.append((
- k.encode('utf-8') if isinstance(k, unicode_type) else k,
- v.encode('utf-8') if isinstance(v, unicode_type) else v))
+ k.encode('utf-8') if isinstance(k, str) else k,
+ v.encode('utf-8') if isinstance(v, str) else v))
return encoded
@@ -141,22 +123,6 @@ def urldecode(query):
if INVALID_HEX_PATTERN.search(query):
raise ValueError('Invalid hex encoding in query string.')
- # We encode to utf-8 prior to parsing because parse_qsl behaves
- # differently on unicode input in python 2 and 3.
- # Python 2.7
- # >>> urlparse.parse_qsl(u'%E5%95%A6%E5%95%A6')
- # u'\xe5\x95\xa6\xe5\x95\xa6'
- # Python 2.7, non unicode input gives the same
- # >>> urlparse.parse_qsl('%E5%95%A6%E5%95%A6')
- # '\xe5\x95\xa6\xe5\x95\xa6'
- # but now we can decode it to unicode
- # >>> urlparse.parse_qsl('%E5%95%A6%E5%95%A6').decode('utf-8')
- # u'\u5566\u5566'
- # Python 3.3 however
- # >>> urllib.parse.parse_qsl(u'%E5%95%A6%E5%95%A6')
- # u'\u5566\u5566'
- query = query.encode(
- 'utf-8') if not PY3 and isinstance(query, unicode_type) else query
# We want to allow queries such as "c2" whereas urlparse.parse_qsl
# with the strict_parsing flag will not.
params = urlparse.parse_qsl(query, keep_blank_values=True)
@@ -173,7 +139,7 @@ def extract_params(raw):
empty list of parameters. Any other input will result in a return
value of None.
"""
- if isinstance(raw, (bytes, unicode_type)):
+ if isinstance(raw, (bytes, str)):
try:
params = urldecode(raw)
except ValueError:
@@ -206,7 +172,7 @@ def generate_nonce():
.. _`section 3.2.1`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
.. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3
"""
- return unicode_type(unicode_type(randbits(64)) + generate_timestamp())
+ return str(str(randbits(64)) + generate_timestamp())
def generate_timestamp():
@@ -218,7 +184,7 @@ def generate_timestamp():
.. _`section 3.2.1`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
.. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3
"""
- return unicode_type(int(time.time()))
+ return str(int(time.time()))
def generate_token(length=30, chars=UNICODE_ASCII_CHARACTER_SET):
@@ -305,11 +271,11 @@ def safe_string_equals(a, b):
def to_unicode(data, encoding='UTF-8'):
"""Convert a number of different types of objects to unicode."""
- if isinstance(data, unicode_type):
+ if isinstance(data, str):
return data
if isinstance(data, bytes):
- return unicode_type(data, encoding=encoding)
+ return str(data, encoding=encoding)
if hasattr(data, '__iter__'):
try:
@@ -323,7 +289,7 @@ def to_unicode(data, encoding='UTF-8'):
# We support 2.6 which lacks dict comprehensions
if hasattr(data, 'items'):
data = data.items()
- return dict(((to_unicode(k, encoding), to_unicode(v, encoding)) for k, v in data))
+ return {to_unicode(k, encoding): to_unicode(v, encoding) for k, v in data}
return data
@@ -335,7 +301,7 @@ class CaseInsensitiveDict(dict):
proxy = {}
def __init__(self, data):
- self.proxy = dict((k.lower(), k) for k in data)
+ self.proxy = {k.lower(): k for k in data}
for k in data:
self[k] = data[k]
@@ -344,27 +310,27 @@ class CaseInsensitiveDict(dict):
def __delitem__(self, k):
key = self.proxy[k.lower()]
- super(CaseInsensitiveDict, self).__delitem__(key)
+ super().__delitem__(key)
del self.proxy[k.lower()]
def __getitem__(self, k):
key = self.proxy[k.lower()]
- return super(CaseInsensitiveDict, self).__getitem__(key)
+ return super().__getitem__(key)
def get(self, k, default=None):
return self[k] if k in self else default
def __setitem__(self, k, v):
- super(CaseInsensitiveDict, self).__setitem__(k, v)
+ super().__setitem__(k, v)
self.proxy[k.lower()] = k
def update(self, *args, **kwargs):
- super(CaseInsensitiveDict, self).update(*args, **kwargs)
+ super().update(*args, **kwargs)
for k in dict(*args, **kwargs):
self.proxy[k.lower()] = k
-class Request(object):
+class Request:
"""A malleable representation of a signable HTTP request.
@@ -444,7 +410,7 @@ class Request(object):
body = SANITIZE_PATTERN.sub('\1<SANITIZED>', str(body))
if 'Authorization' in headers:
headers['Authorization'] = '<SANITIZED>'
- return '<oauthlib.Request url="%s", http_method="%s", headers="%s", body="%s">' % (
+ return '<oauthlib.Request url="{}", http_method="{}", headers="{}", body="{}">'.format(
self.uri, self.http_method, headers, body)
@property
diff --git a/oauthlib/oauth1/__init__.py b/oauthlib/oauth1/__init__.py
index dc908d4..e6d8a80 100644
--- a/oauthlib/oauth1/__init__.py
+++ b/oauthlib/oauth1/__init__.py
@@ -6,8 +6,6 @@ oauthlib.oauth1
This module is a wrapper for the most recent implementation of OAuth 1.0 Client
and Server classes.
"""
-from __future__ import absolute_import, unicode_literals
-
from .rfc5849 import Client
from .rfc5849 import SIGNATURE_HMAC, SIGNATURE_HMAC_SHA1, SIGNATURE_HMAC_SHA256, SIGNATURE_RSA, SIGNATURE_PLAINTEXT
from .rfc5849 import SIGNATURE_TYPE_AUTH_HEADER, SIGNATURE_TYPE_QUERY
diff --git a/oauthlib/oauth1/rfc5849/__init__.py b/oauthlib/oauth1/rfc5849/__init__.py
index 4f462bb..b629fc1 100644
--- a/oauthlib/oauth1/rfc5849/__init__.py
+++ b/oauthlib/oauth1/rfc5849/__init__.py
@@ -6,17 +6,12 @@ oauthlib.oauth1.rfc5849
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
"""
-from __future__ import absolute_import, unicode_literals
import base64
import hashlib
import logging
log = logging.getLogger(__name__)
-import sys
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
+import urllib.parse as urlparse
from oauthlib.common import Request, urlencode, generate_nonce
from oauthlib.common import generate_timestamp, to_unicode
@@ -36,7 +31,7 @@ SIGNATURE_TYPE_BODY = 'BODY'
CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
-class Client(object):
+class Client:
"""A client used to sign OAuth 1.0 RFC 5849 requests."""
SIGNATURE_METHODS = {
@@ -106,8 +101,8 @@ class Client(object):
attrs['rsa_key'] = '****' if attrs['rsa_key'] else None
attrs[
'resource_owner_secret'] = '****' if attrs['resource_owner_secret'] else None
- attribute_str = ', '.join('%s=%s' % (k, v) for k, v in attrs.items())
- return '<%s %s>' % (self.__class__.__name__, attribute_str)
+ attribute_str = ', '.join('{}={}'.format(k, v) for k, v in attrs.items())
+ return '<{} {}>'.format(self.__class__.__name__, attribute_str)
def get_oauth_signature(self, request):
"""Get an OAuth signature to be used in signing a request
@@ -130,24 +125,24 @@ class Client(object):
uri_query=urlparse.urlparse(uri).query,
body=body,
headers=headers)
- log.debug("Collected params: {0}".format(collected_params))
+ log.debug("Collected params: {}".format(collected_params))
normalized_params = signature.normalize_parameters(collected_params)
normalized_uri = signature.base_string_uri(uri, headers.get('Host', None))
- log.debug("Normalized params: {0}".format(normalized_params))
- log.debug("Normalized URI: {0}".format(normalized_uri))
+ log.debug("Normalized params: {}".format(normalized_params))
+ log.debug("Normalized URI: {}".format(normalized_uri))
base_string = signature.signature_base_string(request.http_method,
normalized_uri, normalized_params)
- log.debug("Signing: signature base string: {0}".format(base_string))
+ log.debug("Signing: signature base string: {}".format(base_string))
if self.signature_method not in self.SIGNATURE_METHODS:
raise ValueError('Invalid signature method.')
sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
- log.debug("Signature: {0}".format(sig))
+ log.debug("Signature: {}".format(sig))
return sig
def get_oauth_params(self, request):
@@ -278,8 +273,8 @@ class Client(object):
# header field set to "application/x-www-form-urlencoded".
elif not should_have_params and has_params:
raise ValueError(
- "Body contains parameters but Content-Type header was {0} "
- "instead of {1}".format(content_type or "not set",
+ "Body contains parameters but Content-Type header was {} "
+ "instead of {}".format(content_type or "not set",
CONTENT_TYPE_FORM_URLENCODED))
# 3.5.2. Form-Encoded Body
diff --git a/oauthlib/oauth1/rfc5849/endpoints/__init__.py b/oauthlib/oauth1/rfc5849/endpoints/__init__.py
index b16ccba..78ade72 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/__init__.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/__init__.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import
-
from .base import BaseEndpoint
from .request_token import RequestTokenEndpoint
from .authorization import AuthorizationEndpoint
diff --git a/oauthlib/oauth1/rfc5849/endpoints/access_token.py b/oauthlib/oauth1/rfc5849/endpoints/access_token.py
index bea8274..13665db 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/access_token.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/access_token.py
@@ -8,8 +8,6 @@ OAuth 1.0 RFC 5849. It validates the correctness of access token requests,
creates and persists tokens as well as create the proper response to be
returned to the client.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.common import urlencode
diff --git a/oauthlib/oauth1/rfc5849/endpoints/authorization.py b/oauthlib/oauth1/rfc5849/endpoints/authorization.py
index b465946..7d0353b 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/authorization.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/authorization.py
@@ -6,17 +6,11 @@ oauthlib.oauth1.rfc5849.endpoints.authorization
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
"""
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.common import Request, add_params_to_uri
from .. import errors
from .base import BaseEndpoint
-
-try:
- from urllib import urlencode
-except ImportError:
- from urllib.parse import urlencode
+from urllib.parse import urlencode
class AuthorizationEndpoint(BaseEndpoint):
diff --git a/oauthlib/oauth1/rfc5849/endpoints/base.py b/oauthlib/oauth1/rfc5849/endpoints/base.py
index f005256..f9a8f57 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/base.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/base.py
@@ -6,8 +6,6 @@ oauthlib.oauth1.rfc5849.endpoints.base
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
"""
-from __future__ import absolute_import, unicode_literals
-
import time
from oauthlib.common import CaseInsensitiveDict, Request, generate_token
@@ -17,7 +15,7 @@ from .. import (CONTENT_TYPE_FORM_URLENCODED, SIGNATURE_HMAC_SHA1, SIGNATURE_HMA
SIGNATURE_TYPE_QUERY, errors, signature, utils)
-class BaseEndpoint(object):
+class BaseEndpoint:
def __init__(self, request_validator, token_generator=None):
self.request_validator = request_validator
@@ -131,7 +129,7 @@ class BaseEndpoint(object):
if (not request.signature_method in
self.request_validator.allowed_signature_methods):
raise errors.InvalidSignatureMethodError(
- description="Invalid signature, %s not in %r." % (
+ description="Invalid signature, {} not in {!r}.".format(
request.signature_method,
self.request_validator.allowed_signature_methods))
diff --git a/oauthlib/oauth1/rfc5849/endpoints/pre_configured.py b/oauthlib/oauth1/rfc5849/endpoints/pre_configured.py
index f89393a..b14a6d8 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/pre_configured.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/pre_configured.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from . import (AccessTokenEndpoint, AuthorizationEndpoint,
RequestTokenEndpoint, ResourceEndpoint)
diff --git a/oauthlib/oauth1/rfc5849/endpoints/request_token.py b/oauthlib/oauth1/rfc5849/endpoints/request_token.py
index e9ca331..bb67e71 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/request_token.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/request_token.py
@@ -8,8 +8,6 @@ OAuth 1.0 RFC 5849. It validates the correctness of request token requests,
creates and persists tokens as well as create the proper response to be
returned to the client.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.common import urlencode
@@ -129,7 +127,7 @@ class RequestTokenEndpoint(BaseEndpoint):
request.client_key, request)
if not self.request_validator.check_realms(request.realms):
raise errors.InvalidRequestError(
- description='Invalid realm %s. Allowed are %r.' % (
+ description='Invalid realm {}. Allowed are {!r}.'.format(
request.realms, self.request_validator.realms))
if not request.redirect_uri:
diff --git a/oauthlib/oauth1/rfc5849/endpoints/resource.py b/oauthlib/oauth1/rfc5849/endpoints/resource.py
index f82e8b1..45bdaaa 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/resource.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/resource.py
@@ -6,8 +6,6 @@ oauthlib.oauth1.rfc5849.endpoints.resource
This module is an implementation of the resource protection provider logic of
OAuth 1.0 RFC 5849.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from .. import errors
diff --git a/oauthlib/oauth1/rfc5849/endpoints/signature_only.py b/oauthlib/oauth1/rfc5849/endpoints/signature_only.py
index 4297770..d693ccb 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/signature_only.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/signature_only.py
@@ -6,8 +6,6 @@ oauthlib.oauth1.rfc5849.endpoints.signature_only
This module is an implementation of the signing logic of OAuth 1.0 RFC 5849.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from .. import errors
diff --git a/oauthlib/oauth1/rfc5849/errors.py b/oauthlib/oauth1/rfc5849/errors.py
index a5c59bd..98d327f 100644
--- a/oauthlib/oauth1/rfc5849/errors.py
+++ b/oauthlib/oauth1/rfc5849/errors.py
@@ -6,8 +6,6 @@ oauthlib.oauth1.rfc5849.errors
Error used both by OAuth 1 clients and provicers to represent the spec
defined error responses for all four core grant types.
"""
-from __future__ import unicode_literals
-
from oauthlib.common import add_params_to_uri, urlencode
@@ -37,10 +35,10 @@ class OAuth1Error(Exception):
request: Oauthlib Request object
"""
self.description = description or self.description
- message = '(%s) %s' % (self.error, self.description)
+ message = '({}) {}'.format(self.error, self.description)
if request:
message += ' ' + repr(request)
- super(OAuth1Error, self).__init__(message)
+ super().__init__(message)
self.uri = uri
self.status_code = status_code
diff --git a/oauthlib/oauth1/rfc5849/parameters.py b/oauthlib/oauth1/rfc5849/parameters.py
index db4400e..778a46d 100644
--- a/oauthlib/oauth1/rfc5849/parameters.py
+++ b/oauthlib/oauth1/rfc5849/parameters.py
@@ -7,16 +7,11 @@ This module contains methods related to `section 3.5`_ of the OAuth 1.0a spec.
.. _`section 3.5`: https://tools.ietf.org/html/rfc5849#section-3.5
"""
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.common import extract_params, urlencode
from . import utils
-try:
- from urlparse import urlparse, urlunparse
-except ImportError: # noqa
- from urllib.parse import urlparse, urlunparse
+from urllib.parse import urlparse, urlunparse
# TODO: do we need filter_params now that oauth_params are handled by Request?
@@ -61,7 +56,7 @@ def prepare_headers(oauth_params, headers=None, realm=None):
# 2. Each parameter's name is immediately followed by an "=" character
# (ASCII code 61), a """ character (ASCII code 34), the parameter
# value (MAY be empty), and another """ character (ASCII code 34).
- part = '{0}="{1}"'.format(escaped_name, escaped_value)
+ part = '{}="{}"'.format(escaped_name, escaped_value)
authorization_header_parameters_parts.append(part)
diff --git a/oauthlib/oauth1/rfc5849/request_validator.py b/oauthlib/oauth1/rfc5849/request_validator.py
index 330bcbb..657bfe3 100644
--- a/oauthlib/oauth1/rfc5849/request_validator.py
+++ b/oauthlib/oauth1/rfc5849/request_validator.py
@@ -6,14 +6,12 @@ oauthlib.oauth1.rfc5849
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
"""
-from __future__ import absolute_import, unicode_literals
-
import sys
from . import SIGNATURE_METHODS, utils
-class RequestValidator(object):
+class RequestValidator:
"""A validator/datastore interaction base class for OAuth 1 providers.
@@ -197,7 +195,7 @@ class RequestValidator(object):
def check_realms(self, realms):
"""Check that the realm is one of a set allowed realms."""
- return all((r in self.realms for r in realms))
+ return all(r in self.realms for r in realms)
def _subclass_must_implement(self, fn):
"""
diff --git a/oauthlib/oauth1/rfc5849/signature.py b/oauthlib/oauth1/rfc5849/signature.py
index 243a586..fdc359e 100644
--- a/oauthlib/oauth1/rfc5849/signature.py
+++ b/oauthlib/oauth1/rfc5849/signature.py
@@ -21,22 +21,16 @@ Steps for signing a request:
.. _`section 3.4`: https://tools.ietf.org/html/rfc5849#section-3.4
"""
-from __future__ import absolute_import, unicode_literals
-
import binascii
import hashlib
import hmac
import logging
-from oauthlib.common import (extract_params, safe_string_equals,
- unicode_type, urldecode)
+from oauthlib.common import extract_params, safe_string_equals, urldecode
+import urllib.parse as urlparse
from . import utils
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
log = logging.getLogger(__name__)
@@ -128,7 +122,7 @@ def base_string_uri(uri, host=None):
The host argument overrides the netloc part of the uri argument.
"""
- if not isinstance(uri, unicode_type):
+ if not isinstance(uri, str):
raise ValueError('uri must be a unicode object.')
# FIXME: urlparse does not support unicode
@@ -301,7 +295,7 @@ def collect_parameters(uri_query='', body=[], headers=None,
#
# .. _`Section 3.5.1`: https://tools.ietf.org/html/rfc5849#section-3.5.1
if headers:
- headers_lower = dict((k.lower(), v) for k, v in headers.items())
+ headers_lower = {k.lower(): v for k, v in headers.items()}
authorization_header = headers_lower.get('authorization')
if authorization_header is not None:
params.extend([i for i in utils.parse_authorization_header(
@@ -430,7 +424,7 @@ def normalize_parameters(params):
# 3. The name of each parameter is concatenated to its corresponding
# value using an "=" character (ASCII code 61) as a separator, even
# if the value is empty.
- parameter_parts = ['{0}={1}'.format(k, v) for k, v in key_values]
+ parameter_parts = ['{}={}'.format(k, v) for k, v in key_values]
# 4. The sorted name/value pairs are concatenated together into a
# single string by using an "&" character (ASCII code 38) as
@@ -577,7 +571,7 @@ def sign_rsa_sha1(base_string, rsa_private_key):
.. _`RFC3447, Section 8.2`: https://tools.ietf.org/html/rfc3447#section-8.2
"""
- if isinstance(base_string, unicode_type):
+ if isinstance(base_string, str):
base_string = base_string.encode('utf-8')
# TODO: finish RSA documentation
alg = _jwt_rs1_signing_algorithm()
diff --git a/oauthlib/oauth1/rfc5849/utils.py b/oauthlib/oauth1/rfc5849/utils.py
index 735f21d..28e006a 100644
--- a/oauthlib/oauth1/rfc5849/utils.py
+++ b/oauthlib/oauth1/rfc5849/utils.py
@@ -6,14 +6,9 @@ oauthlib.utils
This module contains utility methods used by various parts of the OAuth
spec.
"""
-from __future__ import absolute_import, unicode_literals
+from oauthlib.common import quote, unquote
-from oauthlib.common import quote, unicode_type, unquote
-
-try:
- import urllib2
-except ImportError:
- import urllib.request as urllib2
+import urllib.request as urllib2
UNICODE_ASCII_CHARACTER_SET = ('abcdefghijklmnopqrstuvwxyz'
@@ -52,16 +47,16 @@ def escape(u):
.. _`section 3.6`: https://tools.ietf.org/html/rfc5849#section-3.6
"""
- if not isinstance(u, unicode_type):
+ if not isinstance(u, str):
raise ValueError('Only unicode objects are escapable. ' +
- 'Got %r of type %s.' % (u, type(u)))
+ 'Got {!r} of type {}.'.format(u, type(u)))
# Letters, digits, and the characters '_.-' are already treated as safe
# by urllib.quote(). We need to add '~' to fully support rfc5849.
return quote(u, safe=b'~')
def unescape(u):
- if not isinstance(u, unicode_type):
+ if not isinstance(u, str):
raise ValueError('Only unicode objects are unescapable.')
return unquote(u)
diff --git a/oauthlib/oauth2/__init__.py b/oauthlib/oauth2/__init__.py
index 3f43755..9186800 100644
--- a/oauthlib/oauth2/__init__.py
+++ b/oauthlib/oauth2/__init__.py
@@ -6,8 +6,6 @@ oauthlib.oauth2
This module is a wrapper for the most recent implementation of OAuth 2.0 Client
and Server classes.
"""
-from __future__ import absolute_import, unicode_literals
-
from .rfc6749.clients import Client
from .rfc6749.clients import WebApplicationClient
from .rfc6749.clients import MobileApplicationClient
diff --git a/oauthlib/oauth2/rfc6749/__init__.py b/oauthlib/oauth2/rfc6749/__init__.py
index 1a4128c..1c11234 100644
--- a/oauthlib/oauth2/rfc6749/__init__.py
+++ b/oauthlib/oauth2/rfc6749/__init__.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import functools
import logging
diff --git a/oauthlib/oauth2/rfc6749/clients/__init__.py b/oauthlib/oauth2/rfc6749/clients/__init__.py
index 17d0023..6fef738 100644
--- a/oauthlib/oauth2/rfc6749/clients/__init__.py
+++ b/oauthlib/oauth2/rfc6749/clients/__init__.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
from .base import Client, AUTH_HEADER, URI_QUERY, BODY
from .web_application import WebApplicationClient
from .mobile_application import MobileApplicationClient
diff --git a/oauthlib/oauth2/rfc6749/clients/backend_application.py b/oauthlib/oauth2/rfc6749/clients/backend_application.py
index 5737814..5ffe6ae 100644
--- a/oauthlib/oauth2/rfc6749/clients/backend_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/backend_application.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
from ..parameters import parse_token_response, prepare_token_request
from .base import Client
diff --git a/oauthlib/oauth2/rfc6749/clients/base.py b/oauthlib/oauth2/rfc6749/clients/base.py
index 9b05ad5..04dabe6 100644
--- a/oauthlib/oauth2/rfc6749/clients/base.py
+++ b/oauthlib/oauth2/rfc6749/clients/base.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import time
import warnings
@@ -29,7 +27,7 @@ FORM_ENC_HEADERS = {
}
-class Client(object):
+class Client:
"""Base OAuth2 client responsible for access token management.
This class also acts as a generic interface providing methods common to all
@@ -186,8 +184,8 @@ class Client(object):
token_placement = token_placement or self.default_token_placement
- case_insensitive_token_types = dict(
- (k.lower(), v) for k, v in self.token_types.items())
+ case_insensitive_token_types = {
+ k.lower(): v for k, v in self.token_types.items()}
if not self.token_type.lower() in case_insensitive_token_types:
raise ValueError("Unsupported token type: %s" % self.token_type)
diff --git a/oauthlib/oauth2/rfc6749/clients/legacy_application.py b/oauthlib/oauth2/rfc6749/clients/legacy_application.py
index ca218e4..1bb0e14 100644
--- a/oauthlib/oauth2/rfc6749/clients/legacy_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/legacy_application.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
from ..parameters import parse_token_response, prepare_token_request
from .base import Client
@@ -38,7 +36,7 @@ class LegacyApplicationClient(Client):
grant_type = 'password'
def __init__(self, client_id, **kwargs):
- super(LegacyApplicationClient, self).__init__(client_id, **kwargs)
+ super().__init__(client_id, **kwargs)
def prepare_request_body(self, username, password, body='', scope=None,
include_client_id=False, **kwargs):
diff --git a/oauthlib/oauth2/rfc6749/clients/mobile_application.py b/oauthlib/oauth2/rfc6749/clients/mobile_application.py
index 11c6c51..73627c4 100644
--- a/oauthlib/oauth2/rfc6749/clients/mobile_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/mobile_application.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
from ..parameters import parse_implicit_response, prepare_grant_uri
from .base import Client
diff --git a/oauthlib/oauth2/rfc6749/clients/service_application.py b/oauthlib/oauth2/rfc6749/clients/service_application.py
index ea946ce..09fc7ba 100644
--- a/oauthlib/oauth2/rfc6749/clients/service_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/service_application.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import time
from oauthlib.common import to_unicode
@@ -57,7 +55,7 @@ class ServiceApplicationClient(Client):
state and token. See ``Client.__init__.__doc__`` for
details.
"""
- super(ServiceApplicationClient, self).__init__(client_id, **kwargs)
+ super().__init__(client_id, **kwargs)
self.private_key = private_key
self.subject = subject
self.issuer = issuer
diff --git a/oauthlib/oauth2/rfc6749/clients/web_application.py b/oauthlib/oauth2/rfc6749/clients/web_application.py
index 0cd39ce..aedc9d1 100644
--- a/oauthlib/oauth2/rfc6749/clients/web_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/web_application.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import warnings
from ..parameters import (parse_authorization_code_response,
@@ -38,7 +36,7 @@ class WebApplicationClient(Client):
grant_type = 'authorization_code'
def __init__(self, client_id, code=None, **kwargs):
- super(WebApplicationClient, self).__init__(client_id, **kwargs)
+ super().__init__(client_id, **kwargs)
self.code = code
def prepare_request_uri(self, uri, redirect_uri=None, scope=None,
diff --git a/oauthlib/oauth2/rfc6749/endpoints/__init__.py b/oauthlib/oauth2/rfc6749/endpoints/__init__.py
index 51e173d..49e7ee9 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/__init__.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/__init__.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
from .authorization import AuthorizationEndpoint
from .introspect import IntrospectEndpoint
from .metadata import MetadataEndpoint
diff --git a/oauthlib/oauth2/rfc6749/endpoints/authorization.py b/oauthlib/oauth2/rfc6749/endpoints/authorization.py
index 92cde34..fd77f46 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/authorization.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/authorization.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.common import Request
diff --git a/oauthlib/oauth2/rfc6749/endpoints/base.py b/oauthlib/oauth2/rfc6749/endpoints/base.py
index e39232f..5169517 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/base.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/base.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import functools
import logging
@@ -20,7 +18,7 @@ from oauthlib.common import CaseInsensitiveDict, urldecode
log = logging.getLogger(__name__)
-class BaseEndpoint(object):
+class BaseEndpoint:
def __init__(self):
self._available = True
diff --git a/oauthlib/oauth2/rfc6749/endpoints/introspect.py b/oauthlib/oauth2/rfc6749/endpoints/introspect.py
index 4accbdc..bad8950 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/introspect.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/introspect.py
@@ -7,8 +7,6 @@ An implementation of the OAuth 2.0 `Token Introspection`.
.. _`Token Introspection`: https://tools.ietf.org/html/rfc7662
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import logging
diff --git a/oauthlib/oauth2/rfc6749/endpoints/metadata.py b/oauthlib/oauth2/rfc6749/endpoints/metadata.py
index 936e878..6bc078d 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/metadata.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/metadata.py
@@ -7,13 +7,10 @@ An implementation of the `OAuth 2.0 Authorization Server Metadata`.
.. _`OAuth 2.0 Authorization Server Metadata`: https://tools.ietf.org/html/rfc8414
"""
-from __future__ import absolute_import, unicode_literals
-
import copy
import json
import logging
-from ....common import unicode_type
from .base import BaseEndpoint, catch_errors_and_unavailability
from .authorization import AuthorizationEndpoint
from .introspect import IntrospectEndpoint
@@ -85,7 +82,7 @@ class MetadataEndpoint(BaseEndpoint):
if not isinstance(array[key], list):
raise ValueError("key {}: {} must be an Array".format(key, array[key]))
for elem in array[key]:
- if not isinstance(elem, unicode_type):
+ if not isinstance(elem, str):
raise ValueError("array {}: {} must contains only string (not {})".format(key, array[key], elem))
def validate_metadata_token(self, claims, endpoint):
diff --git a/oauthlib/oauth2/rfc6749/endpoints/pre_configured.py b/oauthlib/oauth2/rfc6749/endpoints/pre_configured.py
index e2cc9db..1855973 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/pre_configured.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/pre_configured.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749.endpoints.pre_configured
This module is an implementation of various endpoints needed
for providing OAuth 2.0 RFC6749 servers.
"""
-from __future__ import absolute_import, unicode_literals
-
from ..grant_types import (AuthorizationCodeGrant,
ClientCredentialsGrant,
ImplicitGrant,
diff --git a/oauthlib/oauth2/rfc6749/endpoints/resource.py b/oauthlib/oauth2/rfc6749/endpoints/resource.py
index f19c60c..76e57b1 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/resource.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/resource.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.common import Request
diff --git a/oauthlib/oauth2/rfc6749/endpoints/revocation.py b/oauthlib/oauth2/rfc6749/endpoints/revocation.py
index 1fabd03..ed245f3 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/revocation.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/revocation.py
@@ -7,8 +7,6 @@ An implementation of the OAuth 2 `Token Revocation`_ spec (draft 11).
.. _`Token Revocation`: https://tools.ietf.org/html/draft-ietf-oauth-revocation-11
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.common import Request
@@ -73,7 +71,7 @@ class RevocationEndpoint(BaseEndpoint):
log.debug('Client error during validation of %r. %r.', request, e)
response_body = e.json
if self.enable_jsonp and request.callback:
- response_body = '%s(%s);' % (request.callback, response_body)
+ response_body = '{}({});'.format(request.callback, response_body)
resp_headers.update(e.headers)
return resp_headers, response_body, e.status_code
diff --git a/oauthlib/oauth2/rfc6749/endpoints/token.py b/oauthlib/oauth2/rfc6749/endpoints/token.py
index bc87e9b..2b2d495 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/token.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/token.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.common import Request
diff --git a/oauthlib/oauth2/rfc6749/errors.py b/oauthlib/oauth2/rfc6749/errors.py
index d2a1402..9896303 100644
--- a/oauthlib/oauth2/rfc6749/errors.py
+++ b/oauthlib/oauth2/rfc6749/errors.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749.errors
Error used both by OAuth 2 clients and providers to represent the spec
defined error responses for all four core grant types.
"""
-from __future__ import unicode_literals
-
import json
from oauthlib.common import add_params_to_uri, urlencode
@@ -45,10 +43,10 @@ class OAuth2Error(Exception):
if description is not None:
self.description = description
- message = '(%s) %s' % (self.error, self.description)
+ message = '({}) {}'.format(self.error, self.description)
if request:
message += ' ' + repr(request)
- super(OAuth2Error, self).__init__(message)
+ super().__init__(message)
self.uri = uri
self.state = state
@@ -389,7 +387,7 @@ class CustomOAuth2Error(OAuth2Error):
"""
def __init__(self, error, *args, **kwargs):
self.error = error
- super(CustomOAuth2Error, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
def raise_from_error(error, params=None):
diff --git a/oauthlib/oauth2/rfc6749/grant_types/__init__.py b/oauthlib/oauth2/rfc6749/grant_types/__init__.py
index 2ec8e4f..30c90d7 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/__init__.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/__init__.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import unicode_literals, absolute_import
-
from .authorization_code import AuthorizationCodeGrant
from .implicit import ImplicitGrant
from .resource_owner_password_credentials import ResourceOwnerPasswordCredentialsGrant
diff --git a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
index 9b84c4c..f4bde86 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import base64
import hashlib
import json
diff --git a/oauthlib/oauth2/rfc6749/grant_types/base.py b/oauthlib/oauth2/rfc6749/grant_types/base.py
index f0772e2..66e1fd1 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/base.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/base.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from itertools import chain
@@ -17,7 +15,7 @@ from ..request_validator import RequestValidator
log = logging.getLogger(__name__)
-class ValidatorsContainer(object):
+class ValidatorsContainer:
"""
Container object for holding custom validator callables to be invoked
as part of the grant type `validate_authorization_request()` or
@@ -74,7 +72,7 @@ class ValidatorsContainer(object):
return chain(self.post_auth, self.post_token)
-class GrantTypeBase(object):
+class GrantTypeBase:
error_uri = None
request_validator = None
default_response_mode = 'fragment'
diff --git a/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py
index 7e50857..fdb0bf6 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/client_credentials.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import logging
diff --git a/oauthlib/oauth2/rfc6749/grant_types/implicit.py b/oauthlib/oauth2/rfc6749/grant_types/implicit.py
index 48bae7a..335e58c 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/implicit.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/implicit.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib import common
diff --git a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
index fc61d65..e7405d2 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import logging
@@ -25,7 +23,7 @@ class RefreshTokenGrant(GrantTypeBase):
def __init__(self, request_validator=None,
issue_new_refresh_tokens=True,
**kwargs):
- super(RefreshTokenGrant, self).__init__(
+ super().__init__(
request_validator,
issue_new_refresh_tokens=issue_new_refresh_tokens,
**kwargs)
@@ -126,7 +124,7 @@ class RefreshTokenGrant(GrantTypeBase):
if request.scope:
request.scopes = utils.scope_to_list(request.scope)
- if (not all((s in original_scopes for s in request.scopes))
+ if (not all(s in original_scopes for s in request.scopes)
and not self.request_validator.is_within_original_scope(
request.scopes, request.refresh_token, request)):
log.debug('Refresh token %s lack requested scopes, %r.',
diff --git a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py
index 5929afb..9c8ee1d 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py
@@ -3,8 +3,6 @@
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import logging
diff --git a/oauthlib/oauth2/rfc6749/parameters.py b/oauthlib/oauth2/rfc6749/parameters.py
index 14d4c0d..54c8d24 100644
--- a/oauthlib/oauth2/rfc6749/parameters.py
+++ b/oauthlib/oauth2/rfc6749/parameters.py
@@ -7,14 +7,13 @@ This module contains methods related to `Section 4`_ of the OAuth 2 RFC.
.. _`Section 4`: https://tools.ietf.org/html/rfc6749#section-4
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import os
import time
-from oauthlib.common import add_params_to_qs, add_params_to_uri, unicode_type
+from oauthlib.common import add_params_to_qs, add_params_to_uri
from oauthlib.signals import scope_changed
+import urllib.parse as urlparse
from .errors import (InsecureTransportError, MismatchingStateError,
MissingCodeError, MissingTokenError,
@@ -22,11 +21,6 @@ from .errors import (InsecureTransportError, MismatchingStateError,
from .tokens import OAuth2Token
from .utils import is_secure_transport, list_to_scope, scope_to_list
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
-
def prepare_grant_uri(uri, client_id, response_type, redirect_uri=None,
scope=None, state=None, **kwargs):
@@ -82,7 +76,7 @@ def prepare_grant_uri(uri, client_id, response_type, redirect_uri=None,
for k in kwargs:
if kwargs[k]:
- params.append((unicode_type(k), kwargs[k]))
+ params.append((str(k), kwargs[k]))
return add_params_to_uri(uri, params)
@@ -146,18 +140,18 @@ def prepare_token_request(grant_type, body='', include_client_id=True, **kwargs)
client_id = kwargs.pop('client_id', None)
if include_client_id:
if client_id is not None:
- params.append((unicode_type('client_id'), client_id))
+ params.append(('client_id', client_id))
# the kwargs iteration below only supports including boolean truth (truthy)
# values, but some servers may require an empty string for `client_secret`
client_secret = kwargs.pop('client_secret', None)
if client_secret is not None:
- params.append((unicode_type('client_secret'), client_secret))
+ params.append(('client_secret', client_secret))
# this handles: `code`, `redirect_uri`, and other undocumented params
for k in kwargs:
if kwargs[k]:
- params.append((unicode_type(k), kwargs[k]))
+ params.append((str(k), kwargs[k]))
return add_params_to_qs(body, params)
@@ -209,7 +203,7 @@ def prepare_token_revocation_request(url, token, token_type_hint="access_token",
for k in kwargs:
if kwargs[k]:
- params.append((unicode_type(k), kwargs[k]))
+ params.append((str(k), kwargs[k]))
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
diff --git a/oauthlib/oauth2/rfc6749/request_validator.py b/oauthlib/oauth2/rfc6749/request_validator.py
index 86509b6..78d025b 100644
--- a/oauthlib/oauth2/rfc6749/request_validator.py
+++ b/oauthlib/oauth2/rfc6749/request_validator.py
@@ -3,14 +3,12 @@
oauthlib.oauth2.rfc6749.request_validator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
log = logging.getLogger(__name__)
-class RequestValidator(object):
+class RequestValidator:
def client_authentication_required(self, request, *args, **kwargs):
"""Determine if client authentication is required for current request.
diff --git a/oauthlib/oauth2/rfc6749/tokens.py b/oauthlib/oauth2/rfc6749/tokens.py
index 3587af4..6f6b1f6 100644
--- a/oauthlib/oauth2/rfc6749/tokens.py
+++ b/oauthlib/oauth2/rfc6749/tokens.py
@@ -7,28 +7,23 @@ This module contains methods for adding two types of access tokens to requests.
- Bearer https://tools.ietf.org/html/rfc6750
- MAC https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01
"""
-from __future__ import absolute_import, unicode_literals
-
import hashlib
import hmac
from binascii import b2a_base64
import warnings
from oauthlib import common
-from oauthlib.common import add_params_to_qs, add_params_to_uri, unicode_type
+from oauthlib.common import add_params_to_qs, add_params_to_uri
+from urllib.parse import urlparse
from . import utils
-try:
- from urlparse import urlparse
-except ImportError:
- from urllib.parse import urlparse
class OAuth2Token(dict):
def __init__(self, params, old_scope=None):
- super(OAuth2Token, self).__init__(params)
+ super().__init__(params)
self._new_scope = None
if 'scope' in params and params['scope']:
self._new_scope = set(utils.scope_to_list(params['scope']))
@@ -121,7 +116,7 @@ def prepare_mac_header(token, uri, key, http_method,
raise ValueError('unknown hash algorithm')
if draft == 0:
- nonce = nonce or '{0}:{1}'.format(utils.generate_age(issue_time),
+ nonce = nonce or '{}:{}'.format(utils.generate_age(issue_time),
common.generate_nonce())
else:
ts = common.generate_timestamp()
@@ -158,7 +153,7 @@ def prepare_mac_header(token, uri, key, http_method,
base_string = '\n'.join(base) + '\n'
# hmac struggles with unicode strings - http://bugs.python.org/issue5285
- if isinstance(key, unicode_type):
+ if isinstance(key, str):
key = key.encode('utf-8')
sign = hmac.new(key, base_string.encode('utf-8'), h)
sign = b2a_base64(sign.digest())[:-1].decode('utf-8')
@@ -262,7 +257,7 @@ def get_token_from_header(request):
return token
-class TokenBase(object):
+class TokenBase:
def __call__(self, request, refresh_token=False):
raise NotImplementedError('Subclasses must implement this method.')
diff --git a/oauthlib/oauth2/rfc6749/utils.py b/oauthlib/oauth2/rfc6749/utils.py
index f67019d..3117d4b 100644
--- a/oauthlib/oauth2/rfc6749/utils.py
+++ b/oauthlib/oauth2/rfc6749/utils.py
@@ -5,29 +5,20 @@ oauthlib.utils
This module contains utility methods used by various parts of the OAuth 2 spec.
"""
-from __future__ import absolute_import, unicode_literals
-
import datetime
import os
-from oauthlib.common import unicode_type, urldecode
-
-try:
- from urllib import quote
-except ImportError:
- from urllib.parse import quote
-try:
- from urlparse import urlparse
-except ImportError:
- from urllib.parse import urlparse
+from oauthlib.common import urldecode
+from urllib.parse import quote
+from urllib.parse import urlparse
def list_to_scope(scope):
"""Convert a list of scopes to a space separated string."""
- if isinstance(scope, unicode_type) or scope is None:
+ if isinstance(scope, str) or scope is None:
return scope
elif isinstance(scope, (set, tuple, list)):
- return " ".join([unicode_type(s) for s in scope])
+ return " ".join([str(s) for s in scope])
else:
raise ValueError("Invalid scope (%s), must be string, tuple, set, or list." % scope)
@@ -35,7 +26,7 @@ def list_to_scope(scope):
def scope_to_list(scope):
"""Convert a space separated string to a list of scopes."""
if isinstance(scope, (tuple, list, set)):
- return [unicode_type(s) for s in scope]
+ return [str(s) for s in scope]
elif scope is None:
return None
else:
@@ -74,7 +65,7 @@ def escape(u):
TODO: verify whether this can in fact be used for OAuth 2
"""
- if not isinstance(u, unicode_type):
+ if not isinstance(u, str):
raise ValueError('Only unicode objects are escapable.')
return quote(u.encode('utf-8'), safe=b'~')
@@ -84,7 +75,7 @@ def generate_age(issue_time):
td = datetime.datetime.now() - issue_time
age = (td.microseconds + (td.seconds + td.days * 24 * 3600)
* 10 ** 6) / 10 ** 6
- return unicode_type(age)
+ return str(age)
def is_secure_transport(uri):
diff --git a/oauthlib/openid/__init__.py b/oauthlib/openid/__init__.py
index 8157c29..fb1ac8d 100644
--- a/oauthlib/openid/__init__.py
+++ b/oauthlib/openid/__init__.py
@@ -4,8 +4,6 @@ oauthlib.openid
~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
from .connect.core.endpoints import Server
from .connect.core.endpoints import UserInfoEndpoint
from .connect.core.request_validator import RequestValidator
diff --git a/oauthlib/openid/connect/core/endpoints/__init__.py b/oauthlib/openid/connect/core/endpoints/__init__.py
index 528841f..92f1ba9 100644
--- a/oauthlib/openid/connect/core/endpoints/__init__.py
+++ b/oauthlib/openid/connect/core/endpoints/__init__.py
@@ -6,7 +6,5 @@ oauthlib.oopenid.core
This module is an implementation of various logic needed
for consuming and providing OpenID Connect
"""
-from __future__ import absolute_import, unicode_literals
-
from .pre_configured import Server
from .userinfo import UserInfoEndpoint
diff --git a/oauthlib/openid/connect/core/endpoints/pre_configured.py b/oauthlib/openid/connect/core/endpoints/pre_configured.py
index fde2739..ad2faa7 100644
--- a/oauthlib/openid/connect/core/endpoints/pre_configured.py
+++ b/oauthlib/openid/connect/core/endpoints/pre_configured.py
@@ -6,8 +6,6 @@ oauthlib.openid.connect.core.endpoints.pre_configured
This module is an implementation of various endpoints needed
for providing OpenID Connect servers.
"""
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.oauth2.rfc6749.endpoints import (
AuthorizationEndpoint,
IntrospectEndpoint,
diff --git a/oauthlib/openid/connect/core/endpoints/userinfo.py b/oauthlib/openid/connect/core/endpoints/userinfo.py
index 7a39f76..dc73373 100644
--- a/oauthlib/openid/connect/core/endpoints/userinfo.py
+++ b/oauthlib/openid/connect/core/endpoints/userinfo.py
@@ -4,13 +4,10 @@ oauthlib.openid.connect.core.endpoints.userinfo
This module is an implementation of userinfo endpoint.
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import logging
from oauthlib.common import Request
-from oauthlib.common import unicode_type
from oauthlib.oauth2.rfc6749.endpoints.base import BaseEndpoint
from oauthlib.oauth2.rfc6749.endpoints.base import catch_errors_and_unavailability
from oauthlib.oauth2.rfc6749.tokens import BearerToken
@@ -55,7 +52,7 @@ class UserInfoEndpoint(BaseEndpoint):
log.error('Userinfo MUST have "sub" for %r.', request)
raise errors.ServerError(status_code=500)
body = json.dumps(claims)
- elif isinstance(claims, unicode_type):
+ elif isinstance(claims, str):
resp_headers = {
'Content-Type': 'application/jwt'
}
diff --git a/oauthlib/openid/connect/core/exceptions.py b/oauthlib/openid/connect/core/exceptions.py
index 8b08d21..aa795e0 100644
--- a/oauthlib/openid/connect/core/exceptions.py
+++ b/oauthlib/openid/connect/core/exceptions.py
@@ -6,8 +6,6 @@ oauthlib.oauth2.rfc6749.errors
Error used both by OAuth 2 clients and providers to represent the spec
defined error responses for all four core grant types.
"""
-from __future__ import unicode_literals
-
from oauthlib.oauth2.rfc6749.errors import FatalClientError, OAuth2Error
diff --git a/oauthlib/openid/connect/core/grant_types/__init__.py b/oauthlib/openid/connect/core/grant_types/__init__.py
index 63f30ac..4e7b474 100644
--- a/oauthlib/openid/connect/core/grant_types/__init__.py
+++ b/oauthlib/openid/connect/core/grant_types/__init__.py
@@ -3,8 +3,6 @@
oauthlib.openid.connect.core.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import unicode_literals, absolute_import
-
from .authorization_code import AuthorizationCodeGrant
from .implicit import ImplicitGrant
from .base import GrantTypeBase
diff --git a/oauthlib/openid/connect/core/grant_types/authorization_code.py b/oauthlib/openid/connect/core/grant_types/authorization_code.py
index becfcfa..d07d138 100644
--- a/oauthlib/openid/connect/core/grant_types/authorization_code.py
+++ b/oauthlib/openid/connect/core/grant_types/authorization_code.py
@@ -3,8 +3,6 @@
oauthlib.openid.connect.core.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.oauth2.rfc6749.grant_types.authorization_code import AuthorizationCodeGrant as OAuth2AuthorizationCodeGrant
@@ -41,4 +39,4 @@ class AuthorizationCodeGrant(GrantTypeBase):
request.redirect_uri,
request
)
- return super(AuthorizationCodeGrant, self).add_id_token(token, token_handler, request, nonce=nonce)
+ return super().add_id_token(token, token_handler, request, nonce=nonce)
diff --git a/oauthlib/openid/connect/core/grant_types/base.py b/oauthlib/openid/connect/core/grant_types/base.py
index 32a21b6..cd27237 100644
--- a/oauthlib/openid/connect/core/grant_types/base.py
+++ b/oauthlib/openid/connect/core/grant_types/base.py
@@ -11,7 +11,7 @@ from oauthlib.oauth2.rfc6749.errors import ConsentRequired, InvalidRequestError,
log = logging.getLogger(__name__)
-class GrantTypeBase(object):
+class GrantTypeBase:
# Just proxy the majority of method calls through to the
# proxy_target grant type handler, which will usually be either
@@ -20,7 +20,7 @@ class GrantTypeBase(object):
return getattr(self.proxy_target, attr)
def __setattr__(self, attr, value):
- proxied_attrs = set(('refresh_token', 'response_types'))
+ proxied_attrs = {'refresh_token', 'response_types'}
if attr in proxied_attrs:
setattr(self.proxy_target, attr, value)
else:
diff --git a/oauthlib/openid/connect/core/grant_types/dispatchers.py b/oauthlib/openid/connect/core/grant_types/dispatchers.py
index be8e2f3..541467a 100644
--- a/oauthlib/openid/connect/core/grant_types/dispatchers.py
+++ b/oauthlib/openid/connect/core/grant_types/dispatchers.py
@@ -2,7 +2,7 @@ import logging
log = logging.getLogger(__name__)
-class Dispatcher(object):
+class Dispatcher:
default_grant = None
oidc_grant = None
diff --git a/oauthlib/openid/connect/core/grant_types/exceptions.py b/oauthlib/openid/connect/core/grant_types/exceptions.py
index 809f1b3..4636fe7 100644
--- a/oauthlib/openid/connect/core/grant_types/exceptions.py
+++ b/oauthlib/openid/connect/core/grant_types/exceptions.py
@@ -29,4 +29,4 @@ class OIDCNoPrompt(Exception):
"for authorization, it should been done using silent "
"authentication through create_authorization_response. "
"See OIDCNoPrompt.__doc__ for more details.")
- super(OIDCNoPrompt, self).__init__(msg)
+ super().__init__(msg)
diff --git a/oauthlib/openid/connect/core/grant_types/hybrid.py b/oauthlib/openid/connect/core/grant_types/hybrid.py
index 685fa08..caf8547 100644
--- a/oauthlib/openid/connect/core/grant_types/hybrid.py
+++ b/oauthlib/openid/connect/core/grant_types/hybrid.py
@@ -3,8 +3,6 @@
oauthlib.openid.connect.core.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.oauth2.rfc6749.grant_types.authorization_code import AuthorizationCodeGrant as OAuth2AuthorizationCodeGrant
@@ -39,7 +37,7 @@ class HybridGrant(GrantTypeBase):
def openid_authorization_validator(self, request):
"""Additional validation when following the Authorization Code flow.
"""
- request_info = super(HybridGrant, self).openid_authorization_validator(request)
+ request_info = super().openid_authorization_validator(request)
if not request_info: # returns immediately if OAuth2.0
return request_info
diff --git a/oauthlib/openid/connect/core/grant_types/implicit.py b/oauthlib/openid/connect/core/grant_types/implicit.py
index c2dbc27..62f63f9 100644
--- a/oauthlib/openid/connect/core/grant_types/implicit.py
+++ b/oauthlib/openid/connect/core/grant_types/implicit.py
@@ -3,8 +3,6 @@
oauthlib.openid.connect.core.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from .base import GrantTypeBase
@@ -29,12 +27,12 @@ class ImplicitGrant(GrantTypeBase):
def add_id_token(self, token, token_handler, request):
if 'state' not in token and request.state:
token['state'] = request.state
- return super(ImplicitGrant, self).add_id_token(token, token_handler, request, nonce=request.nonce)
+ return super().add_id_token(token, token_handler, request, nonce=request.nonce)
def openid_authorization_validator(self, request):
"""Additional validation when following the implicit flow.
"""
- request_info = super(ImplicitGrant, self).openid_authorization_validator(request)
+ request_info = super().openid_authorization_validator(request)
if not request_info: # returns immediately if OAuth2.0
return request_info
diff --git a/oauthlib/openid/connect/core/request_validator.py b/oauthlib/openid/connect/core/request_validator.py
index e853d39..ebc07dc 100644
--- a/oauthlib/openid/connect/core/request_validator.py
+++ b/oauthlib/openid/connect/core/request_validator.py
@@ -3,8 +3,6 @@
oauthlib.openid.connect.core.request_validator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from __future__ import absolute_import, unicode_literals
-
import logging
from oauthlib.oauth2.rfc6749.request_validator import RequestValidator as OAuth2RequestValidator
diff --git a/oauthlib/openid/connect/core/tokens.py b/oauthlib/openid/connect/core/tokens.py
index b67cdf2..d24cb56 100644
--- a/oauthlib/openid/connect/core/tokens.py
+++ b/oauthlib/openid/connect/core/tokens.py
@@ -4,9 +4,6 @@ authlib.openid.connect.core.tokens
This module contains methods for adding JWT tokens to requests.
"""
-from __future__ import absolute_import, unicode_literals
-
-
from oauthlib.oauth2.rfc6749.tokens import TokenBase, random_token_generator
diff --git a/oauthlib/signals.py b/oauthlib/signals.py
index 22d47a4..9356cc2 100644
--- a/oauthlib/signals.py
+++ b/oauthlib/signals.py
@@ -9,11 +9,11 @@ try:
from blinker import Namespace
signals_available = True
except ImportError: # noqa
- class Namespace(object):
+ class Namespace:
def signal(self, name, doc=None):
return _FakeSignal(name, doc)
- class _FakeSignal(object):
+ class _FakeSignal:
"""If blinker is unavailable, create a fake class with the same
interface that allows sending of signals but will fail with an
error on anything else. Instead of doing anything on send, it
diff --git a/oauthlib/uri_validate.py b/oauthlib/uri_validate.py
index ce8ea40..93b6131 100644
--- a/oauthlib/uri_validate.py
+++ b/oauthlib/uri_validate.py
@@ -8,8 +8,6 @@ They should be processed with re.VERBOSE.
Thanks Mark Nottingham for this code - https://gist.github.com/138549
"""
-from __future__ import unicode_literals
-
import re
# basics
diff --git a/setup.py b/setup.py
index 7c4e8c4..9e248dd 100755
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,6 @@ try:
except ImportError:
pass
-import sys
from os.path import dirname, join
from setuptools import find_packages, setup
@@ -37,7 +36,7 @@ setup(
platforms='any',
license='BSD',
packages=find_packages(exclude=('docs', 'tests', 'tests.*')),
- python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, != 3.4.*',
+ python_requires='>=3.5',
extras_require={
'rsa': rsa_require,
'signedtoken': signedtoken_require,
@@ -53,12 +52,11 @@ setup(
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
- 'Programming Language :: Python :: 2',
- 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
diff --git a/tests/oauth1/rfc5849/endpoints/test_access_token.py b/tests/oauth1/rfc5849/endpoints/test_access_token.py
index 3499fdb..9ba8a3e 100644
--- a/tests/oauth1/rfc5849/endpoints/test_access_token.py
+++ b/tests/oauth1/rfc5849/endpoints/test_access_token.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from mock import ANY, MagicMock
from oauthlib.oauth1 import RequestValidator
diff --git a/tests/oauth1/rfc5849/endpoints/test_authorization.py b/tests/oauth1/rfc5849/endpoints/test_authorization.py
index e9d3604..178bddf 100644
--- a/tests/oauth1/rfc5849/endpoints/test_authorization.py
+++ b/tests/oauth1/rfc5849/endpoints/test_authorization.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from mock import MagicMock
from oauthlib.oauth1 import RequestValidator
diff --git a/tests/oauth1/rfc5849/endpoints/test_base.py b/tests/oauth1/rfc5849/endpoints/test_base.py
index 795ddee..de6c1a4 100644
--- a/tests/oauth1/rfc5849/endpoints/test_base.py
+++ b/tests/oauth1/rfc5849/endpoints/test_base.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from re import sub
from mock import MagicMock
diff --git a/tests/oauth1/rfc5849/endpoints/test_request_token.py b/tests/oauth1/rfc5849/endpoints/test_request_token.py
index 5c9ae88..ece36bd 100644
--- a/tests/oauth1/rfc5849/endpoints/test_request_token.py
+++ b/tests/oauth1/rfc5849/endpoints/test_request_token.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from mock import ANY, MagicMock
from oauthlib.oauth1 import RequestValidator
diff --git a/tests/oauth1/rfc5849/endpoints/test_resource.py b/tests/oauth1/rfc5849/endpoints/test_resource.py
index b71412a..41c9aee 100644
--- a/tests/oauth1/rfc5849/endpoints/test_resource.py
+++ b/tests/oauth1/rfc5849/endpoints/test_resource.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from mock import ANY, MagicMock
from oauthlib.oauth1 import RequestValidator
diff --git a/tests/oauth1/rfc5849/endpoints/test_signature_only.py b/tests/oauth1/rfc5849/endpoints/test_signature_only.py
index 1d758b1..9804137 100644
--- a/tests/oauth1/rfc5849/endpoints/test_signature_only.py
+++ b/tests/oauth1/rfc5849/endpoints/test_signature_only.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from mock import ANY, MagicMock
from oauthlib.oauth1 import RequestValidator
diff --git a/tests/oauth1/rfc5849/test_client.py b/tests/oauth1/rfc5849/test_client.py
index e1f83de..5c805a1 100644
--- a/tests/oauth1/rfc5849/test_client.py
+++ b/tests/oauth1/rfc5849/test_client.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.common import Request
from oauthlib.oauth1 import (SIGNATURE_PLAINTEXT, SIGNATURE_HMAC_SHA1,
SIGNATURE_HMAC_SHA256, SIGNATURE_RSA,
@@ -163,7 +161,7 @@ class SignatureMethodTest(TestCase):
Client.register_signature_method('PIZZA',
lambda base_string, client: 'PIZZA')
- self.assertTrue('PIZZA' in Client.SIGNATURE_METHODS)
+ self.assertIn('PIZZA', Client.SIGNATURE_METHODS)
client = Client('client_key', signature_method='PIZZA',
timestamp='1234567890', nonce='abc')
diff --git a/tests/oauth1/rfc5849/test_parameters.py b/tests/oauth1/rfc5849/test_parameters.py
index ae72fd7..3afbb3a 100644
--- a/tests/oauth1/rfc5849/test_parameters.py
+++ b/tests/oauth1/rfc5849/test_parameters.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.common import urlencode
from oauthlib.oauth1.rfc5849.parameters import (_append_params,
prepare_form_encoded_body,
diff --git a/tests/oauth1/rfc5849/test_request_validator.py b/tests/oauth1/rfc5849/test_request_validator.py
index 88bbcdc..a3fe58f 100644
--- a/tests/oauth1/rfc5849/test_request_validator.py
+++ b/tests/oauth1/rfc5849/test_request_validator.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.oauth1 import RequestValidator
from ...unittest import TestCase
diff --git a/tests/oauth1/rfc5849/test_signatures.py b/tests/oauth1/rfc5849/test_signatures.py
index 5ff0989..89219f7 100644
--- a/tests/oauth1/rfc5849/test_signatures.py
+++ b/tests/oauth1/rfc5849/test_signatures.py
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
-from oauthlib.common import unicode_type
from oauthlib.oauth1.rfc5849.signature import (collect_parameters,
signature_base_string,
base_string_uri,
@@ -12,13 +9,10 @@ from oauthlib.oauth1.rfc5849.signature import (collect_parameters,
sign_plaintext_with_client,
sign_rsa_sha1,
sign_rsa_sha1_with_client)
+from urllib.parse import quote
from ...unittest import TestCase
-try:
- from urllib import quote
-except ImportError:
- from urllib.parse import quote
@@ -241,7 +235,7 @@ class SignatureTests(TestCase):
normalized = normalize_parameters(parameters)
# Unicode everywhere and always
- self.assertIsInstance(normalized, unicode_type)
+ self.assertIsInstance(normalized, str)
# Lets see if things are in order
# check to see that querystring keys come in alphanumeric order:
diff --git a/tests/oauth1/rfc5849/test_utils.py b/tests/oauth1/rfc5849/test_utils.py
index 5a889e8..ba8ed0e 100644
--- a/tests/oauth1/rfc5849/test_utils.py
+++ b/tests/oauth1/rfc5849/test_utils.py
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
-from oauthlib.common import unicode_type
from oauthlib.oauth1.rfc5849.utils import *
from ...unittest import TestCase
@@ -102,12 +99,12 @@ class UtilsTests(TestCase):
def test_escape(self):
self.assertRaises(ValueError, escape, b"I am a string type. Not a unicode type.")
self.assertEqual(escape("I am a unicode type."), "I%20am%20a%20unicode%20type.")
- self.assertIsInstance(escape("I am a unicode type."), unicode_type)
+ self.assertIsInstance(escape("I am a unicode type."), str)
def test_unescape(self):
self.assertRaises(ValueError, unescape, b"I am a string type. Not a unicode type.")
self.assertEqual(unescape("I%20am%20a%20unicode%20type."), 'I am a unicode type.')
- self.assertIsInstance(unescape("I%20am%20a%20unicode%20type."), unicode_type)
+ self.assertIsInstance(unescape("I%20am%20a%20unicode%20type."), str)
def test_parse_authorization_header(self):
# make us some headers
@@ -122,8 +119,8 @@ class UtilsTests(TestCase):
# are the internal components of each tuple unicode?
for k, v in authorization_headers:
- self.assertIsInstance(k, unicode_type)
- self.assertIsInstance(v, unicode_type)
+ self.assertIsInstance(k, str)
+ self.assertIsInstance(v, str)
# let's check the parsed headers created
correct_headers = [
diff --git a/tests/oauth2/rfc6749/clients/test_backend_application.py b/tests/oauth2/rfc6749/clients/test_backend_application.py
index aa2ba2b..8d80b39 100644
--- a/tests/oauth2/rfc6749/clients/test_backend_application.py
+++ b/tests/oauth2/rfc6749/clients/test_backend_application.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import os
from mock import patch
diff --git a/tests/oauth2/rfc6749/clients/test_base.py b/tests/oauth2/rfc6749/clients/test_base.py
index d48a944..c545c25 100644
--- a/tests/oauth2/rfc6749/clients/test_base.py
+++ b/tests/oauth2/rfc6749/clients/test_base.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import datetime
from oauthlib import common
@@ -295,11 +293,11 @@ class ClientTest(TestCase):
u, h, b = client.prepare_refresh_token_request(url, token, scope=scope)
self.assertEqual(u, url)
self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'})
- self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope=%s&refresh_token=%s' % (scope, token))
+ self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope={}&refresh_token={}'.format(scope, token))
# provide scope while init
client = Client(self.client_id, scope=scope)
u, h, b = client.prepare_refresh_token_request(url, token, scope=scope)
self.assertEqual(u, url)
self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'})
- self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope=%s&refresh_token=%s' % (scope, token))
+ self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope={}&refresh_token={}'.format(scope, token))
diff --git a/tests/oauth2/rfc6749/clients/test_legacy_application.py b/tests/oauth2/rfc6749/clients/test_legacy_application.py
index 21af4a3..34ea108 100644
--- a/tests/oauth2/rfc6749/clients/test_legacy_application.py
+++ b/tests/oauth2/rfc6749/clients/test_legacy_application.py
@@ -1,20 +1,14 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import os
from mock import patch
from oauthlib import signals
from oauthlib.oauth2 import LegacyApplicationClient
+import urllib.parse as urlparse
from ....unittest import TestCase
-# this is the same import method used in oauthlib/oauth2/rfc6749/parameters.py
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
@patch('time.time', new=lambda: 1000)
@@ -32,7 +26,7 @@ class LegacyApplicationClientTest(TestCase):
password = "user_password"
body = "not=empty"
- body_up = "not=empty&grant_type=password&username=%s&password=%s" % (username, password)
+ body_up = "not=empty&grant_type=password&username={}&password={}".format(username, password)
body_kwargs = body_up + "&some=providers&require=extra+arguments"
token_json = ('{ "access_token":"2YotnFZFEjr1zCsicMWpAA",'
@@ -105,8 +99,8 @@ class LegacyApplicationClientTest(TestCase):
# scenario 1, default behavior to not include `client_id`
r1 = client.prepare_request_body(username=self.username, password=self.password)
- self.assertIn(r1, ('grant_type=password&username=%s&password=%s' % (self.username, self.password, ),
- 'grant_type=password&password=%s&username=%s' % (self.password, self.username, ),
+ self.assertIn(r1, ('grant_type=password&username={}&password={}'.format(self.username, self.password),
+ 'grant_type=password&password={}&username={}'.format(self.password, self.username),
))
# scenario 2, include `client_id` in the body
diff --git a/tests/oauth2/rfc6749/clients/test_mobile_application.py b/tests/oauth2/rfc6749/clients/test_mobile_application.py
index 622b275..e2bdebe 100644
--- a/tests/oauth2/rfc6749/clients/test_mobile_application.py
+++ b/tests/oauth2/rfc6749/clients/test_mobile_application.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import os
from mock import patch
diff --git a/tests/oauth2/rfc6749/clients/test_service_application.py b/tests/oauth2/rfc6749/clients/test_service_application.py
index dc337cf..ba9406b 100644
--- a/tests/oauth2/rfc6749/clients/test_service_application.py
+++ b/tests/oauth2/rfc6749/clients/test_service_application.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import os
from time import time
diff --git a/tests/oauth2/rfc6749/clients/test_web_application.py b/tests/oauth2/rfc6749/clients/test_web_application.py
index 092f93e..e3382c8 100644
--- a/tests/oauth2/rfc6749/clients/test_web_application.py
+++ b/tests/oauth2/rfc6749/clients/test_web_application.py
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
-import datetime
import os
import warnings
@@ -13,14 +10,10 @@ from oauthlib.oauth2 import (BackendApplicationClient, Client,
WebApplicationClient)
from oauthlib.oauth2.rfc6749 import errors, utils
from oauthlib.oauth2.rfc6749.clients import AUTH_HEADER, BODY, URI_QUERY
+import urllib.parse as urlparse
from ....unittest import TestCase
-# this is the same import method used in oauthlib/oauth2/rfc6749/parameters.py
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
@patch('time.time', new=lambda: 1000)
@@ -46,7 +39,7 @@ class WebApplicationClientTest(TestCase):
code = "zzzzaaaa"
body = "not=empty"
- body_code = "not=empty&grant_type=authorization_code&code=%s&client_id=%s" % (code, client_id)
+ body_code = "not=empty&grant_type=authorization_code&code={}&client_id={}".format(code, client_id)
body_redirect = body_code + "&redirect_uri=http%3A%2F%2Fmy.page.com%2Fcallback"
body_kwargs = body_code + "&some=providers&require=extra+arguments"
diff --git a/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py
index bf04a42..2289b58 100644
--- a/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py
+++ b/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.oauth2 import (FatalClientError, OAuth2Error, RequestValidator,
Server)
from oauthlib.oauth2.rfc6749 import (BaseEndpoint,
diff --git a/tests/oauth2/rfc6749/endpoints/test_client_authentication.py b/tests/oauth2/rfc6749/endpoints/test_client_authentication.py
index 133da59..48b5485 100644
--- a/tests/oauth2/rfc6749/endpoints/test_client_authentication.py
+++ b/tests/oauth2/rfc6749/endpoints/test_client_authentication.py
@@ -9,8 +9,6 @@ We make sure authentication is done by requiring a client object to be set
on the request object with a client_id parameter. The client_id attribute
prevents this check from being circumvented with a client form parameter.
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py b/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py
index e7c66b6..bda71f7 100644
--- a/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py
+++ b/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py
@@ -3,8 +3,6 @@
The Authorization Code Grant will need to preserve state as well as redirect
uri and the Implicit Grant will need to preserve state.
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/endpoints/test_error_responses.py b/tests/oauth2/rfc6749/endpoints/test_error_responses.py
index 2479836..cdf2b63 100644
--- a/tests/oauth2/rfc6749/endpoints/test_error_responses.py
+++ b/tests/oauth2/rfc6749/endpoints/test_error_responses.py
@@ -1,7 +1,5 @@
"""Ensure the correct error responses are returned for all defined error types.
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py b/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py
index a12fcd2..6895dcd 100644
--- a/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py
+++ b/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py
@@ -1,7 +1,5 @@
"""Ensure extra credentials can be supplied for inclusion in tokens.
"""
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.oauth2 import (BackendApplicationServer, LegacyApplicationServer,
diff --git a/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py
index ae3deae..0942d96 100644
--- a/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py
+++ b/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from json import loads
from mock import MagicMock
diff --git a/tests/oauth2/rfc6749/endpoints/test_metadata.py b/tests/oauth2/rfc6749/endpoints/test_metadata.py
index 4813b46..a01500f 100644
--- a/tests/oauth2/rfc6749/endpoints/test_metadata.py
+++ b/tests/oauth2/rfc6749/endpoints/test_metadata.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.oauth2 import MetadataEndpoint
from oauthlib.oauth2 import TokenEndpoint
from oauthlib.oauth2 import Server
diff --git a/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py b/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py
index e823286..9e9d836 100644
--- a/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py
+++ b/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py
@@ -1,7 +1,5 @@
"""Ensure all tokens are associated with a resource owner.
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
index 17be3a5..0e3b2e1 100644
--- a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
+++ b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from json import loads
from mock import MagicMock
diff --git a/tests/oauth2/rfc6749/endpoints/test_scope_handling.py b/tests/oauth2/rfc6749/endpoints/test_scope_handling.py
index 4f27963..65e0e3c 100644
--- a/tests/oauth2/rfc6749/endpoints/test_scope_handling.py
+++ b/tests/oauth2/rfc6749/endpoints/test_scope_handling.py
@@ -3,8 +3,6 @@
Fairly trivial in all grants except the Authorization Code Grant where scope
need to be persisted temporarily in an authorization code.
"""
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
@@ -65,13 +63,13 @@ class TestScopeHandling(TestCase):
for scope, correct_scopes in scopes:
scopes, _ = self.web.validate_authorization_request(
uri % (scope, 'code'))
- self.assertItemsEqual(scopes, correct_scopes)
+ self.assertCountEqual(scopes, correct_scopes)
scopes, _ = self.mobile.validate_authorization_request(
uri % (scope, 'token'))
- self.assertItemsEqual(scopes, correct_scopes)
+ self.assertCountEqual(scopes, correct_scopes)
scopes, _ = self.server.validate_authorization_request(
uri % (scope, 'code'))
- self.assertItemsEqual(scopes, correct_scopes)
+ self.assertCountEqual(scopes, correct_scopes)
def test_scope_preservation(self):
scope = 'pics+http%3A%2f%2fa.b%2fvideos'
diff --git a/tests/oauth2/rfc6749/endpoints/test_utils.py b/tests/oauth2/rfc6749/endpoints/test_utils.py
index 6b7cff8..5eae195 100644
--- a/tests/oauth2/rfc6749/endpoints/test_utils.py
+++ b/tests/oauth2/rfc6749/endpoints/test_utils.py
@@ -1,7 +1,4 @@
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
+import urllib.parse as urlparse
def get_query_credentials(uri):
diff --git a/tests/oauth2/rfc6749/grant_types/test_authorization_code.py b/tests/oauth2/rfc6749/grant_types/test_authorization_code.py
index 2c9db3c..4ed9086 100644
--- a/tests/oauth2/rfc6749/grant_types/test_authorization_code.py
+++ b/tests/oauth2/rfc6749/grant_types/test_authorization_code.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/grant_types/test_client_credentials.py b/tests/oauth2/rfc6749/grant_types/test_client_credentials.py
index edc6bfe..d994278 100644
--- a/tests/oauth2/rfc6749/grant_types/test_client_credentials.py
+++ b/tests/oauth2/rfc6749/grant_types/test_client_credentials.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/grant_types/test_implicit.py b/tests/oauth2/rfc6749/grant_types/test_implicit.py
index 0c18cab..ffd766a 100644
--- a/tests/oauth2/rfc6749/grant_types/test_implicit.py
+++ b/tests/oauth2/rfc6749/grant_types/test_implicit.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.common import Request
diff --git a/tests/oauth2/rfc6749/grant_types/test_refresh_token.py b/tests/oauth2/rfc6749/grant_types/test_refresh_token.py
index 32a0977..074f359 100644
--- a/tests/oauth2/rfc6749/grant_types/test_refresh_token.py
+++ b/tests/oauth2/rfc6749/grant_types/test_refresh_token.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py b/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py
index 82e0524..4e93015 100644
--- a/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py
+++ b/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
diff --git a/tests/oauth2/rfc6749/test_parameters.py b/tests/oauth2/rfc6749/test_parameters.py
index 48b7eac..e9b3621 100644
--- a/tests/oauth2/rfc6749/test_parameters.py
+++ b/tests/oauth2/rfc6749/test_parameters.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
from mock import patch
from oauthlib import signals
@@ -77,9 +75,9 @@ class ParameterTests(TestCase):
error_invalid = 'https://client.example.com/cb?error=invalid_request&state=xyz'
implicit_base = 'https://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA&scope=abc&'
- implicit_response = implicit_base + 'state={0}&token_type=example&expires_in=3600'.format(state)
- implicit_notype = implicit_base + 'state={0}&expires_in=3600'.format(state)
- implicit_wrongstate = implicit_base + 'state={0}&token_type=exampleexpires_in=3600'.format('invalid')
+ implicit_response = implicit_base + 'state={}&token_type=example&expires_in=3600'.format(state)
+ implicit_notype = implicit_base + 'state={}&expires_in=3600'.format(state)
+ implicit_wrongstate = implicit_base + 'state={}&token_type=exampleexpires_in=3600'.format('invalid')
implicit_nostate = implicit_base + 'token_type=example&expires_in=3600'
implicit_notoken = 'https://example.com/cb#state=xyz&token_type=example&expires_in=3600'
@@ -244,7 +242,7 @@ class ParameterTests(TestCase):
for scope in new + old:
self.assertIn(scope, message)
self.assertEqual(old, ['aaa'])
- self.assertEqual(set(new), set(['abc', 'def']))
+ self.assertEqual(set(new), {'abc', 'def'})
finally:
signals.scope_changed.disconnect(record_scope_change)
del os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE']
@@ -278,7 +276,7 @@ class ParameterTests(TestCase):
for scope in new + old:
self.assertIn(scope, message)
self.assertEqual(old, ['aaa'])
- self.assertEqual(set(new), set(['abc', 'def']))
+ self.assertEqual(set(new), {'abc', 'def'})
finally:
signals.scope_changed.disconnect(record_scope_change)
del os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE']
diff --git a/tests/oauth2/rfc6749/test_request_validator.py b/tests/oauth2/rfc6749/test_request_validator.py
index 9dde814..257280c 100644
--- a/tests/oauth2/rfc6749/test_request_validator.py
+++ b/tests/oauth2/rfc6749/test_request_validator.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.oauth2 import RequestValidator
from ...unittest import TestCase
diff --git a/tests/oauth2/rfc6749/test_server.py b/tests/oauth2/rfc6749/test_server.py
index 2c6ecff..9288e49 100644
--- a/tests/oauth2/rfc6749/test_server.py
+++ b/tests/oauth2/rfc6749/test_server.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
@@ -73,7 +71,7 @@ class AuthorizationEndpointTest(TestCase):
uri, scopes=['all', 'of', 'them'])
self.assertIn('Location', headers)
self.assertURLEqual(headers['Location'], 'http://back.to/me?state=xyz', parse_fragment=True)
- self.assertEqual(body, None)
+ self.assertIsNone(body)
self.assertEqual(status_code, 302)
# and without the state parameter
@@ -83,7 +81,7 @@ class AuthorizationEndpointTest(TestCase):
uri, scopes=['all', 'of', 'them'])
self.assertIn('Location', headers)
self.assertURLEqual(headers['Location'], 'http://back.to/me', parse_fragment=True)
- self.assertEqual(body, None)
+ self.assertIsNone(body)
self.assertEqual(status_code, 302)
def test_missing_type(self):
diff --git a/tests/oauth2/rfc6749/test_tokens.py b/tests/oauth2/rfc6749/test_tokens.py
index e6f49b1..61a23cb 100644
--- a/tests/oauth2/rfc6749/test_tokens.py
+++ b/tests/oauth2/rfc6749/test_tokens.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.common import Request
diff --git a/tests/oauth2/rfc6749/test_utils.py b/tests/oauth2/rfc6749/test_utils.py
index 609162c..cfc6c2c 100644
--- a/tests/oauth2/rfc6749/test_utils.py
+++ b/tests/oauth2/rfc6749/test_utils.py
@@ -1,9 +1,6 @@
-from __future__ import absolute_import, unicode_literals
-
import datetime
import os
-from oauthlib.common import PY3
from oauthlib.oauth2.rfc6749.utils import (escape, generate_age, host_from_uri,
is_secure_transport, list_to_scope,
params_from_uri, scope_to_list)
@@ -19,12 +16,8 @@ class ScopeObject:
def __init__(self, scope):
self.scope = scope
- if PY3:
- def __str__(self):
- return self.scope
- else:
- def __unicode__(self):
- return self.scope
+ def __str__(self):
+ return self.scope
class UtilsTests(TestCase):
diff --git a/tests/openid/connect/core/endpoints/test_claims_handling.py b/tests/openid/connect/core/endpoints/test_claims_handling.py
index 5f39d96..943210c 100644
--- a/tests/openid/connect/core/endpoints/test_claims_handling.py
+++ b/tests/openid/connect/core/endpoints/test_claims_handling.py
@@ -6,8 +6,6 @@ The claims parameter is an optional query param for the Authorization Request en
request the claims should be transferred (via the oauthlib request) to be persisted
with the Access Token when it is created.
"""
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.openid import RequestValidator
diff --git a/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py b/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py
index 517239a..26ff46b 100644
--- a/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py
+++ b/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.oauth2 import InvalidRequestError
@@ -7,14 +5,10 @@ from oauthlib.oauth2.rfc6749.endpoints.authorization import \
AuthorizationEndpoint
from oauthlib.oauth2.rfc6749.tokens import BearerToken
from oauthlib.openid.connect.core.grant_types import AuthorizationCodeGrant
+from urllib.parse import urlencode
from tests.unittest import TestCase
-try:
- from urllib.parse import urlencode
-except ImportError:
- from urllib import urlencode
-
class OpenIDConnectEndpointTest(TestCase):
@@ -53,7 +47,7 @@ class OpenIDConnectEndpointTest(TestCase):
credentials=creds)
expected = 'https://a.b/cb?state=abc&code=MOCK_CODE'
self.assertURLEqual(h['Location'], expected)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
def test_prompt_none_exclusiveness(self):
diff --git a/tests/openid/connect/core/endpoints/test_userinfo_endpoint.py b/tests/openid/connect/core/endpoints/test_userinfo_endpoint.py
index 4593d79..9edc970 100644
--- a/tests/openid/connect/core/endpoints/test_userinfo_endpoint.py
+++ b/tests/openid/connect/core/endpoints/test_userinfo_endpoint.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import mock
import json
diff --git a/tests/openid/connect/core/grant_types/test_authorization_code.py b/tests/openid/connect/core/grant_types/test_authorization_code.py
index b721a19..b6bb99c 100644
--- a/tests/openid/connect/core/grant_types/test_authorization_code.py
+++ b/tests/openid/connect/core/grant_types/test_authorization_code.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
@@ -24,7 +22,7 @@ class OpenIDAuthCodeInterferenceTest(AuthorizationCodeGrantTest):
"""Test that OpenID don't interfere with normal OAuth 2 flows."""
def setUp(self):
- super(OpenIDAuthCodeInterferenceTest, self).setUp()
+ super().setUp()
self.auth = AuthorizationCodeGrant(request_validator=self.mock_validator)
@@ -66,13 +64,13 @@ class OpenIDAuthCodeTest(TestCase):
self.request.response_mode = 'query'
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_query)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
self.request.response_mode = 'fragment'
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_fragment, parse_fragment=True)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
@mock.patch('oauthlib.common.generate_token')
@@ -90,7 +88,7 @@ class OpenIDAuthCodeTest(TestCase):
self.request.id_token_hint = 'me@email.com'
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_query)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
# Test alernative response modes
@@ -159,5 +157,5 @@ class OpenIDAuthCodeTest(TestCase):
self.request.response_mode = 'query'
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_query)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
diff --git a/tests/openid/connect/core/grant_types/test_dispatchers.py b/tests/openid/connect/core/grant_types/test_dispatchers.py
index 9e45d65..2fc4ae6 100644
--- a/tests/openid/connect/core/grant_types/test_dispatchers.py
+++ b/tests/openid/connect/core/grant_types/test_dispatchers.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
import mock
from oauthlib.common import Request
@@ -72,7 +71,7 @@ class DispatcherTest(TestCase):
class AuthTokenGrantDispatcherOpenIdTest(DispatcherTest):
def setUp(self):
- super(AuthTokenGrantDispatcherOpenIdTest, self).setUp()
+ super().setUp()
self.request_validator.get_authorization_code_scopes.return_value = ('hello', 'openid')
self.dispatcher = AuthorizationTokenGrantDispatcher(
self.request_validator,
@@ -89,7 +88,7 @@ class AuthTokenGrantDispatcherOpenIdTest(DispatcherTest):
class AuthTokenGrantDispatcherOpenIdWithoutCodeTest(DispatcherTest):
def setUp(self):
- super(AuthTokenGrantDispatcherOpenIdWithoutCodeTest, self).setUp()
+ super().setUp()
self.request.decoded_body = (
("client_id", "me"),
("code", ""),
@@ -111,7 +110,7 @@ class AuthTokenGrantDispatcherOpenIdWithoutCodeTest(DispatcherTest):
class AuthTokenGrantDispatcherOAuthTest(DispatcherTest):
def setUp(self):
- super(AuthTokenGrantDispatcherOAuthTest, self).setUp()
+ super().setUp()
self.request_validator.get_authorization_code_scopes.return_value = ('hello', 'world')
self.dispatcher = AuthorizationTokenGrantDispatcher(
self.request_validator,
diff --git a/tests/openid/connect/core/grant_types/test_hybrid.py b/tests/openid/connect/core/grant_types/test_hybrid.py
index 0aa0add..3347031 100644
--- a/tests/openid/connect/core/grant_types/test_hybrid.py
+++ b/tests/openid/connect/core/grant_types/test_hybrid.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.oauth2.rfc6749 import errors
@@ -15,14 +13,14 @@ class OpenIDHybridInterferenceTest(AuthorizationCodeGrantTest):
"""Test that OpenID don't interfere with normal OAuth 2 flows."""
def setUp(self):
- super(OpenIDHybridInterferenceTest, self).setUp()
+ super().setUp()
self.auth = HybridGrant(request_validator=self.mock_validator)
class OpenIDHybridCodeTokenTest(OpenIDAuthCodeTest):
def setUp(self):
- super(OpenIDHybridCodeTokenTest, self).setUp()
+ super().setUp()
self.request.response_type = 'code token'
self.request.nonce = None
self.auth = HybridGrant(request_validator=self.mock_validator)
@@ -38,14 +36,14 @@ class OpenIDHybridCodeTokenTest(OpenIDAuthCodeTest):
bearer = BearerToken(self.mock_validator)
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_fragment, parse_fragment=True)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
class OpenIDHybridCodeIdTokenTest(OpenIDAuthCodeTest):
def setUp(self):
- super(OpenIDHybridCodeIdTokenTest, self).setUp()
+ super().setUp()
self.mock_validator.get_code_challenge.return_value = None
self.request.response_type = 'code id_token'
self.request.nonce = 'zxc'
@@ -63,14 +61,14 @@ class OpenIDHybridCodeIdTokenTest(OpenIDAuthCodeTest):
bearer = BearerToken(self.mock_validator)
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertIn('error=invalid_request', h['Location'])
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
class OpenIDHybridCodeIdTokenTokenTest(OpenIDAuthCodeTest):
def setUp(self):
- super(OpenIDHybridCodeIdTokenTokenTest, self).setUp()
+ super().setUp()
self.mock_validator.get_code_challenge.return_value = None
self.request.response_type = 'code id_token token'
self.request.nonce = 'xyz'
@@ -88,5 +86,5 @@ class OpenIDHybridCodeIdTokenTokenTest(OpenIDAuthCodeTest):
bearer = BearerToken(self.mock_validator)
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertIn('error=invalid_request', h['Location'])
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
diff --git a/tests/openid/connect/core/grant_types/test_implicit.py b/tests/openid/connect/core/grant_types/test_implicit.py
index 1ee805c..c8fefd4 100644
--- a/tests/openid/connect/core/grant_types/test_implicit.py
+++ b/tests/openid/connect/core/grant_types/test_implicit.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.common import Request
@@ -17,7 +15,7 @@ class OpenIDImplicitInterferenceTest(ImplicitGrantTest):
"""Test that OpenID don't interfere with normal OAuth 2 flows."""
def setUp(self):
- super(OpenIDImplicitInterferenceTest, self).setUp()
+ super().setUp()
self.auth = ImplicitGrant(request_validator=self.mock_validator)
@@ -50,7 +48,7 @@ class OpenIDImplicitTest(TestCase):
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_fragment, parse_fragment=True)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
self.request.response_type = 'id_token'
@@ -58,7 +56,7 @@ class OpenIDImplicitTest(TestCase):
url = 'https://a.b/cb#state=abc&id_token=%s' % token
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], url, parse_fragment=True)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
@mock.patch('oauthlib.common.generate_token')
@@ -74,7 +72,7 @@ class OpenIDImplicitTest(TestCase):
self.request.id_token_hint = 'me@email.com'
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertURLEqual(h['Location'], self.url_fragment, parse_fragment=True)
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
# Test alernative response modes
@@ -108,13 +106,13 @@ class OpenIDImplicitTest(TestCase):
bearer = BearerToken(self.mock_validator)
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertIn('error=invalid_request', h['Location'])
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
class OpenIDImplicitNoAccessTokenTest(OpenIDImplicitTest):
def setUp(self):
- super(OpenIDImplicitNoAccessTokenTest, self).setUp()
+ super().setUp()
self.request.response_type = 'id_token'
token = 'MOCKED_TOKEN'
self.url_query = 'https://a.b/cb?state=abc&id_token=%s' % token
@@ -129,5 +127,5 @@ class OpenIDImplicitNoAccessTokenTest(OpenIDImplicitTest):
bearer = BearerToken(self.mock_validator)
h, b, s = self.auth.create_authorization_response(self.request, bearer)
self.assertIn('error=invalid_request', h['Location'])
- self.assertEqual(b, None)
+ self.assertIsNone(b)
self.assertEqual(s, 302)
diff --git a/tests/openid/connect/core/test_request_validator.py b/tests/openid/connect/core/test_request_validator.py
index ebe0aeb..6a800d4 100644
--- a/tests/openid/connect/core/test_request_validator.py
+++ b/tests/openid/connect/core/test_request_validator.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
from oauthlib.openid import RequestValidator
from tests.unittest import TestCase
diff --git a/tests/openid/connect/core/test_server.py b/tests/openid/connect/core/test_server.py
index 756c9d0..681748f 100644
--- a/tests/openid/connect/core/test_server.py
+++ b/tests/openid/connect/core/test_server.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import json
import mock
@@ -78,7 +76,7 @@ class AuthorizationEndpointTest(TestCase):
uri, scopes=['all', 'of', 'them'])
self.assertIn('Location', headers)
self.assertURLEqual(headers['Location'], 'http://back.to/me?state=xyz', parse_fragment=True)
- self.assertEqual(body, None)
+ self.assertIsNone(body)
self.assertEqual(status_code, 302)
# and without the state parameter
@@ -88,7 +86,7 @@ class AuthorizationEndpointTest(TestCase):
uri, scopes=['all', 'of', 'them'])
self.assertIn('Location', headers)
self.assertURLEqual(headers['Location'], 'http://back.to/me', parse_fragment=True)
- self.assertEqual(body, None)
+ self.assertIsNone(body)
self.assertEqual(status_code, 302)
def test_missing_type(self):
diff --git a/tests/openid/connect/core/test_tokens.py b/tests/openid/connect/core/test_tokens.py
index fde89d6..f1a6688 100644
--- a/tests/openid/connect/core/test_tokens.py
+++ b/tests/openid/connect/core/test_tokens.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import, unicode_literals
-
import mock
from oauthlib.openid.connect.core.tokens import JWTToken
diff --git a/tests/test_common.py b/tests/test_common.py
index ae2531b..b0fb4b0 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
-
import os
import sys
@@ -8,7 +6,7 @@ import oauthlib
from oauthlib.common import (CaseInsensitiveDict, Request, add_params_to_uri,
extract_params, generate_client_id,
generate_nonce, generate_timestamp,
- generate_token, unicode_type, urldecode)
+ generate_token, urldecode)
from .unittest import TestCase
@@ -21,23 +19,23 @@ URI = 'http://www.someuri.com'
class EncodingTest(TestCase):
def test_urldecode(self):
- self.assertItemsEqual(urldecode(''), [])
- self.assertItemsEqual(urldecode('='), [('', '')])
- self.assertItemsEqual(urldecode('%20'), [(' ', '')])
- self.assertItemsEqual(urldecode('+'), [(' ', '')])
- self.assertItemsEqual(urldecode('c2'), [('c2', '')])
- self.assertItemsEqual(urldecode('c2='), [('c2', '')])
- self.assertItemsEqual(urldecode('foo=bar'), [('foo', 'bar')])
- self.assertItemsEqual(urldecode('foo_%20~=.bar-'),
+ self.assertCountEqual(urldecode(''), [])
+ self.assertCountEqual(urldecode('='), [('', '')])
+ self.assertCountEqual(urldecode('%20'), [(' ', '')])
+ self.assertCountEqual(urldecode('+'), [(' ', '')])
+ self.assertCountEqual(urldecode('c2'), [('c2', '')])
+ self.assertCountEqual(urldecode('c2='), [('c2', '')])
+ self.assertCountEqual(urldecode('foo=bar'), [('foo', 'bar')])
+ self.assertCountEqual(urldecode('foo_%20~=.bar-'),
[('foo_ ~', '.bar-')])
- self.assertItemsEqual(urldecode('foo=1,2,3'), [('foo', '1,2,3')])
- self.assertItemsEqual(urldecode('foo=(1,2,3)'), [('foo', '(1,2,3)')])
- self.assertItemsEqual(urldecode('foo=bar.*'), [('foo', 'bar.*')])
- self.assertItemsEqual(urldecode('foo=bar@spam'), [('foo', 'bar@spam')])
- self.assertItemsEqual(urldecode('foo=bar/baz'), [('foo', 'bar/baz')])
- self.assertItemsEqual(urldecode('foo=bar?baz'), [('foo', 'bar?baz')])
- self.assertItemsEqual(urldecode('foo=bar\'s'), [('foo', 'bar\'s')])
- self.assertItemsEqual(urldecode('foo=$'), [('foo', '$')])
+ self.assertCountEqual(urldecode('foo=1,2,3'), [('foo', '1,2,3')])
+ self.assertCountEqual(urldecode('foo=(1,2,3)'), [('foo', '(1,2,3)')])
+ self.assertCountEqual(urldecode('foo=bar.*'), [('foo', 'bar.*')])
+ self.assertCountEqual(urldecode('foo=bar@spam'), [('foo', 'bar@spam')])
+ self.assertCountEqual(urldecode('foo=bar/baz'), [('foo', 'bar/baz')])
+ self.assertCountEqual(urldecode('foo=bar?baz'), [('foo', 'bar?baz')])
+ self.assertCountEqual(urldecode('foo=bar\'s'), [('foo', 'bar\'s')])
+ self.assertCountEqual(urldecode('foo=$'), [('foo', '$')])
self.assertRaises(ValueError, urldecode, 'foo bar')
self.assertRaises(ValueError, urldecode, '%R')
self.assertRaises(ValueError, urldecode, '%RA')
@@ -48,30 +46,30 @@ class EncodingTest(TestCase):
class ParameterTest(TestCase):
def test_extract_params_dict(self):
- self.assertItemsEqual(extract_params(PARAMS_DICT), PARAMS_TWOTUPLE)
+ self.assertCountEqual(extract_params(PARAMS_DICT), PARAMS_TWOTUPLE)
def test_extract_params_twotuple(self):
- self.assertItemsEqual(extract_params(PARAMS_TWOTUPLE), PARAMS_TWOTUPLE)
+ self.assertCountEqual(extract_params(PARAMS_TWOTUPLE), PARAMS_TWOTUPLE)
def test_extract_params_formencoded(self):
- self.assertItemsEqual(extract_params(PARAMS_FORMENCODED),
+ self.assertCountEqual(extract_params(PARAMS_FORMENCODED),
PARAMS_TWOTUPLE)
def test_extract_params_blank_string(self):
- self.assertItemsEqual(extract_params(''), [])
+ self.assertCountEqual(extract_params(''), [])
def test_extract_params_empty_list(self):
- self.assertItemsEqual(extract_params([]), [])
+ self.assertCountEqual(extract_params([]), [])
def test_extract_non_formencoded_string(self):
- self.assertEqual(extract_params('not a formencoded string'), None)
+ self.assertIsNone(extract_params('not a formencoded string'))
def test_extract_invalid(self):
- self.assertEqual(extract_params(object()), None)
- self.assertEqual(extract_params([('')]), None)
+ self.assertIsNone(extract_params(object()))
+ self.assertIsNone(extract_params([('')]))
def test_add_params_to_uri(self):
- correct = '%s?%s' % (URI, PARAMS_FORMENCODED)
+ correct = '{}?{}'.format(URI, PARAMS_FORMENCODED)
self.assertURLEqual(add_params_to_uri(URI, PARAMS_DICT), correct)
self.assertURLEqual(add_params_to_uri(URI, PARAMS_TWOTUPLE), correct)
@@ -80,7 +78,7 @@ class GeneratorTest(TestCase):
def test_generate_timestamp(self):
timestamp = generate_timestamp()
- self.assertIsInstance(timestamp, unicode_type)
+ self.assertIsInstance(timestamp, str)
self.assertTrue(int(timestamp))
self.assertGreater(int(timestamp), 1331672335)
@@ -134,7 +132,7 @@ class RequestTest(TestCase):
def test_none_body(self):
r = Request(URI)
- self.assertEqual(r.decoded_body, None)
+ self.assertIsNone(r.decoded_body)
def test_empty_list_body(self):
r = Request(URI, body=[])
@@ -151,20 +149,20 @@ class RequestTest(TestCase):
def test_non_formencoded_string_body(self):
body = 'foo bar'
r = Request(URI, body=body)
- self.assertEqual(r.decoded_body, None)
+ self.assertIsNone(r.decoded_body)
def test_param_free_sequence_body(self):
body = [1, 1, 2, 3, 5, 8, 13]
r = Request(URI, body=body)
- self.assertEqual(r.decoded_body, None)
+ self.assertIsNone(r.decoded_body)
def test_list_body(self):
r = Request(URI, body=PARAMS_TWOTUPLE)
- self.assertItemsEqual(r.decoded_body, PARAMS_TWOTUPLE)
+ self.assertCountEqual(r.decoded_body, PARAMS_TWOTUPLE)
def test_dict_body(self):
r = Request(URI, body=PARAMS_DICT)
- self.assertItemsEqual(r.decoded_body, PARAMS_TWOTUPLE)
+ self.assertCountEqual(r.decoded_body, PARAMS_TWOTUPLE)
def test_getattr_existing_attribute(self):
r = Request(URI, body='foo bar')
diff --git a/tests/unittest/__init__.py b/tests/unittest/__init__.py
index 6cb79a6..13ad92f 100644
--- a/tests/unittest/__init__.py
+++ b/tests/unittest/__init__.py
@@ -1,18 +1,8 @@
-import collections
-import sys
from unittest import TestCase
-try:
- import urlparse
-except ImportError:
- import urllib.parse as urlparse
+import urllib.parse as urlparse
-# Somewhat consistent itemsequal between all python versions
-if sys.version_info[0] == 3:
- TestCase.assertItemsEqual = TestCase.assertCountEqual
-
-
-# URL comparison where query param order is insignifcant
+# URL comparison where query param order is insignificant
def url_equals(self, a, b, parse_fragment=False):
parsed_a = urlparse.urlparse(a, allow_fragments=parse_fragment)
parsed_b = urlparse.urlparse(b, allow_fragments=parse_fragment)
@@ -21,7 +11,7 @@ def url_equals(self, a, b, parse_fragment=False):
if parse_fragment:
fragment_a = urlparse.parse_qsl(parsed_a.fragment)
fragment_b = urlparse.parse_qsl(parsed_b.fragment)
- self.assertItemsEqual(fragment_a, fragment_b)
+ self.assertCountEqual(fragment_a, fragment_b)
else:
self.assertEqual(parsed_a.fragment, parsed_b.fragment)
self.assertEqual(parsed_a.scheme, parsed_b.scheme)
@@ -32,10 +22,11 @@ def url_equals(self, a, b, parse_fragment=False):
self.assertEqual(parsed_a.password, parsed_b.password)
self.assertEqual(parsed_a.hostname, parsed_b.hostname)
self.assertEqual(parsed_a.port, parsed_b.port)
- self.assertItemsEqual(query_a, query_b)
+ self.assertCountEqual(query_a, query_b)
+
TestCase.assertURLEqual = url_equals
# Form body comparison where order is insignificant
-TestCase.assertFormBodyEqual = lambda self, a, b: self.assertItemsEqual(
+TestCase.assertFormBodyEqual = lambda self, a, b: self.assertCountEqual(
urlparse.parse_qsl(a), urlparse.parse_qsl(b))
diff --git a/tox.ini b/tox.ini
index 1b03598..22f6f33 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,11 +1,11 @@
[tox]
-envlist = py27,py35,py36,py37,pypy,pypy3,docs,readme,bandit
+envlist = py35,py36,py37,pypy,pypy3,docs,readme,bandit
[testenv]
deps=
-rrequirements-test.txt
commands=
- py.test --cov=oauthlib tests/
+ pytest --cov=oauthlib tests/
# tox -e docs to mimick readthedocs build.
@@ -29,7 +29,7 @@ commands=
twine check dist/*
[testenv:bandit]
-basepython=python2.7
+basepython=python3.7
skipsdist=True
deps=bandit
commands=bandit -b bandit.json -r oauthlib/