Skip to content

Commit 8ef4178

Browse files
committed
Standardize quotes and add flake8-quotes linter
1 parent d93f9c3 commit 8ef4178

File tree

17 files changed

+267
-245
lines changed

17 files changed

+267
-245
lines changed

oauth2_provider/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class DOTConfig(AppConfig):
5-
name = 'oauth2_provider'
5+
name = "oauth2_provider"
66
verbose_name = "Django OAuth Toolkit"

oauth2_provider/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _validate(request, *args, **kwargs):
6767
)
6868

6969
# Check if method is safe
70-
if request.method.upper() in ['GET', 'HEAD', 'OPTIONS']:
70+
if request.method.upper() in ["GET", "HEAD", "OPTIONS"]:
7171
_scopes.append(oauth2_settings.READ_SCOPE)
7272
else:
7373
_scopes.append(oauth2_settings.WRITE_SCOPE)

oauth2_provider/ext/rest_framework/authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class OAuth2Authentication(BaseAuthentication):
77
"""
88
OAuth 2 authentication backend using `django-oauth-toolkit`
99
"""
10-
www_authenticate_realm = 'api'
10+
www_authenticate_realm = "api"
1111

1212
def authenticate(self, request):
1313
"""

oauth2_provider/ext/rest_framework/permissions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from ...settings import oauth2_settings
88

99

10-
log = logging.getLogger('oauth2_provider')
10+
log = logging.getLogger("oauth2_provider")
1111

12-
SAFE_HTTP_METHODS = ['GET', 'HEAD', 'OPTIONS']
12+
SAFE_HTTP_METHODS = ["GET", "HEAD", "OPTIONS"]
1313

1414

1515
class TokenHasScope(BasePermission):
@@ -23,22 +23,23 @@ def has_permission(self, request, view):
2323
if not token:
2424
return False
2525

26-
if hasattr(token, 'scope'): # OAuth 2
26+
if hasattr(token, "scope"): # OAuth 2
2727
required_scopes = self.get_scopes(request, view)
2828
log.debug("Required scopes to access resource: {0}".format(required_scopes))
2929

3030
return token.is_valid(required_scopes)
3131

32-
assert False, ('TokenHasScope requires the'
33-
'`oauth2_provider.rest_framework.OAuth2Authentication` authentication '
34-
'class to be used.')
32+
assert False, ("TokenHasScope requires the"
33+
"`oauth2_provider.rest_framework.OAuth2Authentication` authentication "
34+
"class to be used.")
3535

3636
def get_scopes(self, request, view):
3737
try:
38-
return getattr(view, 'required_scopes')
38+
return getattr(view, "required_scopes")
3939
except AttributeError:
4040
raise ImproperlyConfigured(
41-
'TokenHasScope requires the view to define the required_scopes attribute')
41+
"TokenHasScope requires the view to define the required_scopes attribute"
42+
)
4243

4344

4445
class TokenHasReadWriteScope(TokenHasScope):
@@ -80,7 +81,7 @@ def get_scopes(self, request, view):
8081
scope_type = oauth2_settings.WRITE_SCOPE
8182

8283
required_scopes = [
83-
'{0}:{1}'.format(scope, scope_type) for scope in view_scopes
84+
"{}:{}".format(scope, scope_type) for scope in view_scopes
8485
]
8586

8687
return required_scopes

oauth2_provider/middleware.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ class OAuth2TokenMiddleware(MiddlewareMixin):
2020
also request._cached_user field makes AuthenticationMiddleware use that instead of the one from
2121
the session.
2222
23-
It also adds 'Authorization' to the 'Vary' header. So that django's cache middleware or a
24-
reverse proxy can create proper cache keys
23+
It also adds "Authorization" to the "Vary" header, so that django's cache middleware or a
24+
reverse proxy can create proper cache keys.
2525
"""
2626
def process_request(self, request):
2727
# do something only if request contains a Bearer token
28-
if request.META.get('HTTP_AUTHORIZATION', '').startswith('Bearer'):
29-
if not hasattr(request, 'user') or request.user.is_anonymous:
28+
if request.META.get("HTTP_AUTHORIZATION", "").startswith("Bearer"):
29+
if not hasattr(request, "user") or request.user.is_anonymous:
3030
user = authenticate(request=request)
3131
if user:
3232
request.user = request._cached_user = user
3333

3434
def process_response(self, request, response):
35-
patch_vary_headers(response, ('Authorization',))
35+
patch_vary_headers(response, ("Authorization",))
3636
return response

oauth2_provider/models.py

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,44 @@ class AbstractApplication(models.Model):
3939
the registration process as described in :rfc:`2.2`
4040
* :attr:`name` Friendly name for the Application
4141
"""
42-
CLIENT_CONFIDENTIAL = 'confidential'
43-
CLIENT_PUBLIC = 'public'
42+
CLIENT_CONFIDENTIAL = "confidential"
43+
CLIENT_PUBLIC = "public"
4444
CLIENT_TYPES = (
45-
(CLIENT_CONFIDENTIAL, _('Confidential')),
46-
(CLIENT_PUBLIC, _('Public')),
45+
(CLIENT_CONFIDENTIAL, _("Confidential")),
46+
(CLIENT_PUBLIC, _("Public")),
4747
)
4848

49-
GRANT_AUTHORIZATION_CODE = 'authorization-code'
50-
GRANT_IMPLICIT = 'implicit'
51-
GRANT_PASSWORD = 'password'
52-
GRANT_CLIENT_CREDENTIALS = 'client-credentials'
49+
GRANT_AUTHORIZATION_CODE = "authorization-code"
50+
GRANT_IMPLICIT = "implicit"
51+
GRANT_PASSWORD = "password"
52+
GRANT_CLIENT_CREDENTIALS = "client-credentials"
5353
GRANT_TYPES = (
54-
(GRANT_AUTHORIZATION_CODE, _('Authorization code')),
55-
(GRANT_IMPLICIT, _('Implicit')),
56-
(GRANT_PASSWORD, _('Resource owner password-based')),
57-
(GRANT_CLIENT_CREDENTIALS, _('Client credentials')),
54+
(GRANT_AUTHORIZATION_CODE, _("Authorization code")),
55+
(GRANT_IMPLICIT, _("Implicit")),
56+
(GRANT_PASSWORD, _("Resource owner password-based")),
57+
(GRANT_CLIENT_CREDENTIALS, _("Client credentials")),
5858
)
5959

60-
client_id = models.CharField(max_length=100, unique=True,
61-
default=generate_client_id, db_index=True)
62-
user = models.ForeignKey(settings.AUTH_USER_MODEL,
63-
related_name="%(app_label)s_%(class)s",
64-
null=True, blank=True, on_delete=models.CASCADE)
60+
client_id = models.CharField(
61+
max_length=100, unique=True, default=generate_client_id, db_index=True
62+
)
63+
user = models.ForeignKey(
64+
settings.AUTH_USER_MODEL,
65+
related_name="%(app_label)s_%(class)s",
66+
null=True, blank=True, on_delete=models.CASCADE
67+
)
6568

6669
help_text = _("Allowed URIs list, space separated")
67-
redirect_uris = models.TextField(help_text=help_text,
68-
validators=[validate_uris], blank=True)
70+
redirect_uris = models.TextField(
71+
blank=True, help_text=help_text, validators=[validate_uris]
72+
)
6973
client_type = models.CharField(max_length=32, choices=CLIENT_TYPES)
70-
authorization_grant_type = models.CharField(max_length=32,
71-
choices=GRANT_TYPES)
72-
client_secret = models.CharField(max_length=255, blank=True,
73-
default=generate_client_secret, db_index=True)
74+
authorization_grant_type = models.CharField(
75+
max_length=32, choices=GRANT_TYPES
76+
)
77+
client_secret = models.CharField(
78+
max_length=255, blank=True, default=generate_client_secret, db_index=True
79+
)
7480
name = models.CharField(max_length=255, blank=True)
7581
skip_authorization = models.BooleanField(default=False)
7682

@@ -86,9 +92,11 @@ def default_redirect_uri(self):
8692
if self.redirect_uris:
8793
return self.redirect_uris.split().pop(0)
8894

89-
assert False, "If you are using implicit, authorization_code" \
90-
"or all-in-one grant_type, you must define " \
91-
"redirect_uris field in your Application model"
95+
assert False, (
96+
"If you are using implicit, authorization_code"
97+
"or all-in-one grant_type, you must define "
98+
"redirect_uris field in your Application model"
99+
)
92100

93101
def redirect_uri_allowed(self, uri):
94102
"""
@@ -118,11 +126,11 @@ def clean(self):
118126
and self.authorization_grant_type \
119127
in (AbstractApplication.GRANT_AUTHORIZATION_CODE,
120128
AbstractApplication.GRANT_IMPLICIT):
121-
error = _('Redirect_uris could not be empty with {0} grant_type')
122-
raise ValidationError(error.format(self.authorization_grant_type))
129+
error = _("Redirect_uris could not be empty with {grant_type} grant_type")
130+
raise ValidationError(error.format(grant_type=self.authorization_grant_type))
123131

124132
def get_absolute_url(self):
125-
return reverse('oauth2_provider:detail', args=[str(self.id)])
133+
return reverse("oauth2_provider:detail", args=[str(self.id)])
126134

127135
def __str__(self):
128136
return self.name or self.client_id
@@ -141,7 +149,7 @@ def is_usable(self, request):
141149

142150
class Application(AbstractApplication):
143151
class Meta(AbstractApplication.Meta):
144-
swappable = 'OAUTH2_PROVIDER_APPLICATION_MODEL'
152+
swappable = "OAUTH2_PROVIDER_APPLICATION_MODEL"
145153

146154

147155
@python_2_unicode_compatible
@@ -289,14 +297,17 @@ class AbstractRefreshToken(models.Model):
289297
* :attr:`access_token` AccessToken instance this refresh token is
290298
bounded to
291299
"""
292-
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
293-
related_name="%(app_label)s_%(class)s")
300+
user = models.ForeignKey(
301+
settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
302+
related_name="%(app_label)s_%(class)s"
303+
)
294304
token = models.CharField(max_length=255, unique=True)
295-
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL,
296-
on_delete=models.CASCADE)
297-
access_token = models.OneToOneField(oauth2_settings.ACCESS_TOKEN_MODEL,
298-
related_name='refresh_token',
299-
on_delete=models.CASCADE)
305+
application = models.ForeignKey(
306+
oauth2_settings.APPLICATION_MODEL, on_delete=models.CASCADE)
307+
access_token = models.OneToOneField(
308+
oauth2_settings.ACCESS_TOKEN_MODEL, on_delete=models.CASCADE,
309+
related_name="refresh_token"
310+
)
300311

301312
def revoke(self):
302313
"""

oauth2_provider/oauth2_backends.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _get_escaped_full_path(self, request):
2828
parsed = list(urlparse(request.get_full_path()))
2929
unsafe = set(c for c in parsed[4]).difference(urlencoded)
3030
for c in unsafe:
31-
parsed[4] = parsed[4].replace(c, quote(c, safe=b''))
31+
parsed[4] = parsed[4].replace(c, quote(c, safe=b""))
3232

3333
return urlunparse(parsed)
3434

@@ -62,12 +62,12 @@ def extract_headers(self, request):
6262
:return: a dictionary with OAuthLib needed headers
6363
"""
6464
headers = request.META.copy()
65-
if 'wsgi.input' in headers:
66-
del headers['wsgi.input']
67-
if 'wsgi.errors' in headers:
68-
del headers['wsgi.errors']
69-
if 'HTTP_AUTHORIZATION' in headers:
70-
headers['Authorization'] = headers['HTTP_AUTHORIZATION']
65+
if "wsgi.input" in headers:
66+
del headers["wsgi.input"]
67+
if "wsgi.errors" in headers:
68+
del headers["wsgi.errors"]
69+
if "HTTP_AUTHORIZATION" in headers:
70+
headers["Authorization"] = headers["HTTP_AUTHORIZATION"]
7171

7272
return headers
7373

@@ -113,18 +113,18 @@ def create_authorization_response(self, request, scopes, credentials, allow):
113113
raise oauth2.AccessDeniedError()
114114

115115
# add current user to credentials. this will be used by OAUTH2_VALIDATOR_CLASS
116-
credentials['user'] = request.user
116+
credentials["user"] = request.user
117117

118118
headers, body, status = self.server.create_authorization_response(
119-
uri=credentials['redirect_uri'], scopes=scopes, credentials=credentials)
119+
uri=credentials["redirect_uri"], scopes=scopes, credentials=credentials)
120120
uri = headers.get("Location", None)
121121

122122
return uri, headers, body, status
123123

124124
except oauth2.FatalClientError as error:
125-
raise FatalClientError(error=error, redirect_uri=credentials['redirect_uri'])
125+
raise FatalClientError(error=error, redirect_uri=credentials["redirect_uri"])
126126
except oauth2.OAuth2Error as error:
127-
raise OAuthToolkitError(error=error, redirect_uri=credentials['redirect_uri'])
127+
raise OAuthToolkitError(error=error, redirect_uri=credentials["redirect_uri"])
128128

129129
def create_token_response(self, request):
130130
"""
@@ -180,7 +180,7 @@ def extract_body(self, request):
180180
:return: provided POST parameters "urlencodable"
181181
"""
182182
try:
183-
body = json.loads(request.body.decode('utf-8')).items()
183+
body = json.loads(request.body.decode("utf-8")).items()
184184
except ValueError:
185185
body = ""
186186

0 commit comments

Comments
 (0)