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

Isort integration #727

Merged
merged 12 commits into from Apr 22, 2020
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -34,6 +34,12 @@ clean-build:
@rm -fr dist/
@rm -fr *.egg-info

format fmt:
isort --recursive oauthlib tests

lint:
isort --recursive --check-only --diff oauthlib tests

test:
tox

Expand Down
7 changes: 4 additions & 3 deletions oauthlib/common.py
Expand Up @@ -12,10 +12,11 @@
import re
import time
import urllib.parse as urlparse
from urllib.parse import (
quote as _quote, unquote as _unquote, urlencode as _urlencode,
)

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
Expand Down
21 changes: 13 additions & 8 deletions oauthlib/oauth1/__init__.py
Expand Up @@ -6,12 +6,17 @@
This module is a wrapper for the most recent implementation of OAuth 1.0 Client
and Server classes.
"""
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
from .rfc5849 import SIGNATURE_TYPE_BODY
from .rfc5849 import (
SIGNATURE_HMAC, SIGNATURE_HMAC_SHA1, SIGNATURE_HMAC_SHA256,
SIGNATURE_PLAINTEXT, SIGNATURE_RSA, SIGNATURE_TYPE_AUTH_HEADER,
SIGNATURE_TYPE_BODY, SIGNATURE_TYPE_QUERY, Client,
)
from .rfc5849.endpoints import (
AccessTokenEndpoint, AuthorizationEndpoint, RequestTokenEndpoint,
ResourceEndpoint, SignatureOnlyEndpoint, WebApplicationServer,
)
from .rfc5849.errors import (
InsecureTransportError, InvalidClientError, InvalidRequestError,
InvalidSignatureMethodError, OAuth1Error,
)
from .rfc5849.request_validator import RequestValidator
from .rfc5849.endpoints import RequestTokenEndpoint, AuthorizationEndpoint
from .rfc5849.endpoints import AccessTokenEndpoint, ResourceEndpoint
from .rfc5849.endpoints import SignatureOnlyEndpoint, WebApplicationServer
from .rfc5849.errors import InsecureTransportError, InvalidClientError, InvalidRequestError, InvalidSignatureMethodError, OAuth1Error
12 changes: 8 additions & 4 deletions oauthlib/oauth1/rfc5849/__init__.py
Expand Up @@ -9,14 +9,18 @@
import base64
import hashlib
import logging
log = logging.getLogger(__name__)

import urllib.parse as urlparse

from oauthlib.common import Request, urlencode, generate_nonce
from oauthlib.common import generate_timestamp, to_unicode
from oauthlib.common import (
Request, generate_nonce, generate_timestamp, to_unicode, urlencode,
)

from . import parameters, signature

log = logging.getLogger(__name__)



SIGNATURE_HMAC_SHA1 = "HMAC-SHA1"
SIGNATURE_HMAC_SHA256 = "HMAC-SHA256"
SIGNATURE_HMAC = SIGNATURE_HMAC_SHA1
Expand Down
7 changes: 4 additions & 3 deletions oauthlib/oauth1/rfc5849/endpoints/__init__.py
@@ -1,7 +1,8 @@
from .access_token import AccessTokenEndpoint
from .authorization import AuthorizationEndpoint
from .base import BaseEndpoint
from .request_token import RequestTokenEndpoint
from .authorization import AuthorizationEndpoint
from .access_token import AccessTokenEndpoint
from .resource import ResourceEndpoint
from .signature_only import SignatureOnlyEndpoint
from .pre_configured import WebApplicationServer

from .pre_configured import WebApplicationServer # isort:skip
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

circular import if import .pre_configured is before import .request_token line

5 changes: 3 additions & 2 deletions oauthlib/oauth1/rfc5849/endpoints/authorization.py
Expand Up @@ -6,11 +6,12 @@
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
"""
from oauthlib.common import Request, add_params_to_uri
from urllib.parse import urlencode

from oauthlib.common import add_params_to_uri

from .. import errors
from .base import BaseEndpoint
from urllib.parse import urlencode


class AuthorizationEndpoint(BaseEndpoint):
Expand Down
8 changes: 5 additions & 3 deletions oauthlib/oauth1/rfc5849/endpoints/base.py
Expand Up @@ -10,9 +10,11 @@

from oauthlib.common import CaseInsensitiveDict, Request, generate_token

from .. import (CONTENT_TYPE_FORM_URLENCODED, SIGNATURE_HMAC_SHA1, SIGNATURE_HMAC_SHA256, SIGNATURE_RSA,
SIGNATURE_TYPE_AUTH_HEADER, SIGNATURE_TYPE_BODY,
SIGNATURE_TYPE_QUERY, errors, signature, utils)
from .. import (
CONTENT_TYPE_FORM_URLENCODED, SIGNATURE_HMAC_SHA1, SIGNATURE_HMAC_SHA256,
SIGNATURE_RSA, SIGNATURE_TYPE_AUTH_HEADER, SIGNATURE_TYPE_BODY,
SIGNATURE_TYPE_QUERY, errors, signature, utils,
)


class BaseEndpoint:
Expand Down
6 changes: 4 additions & 2 deletions oauthlib/oauth1/rfc5849/endpoints/pre_configured.py
@@ -1,5 +1,7 @@
from . import (AccessTokenEndpoint, AuthorizationEndpoint,
RequestTokenEndpoint, ResourceEndpoint)
from . import (
AccessTokenEndpoint, AuthorizationEndpoint, RequestTokenEndpoint,
ResourceEndpoint,
)


class WebApplicationServer(RequestTokenEndpoint, AuthorizationEndpoint,
Expand Down
4 changes: 2 additions & 2 deletions oauthlib/oauth1/rfc5849/parameters.py
Expand Up @@ -7,12 +7,12 @@

.. _`section 3.5`: https://tools.ietf.org/html/rfc5849#section-3.5
"""
from urllib.parse import urlparse, urlunparse

from oauthlib.common import extract_params, urlencode

from . import utils

from urllib.parse import urlparse, urlunparse


# TODO: do we need filter_params now that oauth_params are handled by Request?
# We can easily pass in just oauth protocol params.
Expand Down
2 changes: 0 additions & 2 deletions oauthlib/oauth1/rfc5849/request_validator.py
Expand Up @@ -6,8 +6,6 @@
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
"""
import sys

from . import SIGNATURE_METHODS, utils


Expand Down
3 changes: 1 addition & 2 deletions oauthlib/oauth1/rfc5849/signature.py
Expand Up @@ -25,13 +25,12 @@
import hashlib
import hmac
import logging
import urllib.parse as urlparse

from oauthlib.common import extract_params, safe_string_equals, urldecode
import urllib.parse as urlparse

from . import utils


log = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions oauthlib/oauth1/rfc5849/utils.py
Expand Up @@ -6,10 +6,9 @@
This module contains utility methods used by various parts of the OAuth
spec.
"""
from oauthlib.common import quote, unquote

import urllib.request as urllib2

from oauthlib.common import quote, unquote

UNICODE_ASCII_CHARACTER_SET = ('abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Expand Down
48 changes: 25 additions & 23 deletions oauthlib/oauth2/__init__.py
Expand Up @@ -6,29 +6,31 @@
This module is a wrapper for the most recent implementation of OAuth 2.0 Client
and Server classes.
"""
from .rfc6749.clients import Client
from .rfc6749.clients import WebApplicationClient
from .rfc6749.clients import MobileApplicationClient
from .rfc6749.clients import LegacyApplicationClient
from .rfc6749.clients import BackendApplicationClient
from .rfc6749.clients import ServiceApplicationClient
from .rfc6749.endpoints import AuthorizationEndpoint
from .rfc6749.endpoints import IntrospectEndpoint
from .rfc6749.endpoints import MetadataEndpoint
from .rfc6749.endpoints import TokenEndpoint
from .rfc6749.endpoints import ResourceEndpoint
from .rfc6749.endpoints import RevocationEndpoint
from .rfc6749.endpoints import Server
from .rfc6749.endpoints import WebApplicationServer
from .rfc6749.endpoints import MobileApplicationServer
from .rfc6749.endpoints import LegacyApplicationServer
from .rfc6749.endpoints import BackendApplicationServer
from .rfc6749.errors import AccessDeniedError, OAuth2Error, FatalClientError, InsecureTransportError, InvalidClientError, InvalidClientIdError, InvalidGrantError, InvalidRedirectURIError, InvalidRequestError, InvalidRequestFatalError, InvalidScopeError, MismatchingRedirectURIError, MismatchingStateError, MissingClientIdError, MissingCodeError, MissingRedirectURIError, MissingResponseTypeError, MissingTokenError, MissingTokenTypeError, ServerError, TemporarilyUnavailableError, TokenExpiredError, UnauthorizedClientError, UnsupportedGrantTypeError, UnsupportedResponseTypeError, UnsupportedTokenTypeError
from .rfc6749.grant_types import AuthorizationCodeGrant
from .rfc6749.grant_types import ImplicitGrant
from .rfc6749.grant_types import ResourceOwnerPasswordCredentialsGrant
from .rfc6749.grant_types import ClientCredentialsGrant
from .rfc6749.grant_types import RefreshTokenGrant
from .rfc6749.clients import (
BackendApplicationClient, Client, LegacyApplicationClient,
MobileApplicationClient, ServiceApplicationClient, WebApplicationClient,
)
from .rfc6749.endpoints import (
AuthorizationEndpoint, BackendApplicationServer, IntrospectEndpoint,
LegacyApplicationServer, MetadataEndpoint, MobileApplicationServer,
ResourceEndpoint, RevocationEndpoint, Server, TokenEndpoint,
WebApplicationServer,
)
from .rfc6749.errors import (
AccessDeniedError, FatalClientError, InsecureTransportError,
InvalidClientError, InvalidClientIdError, InvalidGrantError,
InvalidRedirectURIError, InvalidRequestError, InvalidRequestFatalError,
InvalidScopeError, MismatchingRedirectURIError, MismatchingStateError,
MissingClientIdError, MissingCodeError, MissingRedirectURIError,
MissingResponseTypeError, MissingTokenError, MissingTokenTypeError,
OAuth2Error, ServerError, TemporarilyUnavailableError, TokenExpiredError,
UnauthorizedClientError, UnsupportedGrantTypeError,
UnsupportedResponseTypeError, UnsupportedTokenTypeError,
)
from .rfc6749.grant_types import (
AuthorizationCodeGrant, ClientCredentialsGrant, ImplicitGrant,
RefreshTokenGrant, ResourceOwnerPasswordCredentialsGrant,
)
from .rfc6749.request_validator import RequestValidator
from .rfc6749.tokens import BearerToken, OAuth2Token
from .rfc6749.utils import is_secure_transport
9 changes: 4 additions & 5 deletions oauthlib/oauth2/rfc6749/__init__.py
Expand Up @@ -9,10 +9,9 @@
import functools
import logging

from .endpoints.base import BaseEndpoint
from .endpoints.base import catch_errors_and_unavailability
from .errors import TemporarilyUnavailableError, ServerError
from .errors import FatalClientError, OAuth2Error

from .endpoints.base import BaseEndpoint, catch_errors_and_unavailability
from .errors import (
FatalClientError, OAuth2Error, ServerError, TemporarilyUnavailableError,
)

log = logging.getLogger(__name__)
8 changes: 4 additions & 4 deletions oauthlib/oauth2/rfc6749/clients/__init__.py
Expand Up @@ -6,9 +6,9 @@
This module is an implementation of various logic needed
for consuming OAuth 2.0 RFC6749.
"""
from .base import Client, AUTH_HEADER, URI_QUERY, BODY
from .web_application import WebApplicationClient
from .mobile_application import MobileApplicationClient
from .legacy_application import LegacyApplicationClient
from .backend_application import BackendApplicationClient
from .base import AUTH_HEADER, BODY, URI_QUERY, Client
from .legacy_application import LegacyApplicationClient
from .mobile_application import MobileApplicationClient
from .service_application import ServiceApplicationClient
from .web_application import WebApplicationClient
2 changes: 1 addition & 1 deletion oauthlib/oauth2/rfc6749/clients/backend_application.py
Expand Up @@ -6,7 +6,7 @@
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
from ..parameters import parse_token_response, prepare_token_request
from ..parameters import prepare_token_request
from .base import Client


Expand Down
12 changes: 7 additions & 5 deletions oauthlib/oauth2/rfc6749/clients/base.py
Expand Up @@ -11,11 +11,13 @@

from oauthlib.common import generate_token
from oauthlib.oauth2.rfc6749 import tokens
from oauthlib.oauth2.rfc6749.errors import (InsecureTransportError,
TokenExpiredError)
from oauthlib.oauth2.rfc6749.parameters import (parse_token_response,
prepare_token_request,
prepare_token_revocation_request)
from oauthlib.oauth2.rfc6749.errors import (
InsecureTransportError, TokenExpiredError,
)
from oauthlib.oauth2.rfc6749.parameters import (
parse_token_response, prepare_token_request,
prepare_token_revocation_request,
)
from oauthlib.oauth2.rfc6749.utils import is_secure_transport

AUTH_HEADER = 'auth_header'
Expand Down
2 changes: 1 addition & 1 deletion oauthlib/oauth2/rfc6749/clients/legacy_application.py
Expand Up @@ -6,7 +6,7 @@
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
"""
from ..parameters import parse_token_response, prepare_token_request
from ..parameters import prepare_token_request
from .base import Client


Expand Down
2 changes: 1 addition & 1 deletion oauthlib/oauth2/rfc6749/clients/service_application.py
Expand Up @@ -10,7 +10,7 @@

from oauthlib.common import to_unicode

from ..parameters import parse_token_response, prepare_token_request
from ..parameters import prepare_token_request
from .base import Client


Expand Down
7 changes: 4 additions & 3 deletions oauthlib/oauth2/rfc6749/clients/web_application.py
Expand Up @@ -8,9 +8,10 @@
"""
import warnings

from ..parameters import (parse_authorization_code_response,
parse_token_response, prepare_grant_uri,
prepare_token_request)
from ..parameters import (
parse_authorization_code_response, prepare_grant_uri,
prepare_token_request,
)
from .base import Client


Expand Down
11 changes: 5 additions & 6 deletions oauthlib/oauth2/rfc6749/endpoints/__init__.py
Expand Up @@ -9,11 +9,10 @@
from .authorization import AuthorizationEndpoint
from .introspect import IntrospectEndpoint
from .metadata import MetadataEndpoint
from .token import TokenEndpoint
from .pre_configured import (
BackendApplicationServer, LegacyApplicationServer, MobileApplicationServer,
Server, WebApplicationServer,
)
from .resource import ResourceEndpoint
from .revocation import RevocationEndpoint
from .pre_configured import Server
from .pre_configured import WebApplicationServer
from .pre_configured import MobileApplicationServer
from .pre_configured import LegacyApplicationServer
from .pre_configured import BackendApplicationServer
from .token import TokenEndpoint
9 changes: 4 additions & 5 deletions oauthlib/oauth2/rfc6749/endpoints/base.py
Expand Up @@ -9,11 +9,10 @@
import functools
import logging

from ..errors import (FatalClientError, OAuth2Error, ServerError,
TemporarilyUnavailableError, InvalidRequestError,
InvalidClientError, UnsupportedTokenTypeError)

from oauthlib.common import CaseInsensitiveDict, urldecode
from ..errors import (
FatalClientError, InvalidClientError, InvalidRequestError, OAuth2Error,
ServerError, TemporarilyUnavailableError, UnsupportedTokenTypeError,
)

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion oauthlib/oauth2/rfc6749/endpoints/introspect.py
Expand Up @@ -12,7 +12,7 @@

from oauthlib.common import Request

from ..errors import OAuth2Error, UnsupportedTokenTypeError
from ..errors import OAuth2Error
from .base import BaseEndpoint, catch_errors_and_unavailability

log = logging.getLogger(__name__)
Expand Down
7 changes: 3 additions & 4 deletions oauthlib/oauth2/rfc6749/endpoints/metadata.py
Expand Up @@ -11,13 +11,12 @@
import json
import logging

from .base import BaseEndpoint, catch_errors_and_unavailability
from .. import grant_types
from .authorization import AuthorizationEndpoint
from .base import BaseEndpoint, catch_errors_and_unavailability
from .introspect import IntrospectEndpoint
from .token import TokenEndpoint
from .revocation import RevocationEndpoint
from .. import grant_types

from .token import TokenEndpoint

log = logging.getLogger(__name__)

Expand Down
9 changes: 4 additions & 5 deletions oauthlib/oauth2/rfc6749/endpoints/pre_configured.py
Expand Up @@ -6,11 +6,10 @@
This module is an implementation of various endpoints needed
for providing OAuth 2.0 RFC6749 servers.
"""
from ..grant_types import (AuthorizationCodeGrant,
ClientCredentialsGrant,
ImplicitGrant,
RefreshTokenGrant,
ResourceOwnerPasswordCredentialsGrant)
from ..grant_types import (
AuthorizationCodeGrant, ClientCredentialsGrant, ImplicitGrant,
RefreshTokenGrant, ResourceOwnerPasswordCredentialsGrant,
)
from ..tokens import BearerToken
from .authorization import AuthorizationEndpoint
from .introspect import IntrospectEndpoint
Expand Down