Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

end support for python 3.7 #570

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
max-parallel: 3
matrix:
python:
- version: "3.7"
- version: "3.8"
- version: "3.9"
- version: "3.10"
Expand Down
9 changes: 4 additions & 5 deletions authlib/common/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#: coding: utf-8
from authlib.consts import default_json_headers


Expand All @@ -20,11 +19,11 @@ def __init__(self, error=None, description=None, uri=None):
if uri is not None:
self.uri = uri

message = '{}: {}'.format(self.error, self.description)
super(AuthlibBaseError, self).__init__(message)
message = f'{self.error}: {self.description}'
super().__init__(message)

def __repr__(self):
return '<{} "{}">'.format(self.__class__.__name__, self.error)
return f'<{self.__class__.__name__} "{self.error}">'


class AuthlibHTTPError(AuthlibBaseError):
Expand All @@ -33,7 +32,7 @@ class AuthlibHTTPError(AuthlibBaseError):

def __init__(self, error=None, description=None, uri=None,
status_code=None):
super(AuthlibHTTPError, self).__init__(error, description, uri)
super().__init__(error, description, uri)
if status_code is not None:
self.status_code = status_code

Expand Down
2 changes: 1 addition & 1 deletion authlib/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version = '1.2.1'
author = 'Hsiaoming Yang <[email protected]>'
homepage = 'https://authlib.org/'
default_user_agent = '{}/{} (+{})'.format(name, version, homepage)
default_user_agent = f'{name}/{version} (+{homepage})'

default_json_headers = [
('Content-Type', 'application/json'),
Expand Down
4 changes: 2 additions & 2 deletions authlib/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AuthlibDeprecationWarning(DeprecationWarning):

def deprecate(message, version=None, link_uid=None, link_file=None):
if version:
message += '\nIt will be compatible before version {}.'.format(version)
message += f'\nIt will be compatible before version {version}.'
if link_uid and link_file:
message += '\nRead more <https://git.io/{}#file-{}-md>'.format(link_uid, link_file)
message += f'\nRead more <https://git.io/{link_uid}#file-{link_file}-md>'
warnings.warn(AuthlibDeprecationWarning(message), stacklevel=2)
2 changes: 1 addition & 1 deletion authlib/integrations/base_client/async_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def create_authorization_url(self, redirect_uri=None, **kwargs):
if self.request_token_params:
params.update(self.request_token_params)
request_token = await client.fetch_request_token(self.request_token_url, **params)
log.debug('Fetch request token: {!r}'.format(request_token))
log.debug(f'Fetch request token: {request_token!r}')
url = client.create_authorization_url(self.authorize_url, **kwargs)
state = request_token['oauth_token']
return {'url': url, 'request_token': request_token, 'state': state}
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/base_client/async_openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__all__ = ['AsyncOpenIDMixin']


class AsyncOpenIDMixin(object):
class AsyncOpenIDMixin:
async def fetch_jwk_set(self, force=False):
metadata = await self.load_server_metadata()
jwk_set = metadata.get('jwks')
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/base_client/framework_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time


class FrameworkIntegration(object):
class FrameworkIntegration:
expires_in = 3600

def __init__(self, name, cache=None):
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/base_client/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)


class BaseOAuth(object):
class BaseOAuth:
"""Registry for oauth clients.

Create an instance for registry::
Expand Down
10 changes: 5 additions & 5 deletions authlib/integrations/base_client/sync_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
log = logging.getLogger(__name__)


class BaseApp(object):
class BaseApp:
client_cls = None
OAUTH_APP_CONFIG = None

Expand Down Expand Up @@ -89,7 +89,7 @@ def _send_token_request(self, session, method, url, token, kwargs):
return session.request(method, url, **kwargs)


class OAuth1Base(object):
class OAuth1Base:
client_cls = None

def __init__(
Expand Down Expand Up @@ -144,7 +144,7 @@ def create_authorization_url(self, redirect_uri=None, **kwargs):
client.redirect_uri = redirect_uri
params = self.request_token_params or {}
request_token = client.fetch_request_token(self.request_token_url, **params)
log.debug('Fetch request token: {!r}'.format(request_token))
log.debug(f'Fetch request token: {request_token!r}')
url = client.create_authorization_url(self.authorize_url, **kwargs)
state = request_token['oauth_token']
return {'url': url, 'request_token': request_token, 'state': state}
Expand All @@ -169,7 +169,7 @@ def fetch_access_token(self, request_token=None, **kwargs):
return token


class OAuth2Base(object):
class OAuth2Base:
client_cls = None

def __init__(
Expand Down Expand Up @@ -251,7 +251,7 @@ def _create_oauth2_authorization_url(client, authorization_endpoint, **kwargs):
code_verifier = generate_token(48)
kwargs['code_verifier'] = code_verifier
rv['code_verifier'] = code_verifier
log.debug('Using code_verifier: {!r}'.format(code_verifier))
log.debug(f'Using code_verifier: {code_verifier!r}')

scope = kwargs.get('scope', client.scope)
if scope and 'openid' in scope.split():
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/base_client/sync_openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from authlib.oidc.core import UserInfo, CodeIDToken, ImplicitIDToken


class OpenIDMixin(object):
class OpenIDMixin:
def fetch_jwk_set(self, force=False):
metadata = self.load_server_metadata()
jwk_set = metadata.get('jwks')
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/django_client/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)


class DjangoAppMixin(object):
class DjangoAppMixin:
def save_authorize_data(self, request, **kwargs):
state = kwargs.pop('state', None)
if state:
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/django_oauth1/authorization_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def handle_response(self, status_code, payload, headers):

class CacheAuthorizationServer(BaseServer):
def __init__(self, client_model, token_model, token_generator=None):
super(CacheAuthorizationServer, self).__init__(
super().__init__(
client_model, token_model, token_generator)
self._temporary_expires_in = self._config.get(
'temporary_credential_expires_in', 86400)
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/django_oauth1/nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def exists_nonce_in_cache(nonce, request, timeout):
timestamp = request.timestamp
client_id = request.client_id
token = request.token
key = '{}{}-{}-{}'.format(key_prefix, nonce, timestamp, client_id)
key = f'{key_prefix}{nonce}-{timestamp}-{client_id}'
if token:
key = '{}-{}'.format(key, token)
key = f'{key}-{token}'

rv = bool(cache.get(key))
cache.set(key, 1, timeout=timeout)
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/django_oauth2/authorization_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, client_model, token_model):
self.client_model = client_model
self.token_model = token_model
scopes_supported = self.config.get('scopes_supported')
super(AuthorizationServer, self).__init__(scopes_supported=scopes_supported)
super().__init__(scopes_supported=scopes_supported)
# add default token generator
self.register_token_generator('default', self.create_bearer_token_generator())

Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/django_oauth2/resource_protector.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def decorated(request, *args, **kwargs):
class BearerTokenValidator(_BearerTokenValidator):
def __init__(self, token_model, realm=None, **extra_attributes):
self.token_model = token_model
super(BearerTokenValidator, self).__init__(realm, **extra_attributes)
super().__init__(realm, **extra_attributes)

def authenticate_token(self, token_string):
try:
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/flask_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class OAuth(BaseOAuth):
framework_integration_cls = FlaskIntegration

def __init__(self, app=None, cache=None, fetch_token=None, update_token=None):
super(OAuth, self).__init__(
super().__init__(
cache=cache, fetch_token=fetch_token, update_token=update_token)
self.app = app
if app:
Expand All @@ -35,7 +35,7 @@ def init_app(self, app, cache=None, fetch_token=None, update_token=None):
def create_client(self, name):
if not self.app:
raise RuntimeError('OAuth is not init with Flask app.')
return super(OAuth, self).create_client(name)
return super().create_client(name)

def register(self, name, overwrite=False, **kwargs):
self._registry[name] = (overwrite, kwargs)
Expand Down
6 changes: 3 additions & 3 deletions authlib/integrations/flask_client/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
)


class FlaskAppMixin(object):
class FlaskAppMixin:
@property
def token(self):
attr = '_oauth_token_{}'.format(self.name)
attr = f'_oauth_token_{self.name}'
token = g.get(attr)
if token:
return token
Expand All @@ -20,7 +20,7 @@ def token(self):

@token.setter
def token(self, token):
attr = '_oauth_token_{}'.format(self.name)
attr = f'_oauth_token_{self.name}'
setattr(g, attr, token)

def _get_requested_token(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/flask_client/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def update_token(self, token, refresh_token=None, access_token=None):
def load_config(oauth, name, params):
rv = {}
for k in params:
conf_key = '{}_{}'.format(name, k).upper()
conf_key = f'{name}_{k}'.upper()
v = oauth.app.config.get(conf_key, None)
if v is not None:
rv[k] = v
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/flask_oauth1/authorization_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ def check_authorization_request(self):
return req

def create_authorization_response(self, request=None, grant_user=None):
return super(AuthorizationServer, self)\
return super()\
.create_authorization_response(request, grant_user)

def create_token_response(self, request=None):
return super(AuthorizationServer, self).create_token_response(request)
return super().create_token_response(request)

def create_oauth1_request(self, request):
if request is None:
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/flask_oauth1/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def create_exists_nonce_func(cache, key_prefix='nonce:', expires=86400):
:param expires: Expire time for nonce
"""
def exists_nonce(nonce, timestamp, client_id, oauth_token):
key = '{}{}-{}-{}'.format(key_prefix, nonce, timestamp, client_id)
key = f'{key_prefix}{nonce}-{timestamp}-{client_id}'
if oauth_token:
key = '{}-{}'.format(key, oauth_token)
key = f'{key}-{oauth_token}'
rv = cache.has(key)
cache.set(key, 1, timeout=expires)
return rv
Expand Down
2 changes: 1 addition & 1 deletion authlib/integrations/flask_oauth2/authorization_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_token(token, request):
"""

def __init__(self, app=None, query_client=None, save_token=None):
super(AuthorizationServer, self).__init__()
super().__init__()
self._query_client = query_client
self._save_token = save_token
self._error_uris = None
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/flask_oauth2/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if _version in ('0', '1'):
class _HTTPException(HTTPException):
def __init__(self, code, body, headers, response=None):
super(_HTTPException, self).__init__(None, response)
super().__init__(None, response)
self.code = code

self.body = body
Expand All @@ -20,7 +20,7 @@ def get_headers(self, environ=None):
else:
class _HTTPException(HTTPException):
def __init__(self, code, body, headers, response=None):
super(_HTTPException, self).__init__(None, response)
super().__init__(None, response)
self.code = code

self.body = body
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/httpx_client/assertion_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def request(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAU
await self.refresh_token()

auth = self.token_auth
return await super(AsyncAssertionClient, self).request(
return await super().request(
method, url, auth=auth, **kwargs)

async def _refresh_token(self, data):
Expand Down Expand Up @@ -77,5 +77,5 @@ def request(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **
self.refresh_token()

auth = self.token_auth
return super(AssertionClient, self).request(
return super().request(
method, url, auth=auth, **kwargs)
10 changes: 5 additions & 5 deletions authlib/integrations/httpx_client/oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def auth_flow(self, request: Request) -> typing.Generator[Request, Response, Non
headers['Content-Length'] = str(len(body))
yield build_request(url=url, headers=headers, body=body, initial_request=request)
except KeyError as error:
description = 'Unsupported token_type: {}'.format(str(error))
description = f'Unsupported token_type: {str(error)}'
raise UnsupportedTokenTypeError(description=description)


Expand Down Expand Up @@ -87,7 +87,7 @@ async def request(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAU

auth = self.token_auth

return await super(AsyncOAuth2Client, self).request(
return await super().request(
method, url, auth=auth, **kwargs)

@asynccontextmanager
Expand All @@ -100,7 +100,7 @@ async def stream(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAUL

auth = self.token_auth

async with super(AsyncOAuth2Client, self).stream(
async with super().stream(
method, url, auth=auth, **kwargs) as resp:
yield resp

Expand Down Expand Up @@ -203,7 +203,7 @@ def request(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **

auth = self.token_auth

return super(OAuth2Client, self).request(
return super().request(
method, url, auth=auth, **kwargs)

def stream(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **kwargs):
Expand All @@ -216,5 +216,5 @@ def stream(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **k

auth = self.token_auth

return super(OAuth2Client, self).stream(
return super().stream(
method, url, auth=auth, **kwargs)
2 changes: 1 addition & 1 deletion authlib/integrations/requests_client/assertion_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def request(self, method, url, withhold_token=False, auth=None, **kwargs):
kwargs.setdefault('timeout', self.default_timeout)
if not withhold_token and auth is None:
auth = self.token_auth
return super(AssertionSession, self).request(
return super().request(
method, url, auth=auth, **kwargs)
1 change: 0 additions & 1 deletion authlib/integrations/requests_client/oauth1_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from requests import Session
from requests.auth import AuthBase
from authlib.oauth1 import (
Expand Down
4 changes: 2 additions & 2 deletions authlib/integrations/requests_client/oauth2_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __call__(self, req):
req.url, req.headers, req.body = self.prepare(
req.url, req.headers, req.body)
except KeyError as error:
description = 'Unsupported token_type: {}'.format(str(error))
description = f'Unsupported token_type: {str(error)}'
raise UnsupportedTokenTypeError(description=description)
return req

Expand Down Expand Up @@ -106,5 +106,5 @@ def request(self, method, url, withhold_token=False, auth=None, **kwargs):
if not self.token:
raise MissingTokenError()
auth = self.token_auth
return super(OAuth2Session, self).request(
return super().request(
method, url, auth=auth, **kwargs)
2 changes: 1 addition & 1 deletion authlib/integrations/starlette_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OAuth(BaseOAuth):
framework_integration_cls = StarletteIntegration

def __init__(self, config=None, cache=None, fetch_token=None, update_token=None):
super(OAuth, self).__init__(
super().__init__(
cache=cache, fetch_token=fetch_token, update_token=update_token)
self.config = config

Expand Down
Loading
Loading