summaryrefslogtreecommitdiff
path: root/oauthlib/oauth1/rfc5849
diff options
context:
space:
mode:
Diffstat (limited to 'oauthlib/oauth1/rfc5849')
-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
14 files changed, 32 insertions, 77 deletions
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)