summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo <hugovk@users.noreply.github.com>2019-08-14 23:44:51 +0300
committerHugo <hugovk@users.noreply.github.com>2019-08-15 12:24:33 +0300
commit2cec2adf8f54c9eda2a2674f565584aea709ef8a (patch)
tree5d965388d9b02f6b82cba84a53dd55ff979e45e2
parent3718a0e048e64994c2ee3819c5e5ed218a05f115 (diff)
downloadoauthlib-2cec2adf8f54c9eda2a2674f565584aea709ef8a.tar.gz
Upgrade Python syntax with pyupgrade
-rw-r--r--docs/conf.py16
-rw-r--r--oauthlib/common.py16
-rw-r--r--oauthlib/oauth1/rfc5849/__init__.py20
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/base.py4
-rw-r--r--oauthlib/oauth1/rfc5849/endpoints/request_token.py2
-rw-r--r--oauthlib/oauth1/rfc5849/errors.py4
-rw-r--r--oauthlib/oauth1/rfc5849/parameters.py2
-rw-r--r--oauthlib/oauth1/rfc5849/request_validator.py4
-rw-r--r--oauthlib/oauth1/rfc5849/signature.py4
-rw-r--r--oauthlib/oauth1/rfc5849/utils.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/base.py6
-rw-r--r--oauthlib/oauth2/rfc6749/clients/legacy_application.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/service_application.py2
-rw-r--r--oauthlib/oauth2/rfc6749/clients/web_application.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/base.py2
-rw-r--r--oauthlib/oauth2/rfc6749/endpoints/revocation.py2
-rw-r--r--oauthlib/oauth2/rfc6749/errors.py6
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/base.py4
-rw-r--r--oauthlib/oauth2/rfc6749/grant_types/refresh_token.py4
-rw-r--r--oauthlib/oauth2/rfc6749/parameters.py4
-rw-r--r--oauthlib/oauth2/rfc6749/request_validator.py2
-rw-r--r--oauthlib/oauth2/rfc6749/tokens.py6
-rw-r--r--oauthlib/openid/connect/core/grant_types/authorization_code.py2
-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.py2
-rw-r--r--oauthlib/openid/connect/core/grant_types/implicit.py4
-rw-r--r--oauthlib/signals.py4
-rw-r--r--tests/oauth2/rfc6749/clients/test_base.py4
-rw-r--r--tests/oauth2/rfc6749/clients/test_legacy_application.py6
-rw-r--r--tests/oauth2/rfc6749/clients/test_web_application.py2
-rw-r--r--tests/oauth2/rfc6749/test_parameters.py10
-rw-r--r--tests/openid/connect/core/grant_types/test_authorization_code.py2
-rw-r--r--tests/openid/connect/core/grant_types/test_dispatchers.py6
-rw-r--r--tests/openid/connect/core/grant_types/test_hybrid.py8
-rw-r--r--tests/openid/connect/core/grant_types/test_implicit.py4
-rw-r--r--tests/test_common.py2
38 files changed, 90 insertions, 90 deletions
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/oauthlib/common.py b/oauthlib/common.py
index 1462e75..52a3567 100644
--- a/oauthlib/common.py
+++ b/oauthlib/common.py
@@ -300,7 +300,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
@@ -312,7 +312,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]
@@ -321,27 +321,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.
@@ -421,7 +421,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/rfc5849/__init__.py b/oauthlib/oauth1/rfc5849/__init__.py
index 4f462bb..cdc96e8 100644
--- a/oauthlib/oauth1/rfc5849/__init__.py
+++ b/oauthlib/oauth1/rfc5849/__init__.py
@@ -36,7 +36,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 +106,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 +130,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 +278,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/base.py b/oauthlib/oauth1/rfc5849/endpoints/base.py
index f005256..c6428ea 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/base.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/base.py
@@ -17,7 +17,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 +131,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/request_token.py b/oauthlib/oauth1/rfc5849/endpoints/request_token.py
index e9ca331..6749755 100644
--- a/oauthlib/oauth1/rfc5849/endpoints/request_token.py
+++ b/oauthlib/oauth1/rfc5849/endpoints/request_token.py
@@ -129,7 +129,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/errors.py b/oauthlib/oauth1/rfc5849/errors.py
index a5c59bd..f8c2281 100644
--- a/oauthlib/oauth1/rfc5849/errors.py
+++ b/oauthlib/oauth1/rfc5849/errors.py
@@ -37,10 +37,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..569a136 100644
--- a/oauthlib/oauth1/rfc5849/parameters.py
+++ b/oauthlib/oauth1/rfc5849/parameters.py
@@ -61,7 +61,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..db5f1dd 100644
--- a/oauthlib/oauth1/rfc5849/request_validator.py
+++ b/oauthlib/oauth1/rfc5849/request_validator.py
@@ -13,7 +13,7 @@ import sys
from . import SIGNATURE_METHODS, utils
-class RequestValidator(object):
+class RequestValidator:
"""A validator/datastore interaction base class for OAuth 1 providers.
@@ -197,7 +197,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 5b080aa..78de755 100644
--- a/oauthlib/oauth1/rfc5849/signature.py
+++ b/oauthlib/oauth1/rfc5849/signature.py
@@ -300,7 +300,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(
@@ -429,7 +429,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
diff --git a/oauthlib/oauth1/rfc5849/utils.py b/oauthlib/oauth1/rfc5849/utils.py
index a010aea..83df65c 100644
--- a/oauthlib/oauth1/rfc5849/utils.py
+++ b/oauthlib/oauth1/rfc5849/utils.py
@@ -54,7 +54,7 @@ def escape(u):
"""
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'~')
diff --git a/oauthlib/oauth2/rfc6749/clients/base.py b/oauthlib/oauth2/rfc6749/clients/base.py
index 9b05ad5..c028552 100644
--- a/oauthlib/oauth2/rfc6749/clients/base.py
+++ b/oauthlib/oauth2/rfc6749/clients/base.py
@@ -29,7 +29,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 +186,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..c224c33 100644
--- a/oauthlib/oauth2/rfc6749/clients/legacy_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/legacy_application.py
@@ -38,7 +38,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/service_application.py b/oauthlib/oauth2/rfc6749/clients/service_application.py
index ea946ce..00ea018 100644
--- a/oauthlib/oauth2/rfc6749/clients/service_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/service_application.py
@@ -57,7 +57,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..fe64ef0 100644
--- a/oauthlib/oauth2/rfc6749/clients/web_application.py
+++ b/oauthlib/oauth2/rfc6749/clients/web_application.py
@@ -38,7 +38,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/base.py b/oauthlib/oauth2/rfc6749/endpoints/base.py
index e39232f..e69ccf0 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/base.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/base.py
@@ -20,7 +20,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/revocation.py b/oauthlib/oauth2/rfc6749/endpoints/revocation.py
index 1fabd03..cda6375 100644
--- a/oauthlib/oauth2/rfc6749/endpoints/revocation.py
+++ b/oauthlib/oauth2/rfc6749/endpoints/revocation.py
@@ -73,7 +73,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/errors.py b/oauthlib/oauth2/rfc6749/errors.py
index d2a1402..8f88bb4 100644
--- a/oauthlib/oauth2/rfc6749/errors.py
+++ b/oauthlib/oauth2/rfc6749/errors.py
@@ -45,10 +45,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 +389,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/base.py b/oauthlib/oauth2/rfc6749/grant_types/base.py
index f0772e2..b4c3665 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/base.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/base.py
@@ -17,7 +17,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 +74,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/refresh_token.py b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
index fc61d65..5f0db28 100644
--- a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
+++ b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
@@ -25,7 +25,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 +126,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/parameters.py b/oauthlib/oauth2/rfc6749/parameters.py
index b6249d8..a3f9dd0 100644
--- a/oauthlib/oauth2/rfc6749/parameters.py
+++ b/oauthlib/oauth2/rfc6749/parameters.py
@@ -146,13 +146,13 @@ 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((str('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((str('client_secret'), client_secret))
+ params.append(('client_secret', client_secret))
# this handles: `code`, `redirect_uri`, and other undocumented params
for k in kwargs:
diff --git a/oauthlib/oauth2/rfc6749/request_validator.py b/oauthlib/oauth2/rfc6749/request_validator.py
index 86509b6..eeef50e 100644
--- a/oauthlib/oauth2/rfc6749/request_validator.py
+++ b/oauthlib/oauth2/rfc6749/request_validator.py
@@ -10,7 +10,7 @@ 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 5b99f0c..8873ed5 100644
--- a/oauthlib/oauth2/rfc6749/tokens.py
+++ b/oauthlib/oauth2/rfc6749/tokens.py
@@ -28,7 +28,7 @@ except ImportError:
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 +121,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()
@@ -262,7 +262,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/openid/connect/core/grant_types/authorization_code.py b/oauthlib/openid/connect/core/grant_types/authorization_code.py
index becfcfa..7047e1e 100644
--- a/oauthlib/openid/connect/core/grant_types/authorization_code.py
+++ b/oauthlib/openid/connect/core/grant_types/authorization_code.py
@@ -41,4 +41,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..af86d10 100644
--- a/oauthlib/openid/connect/core/grant_types/hybrid.py
+++ b/oauthlib/openid/connect/core/grant_types/hybrid.py
@@ -39,7 +39,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..aefec57 100644
--- a/oauthlib/openid/connect/core/grant_types/implicit.py
+++ b/oauthlib/openid/connect/core/grant_types/implicit.py
@@ -29,12 +29,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/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/tests/oauth2/rfc6749/clients/test_base.py b/tests/oauth2/rfc6749/clients/test_base.py
index d48a944..4fbada9 100644
--- a/tests/oauth2/rfc6749/clients/test_base.py
+++ b/tests/oauth2/rfc6749/clients/test_base.py
@@ -295,11 +295,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..01e46e4 100644
--- a/tests/oauth2/rfc6749/clients/test_legacy_application.py
+++ b/tests/oauth2/rfc6749/clients/test_legacy_application.py
@@ -32,7 +32,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 +105,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_web_application.py b/tests/oauth2/rfc6749/clients/test_web_application.py
index 092f93e..f7fbb02 100644
--- a/tests/oauth2/rfc6749/clients/test_web_application.py
+++ b/tests/oauth2/rfc6749/clients/test_web_application.py
@@ -46,7 +46,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/test_parameters.py b/tests/oauth2/rfc6749/test_parameters.py
index 48b7eac..5e449f4 100644
--- a/tests/oauth2/rfc6749/test_parameters.py
+++ b/tests/oauth2/rfc6749/test_parameters.py
@@ -77,9 +77,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 +244,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 +278,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/openid/connect/core/grant_types/test_authorization_code.py b/tests/openid/connect/core/grant_types/test_authorization_code.py
index b721a19..76a4e97 100644
--- a/tests/openid/connect/core/grant_types/test_authorization_code.py
+++ b/tests/openid/connect/core/grant_types/test_authorization_code.py
@@ -24,7 +24,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)
diff --git a/tests/openid/connect/core/grant_types/test_dispatchers.py b/tests/openid/connect/core/grant_types/test_dispatchers.py
index 9e45d65..53625b2 100644
--- a/tests/openid/connect/core/grant_types/test_dispatchers.py
+++ b/tests/openid/connect/core/grant_types/test_dispatchers.py
@@ -72,7 +72,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 +89,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 +111,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..08dcc13 100644
--- a/tests/openid/connect/core/grant_types/test_hybrid.py
+++ b/tests/openid/connect/core/grant_types/test_hybrid.py
@@ -15,14 +15,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)
@@ -45,7 +45,7 @@ class OpenIDHybridCodeTokenTest(OpenIDAuthCodeTest):
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'
@@ -70,7 +70,7 @@ class OpenIDHybridCodeIdTokenTest(OpenIDAuthCodeTest):
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'
diff --git a/tests/openid/connect/core/grant_types/test_implicit.py b/tests/openid/connect/core/grant_types/test_implicit.py
index 1ee805c..e94ad30 100644
--- a/tests/openid/connect/core/grant_types/test_implicit.py
+++ b/tests/openid/connect/core/grant_types/test_implicit.py
@@ -17,7 +17,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)
@@ -114,7 +114,7 @@ class OpenIDImplicitTest(TestCase):
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
diff --git a/tests/test_common.py b/tests/test_common.py
index c2c5e41..2a9a264 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -71,7 +71,7 @@ class ParameterTest(TestCase):
self.assertEqual(extract_params([('')]), None)
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)