summaryrefslogtreecommitdiff
path: root/oauthlib/oauth1
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 /oauthlib/oauth1
parent3718a0e048e64994c2ee3819c5e5ed218a05f115 (diff)
downloadoauthlib-2cec2adf8f54c9eda2a2674f565584aea709ef8a.tar.gz
Upgrade Python syntax with pyupgrade
Diffstat (limited to 'oauthlib/oauth1')
-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
8 files changed, 21 insertions, 21 deletions
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'~')