mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
more passing tests
more f strings done
This commit is contained in:
parent
e7ecbf92c4
commit
0bb44a8c0f
|
@ -106,7 +106,7 @@ class BasicAuthentication(BaseAuthentication):
|
||||||
return (user, None)
|
return (user, None)
|
||||||
|
|
||||||
def authenticate_header(self, request):
|
def authenticate_header(self, request):
|
||||||
return 'Basic realm="%s"' % self.www_authenticate_realm
|
return f'Basic realm="{self.www_authenticate_realm}"'
|
||||||
|
|
||||||
|
|
||||||
class SessionAuthentication(BaseAuthentication):
|
class SessionAuthentication(BaseAuthentication):
|
||||||
|
@ -145,7 +145,7 @@ class SessionAuthentication(BaseAuthentication):
|
||||||
reason = check.process_view(request, None, (), {})
|
reason = check.process_view(request, None, (), {})
|
||||||
if reason:
|
if reason:
|
||||||
# CSRF failed, bail with explicit error message
|
# CSRF failed, bail with explicit error message
|
||||||
raise exceptions.PermissionDenied('CSRF Failed: %s' % reason)
|
raise exceptions.PermissionDenied(f'CSRF Failed: {reason}')
|
||||||
|
|
||||||
|
|
||||||
class TokenAuthentication(BaseAuthentication):
|
class TokenAuthentication(BaseAuthentication):
|
||||||
|
|
|
@ -77,7 +77,7 @@ class _MediaType:
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
ret = "%s/%s" % (self.main_type, self.sub_type)
|
ret = f"{self.main_type}/{self.sub_type}"
|
||||||
for key, val in self.params.items():
|
for key, val in self.params.items():
|
||||||
ret += "; %s=%s" % (key, val.decode('ascii'))
|
ret += f"; {key}={val.decode('ascii')}"
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -19,7 +19,7 @@ def manager_repr(value):
|
||||||
]
|
]
|
||||||
for manager_name, manager_instance in names_and_managers:
|
for manager_name, manager_instance in names_and_managers:
|
||||||
if manager_instance == value:
|
if manager_instance == value:
|
||||||
return '%s.%s.all()' % (model._meta.object_name, manager_name)
|
return f'{model._meta.object_name}.{manager_name}.all()'
|
||||||
return repr(value)
|
return repr(value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ def exception_handler(exc, context):
|
||||||
if getattr(exc, 'auth_header', None):
|
if getattr(exc, 'auth_header', None):
|
||||||
headers['WWW-Authenticate'] = exc.auth_header
|
headers['WWW-Authenticate'] = exc.auth_header
|
||||||
if getattr(exc, 'wait', None):
|
if getattr(exc, 'wait', None):
|
||||||
headers['Retry-After'] = '%d' % exc.wait
|
headers['Retry-After'] = f'{exc.wait}'
|
||||||
|
|
||||||
if isinstance(exc.detail, (list, dict)):
|
if isinstance(exc.detail, (list, dict)):
|
||||||
data = exc.detail
|
data = exc.detail
|
||||||
|
|
|
@ -88,17 +88,17 @@ class ViewSetMixin:
|
||||||
# sanitize keyword arguments
|
# sanitize keyword arguments
|
||||||
for key in initkwargs:
|
for key in initkwargs:
|
||||||
if key in cls.http_method_names:
|
if key in cls.http_method_names:
|
||||||
raise TypeError("You tried to pass in the %s method name as a "
|
raise TypeError(f"You tried to pass in the {key} method name as a "
|
||||||
"keyword argument to %s(). Don't do that."
|
f"keyword argument to {cls.__name__}(). Don't do that."
|
||||||
% (key, cls.__name__))
|
)
|
||||||
if not hasattr(cls, key):
|
if not hasattr(cls, key):
|
||||||
raise TypeError("%s() received an invalid keyword %r" % (
|
raise TypeError("%s() received an invalid keyword %r" % (
|
||||||
cls.__name__, key))
|
cls.__name__, key))
|
||||||
|
|
||||||
# name and suffix are mutually exclusive
|
# name and suffix are mutually exclusive
|
||||||
if 'name' in initkwargs and 'suffix' in initkwargs:
|
if 'name' in initkwargs and 'suffix' in initkwargs:
|
||||||
raise TypeError("%s() received both `name` and `suffix`, which are "
|
raise TypeError(f"{cls.__name__}() received both `name` and `suffix`, which are "
|
||||||
"mutually exclusive arguments." % (cls.__name__))
|
"mutually exclusive arguments.")
|
||||||
|
|
||||||
def view(request, *args, **kwargs):
|
def view(request, *args, **kwargs):
|
||||||
self = cls(**initkwargs)
|
self = cls(**initkwargs)
|
||||||
|
@ -158,7 +158,7 @@ class ViewSetMixin:
|
||||||
"""
|
"""
|
||||||
Reverse the action for the given `url_name`.
|
Reverse the action for the given `url_name`.
|
||||||
"""
|
"""
|
||||||
url_name = '%s-%s' % (self.basename, url_name)
|
url_name = f'{self.basename}-{url_name}'
|
||||||
namespace = None
|
namespace = None
|
||||||
if self.request and self.request.resolver_match:
|
if self.request and self.request.resolver_match:
|
||||||
namespace = self.request.resolver_match.namespace
|
namespace = self.request.resolver_match.namespace
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Bookmark(models.Model):
|
||||||
tags = GenericRelation(Tag)
|
tags = GenericRelation(Tag)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Bookmark: %s' % self.url
|
return f'Bookmark: {self.url}'
|
||||||
|
|
||||||
|
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
|
@ -37,4 +37,4 @@ class Note(models.Model):
|
||||||
tags = GenericRelation(Tag)
|
tags = GenericRelation(Tag)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Note: %s' % self.text
|
return f'Note: {self.text}'
|
||||||
|
|
|
@ -2310,7 +2310,7 @@ class TestSerializerMethodField:
|
||||||
example_field = serializers.SerializerMethodField()
|
example_field = serializers.SerializerMethodField()
|
||||||
|
|
||||||
def get_example_field(self, obj):
|
def get_example_field(self, obj):
|
||||||
return 'ran get_example_field(%d)' % obj['example_field']
|
return f'ran get_example_field({obj["example_field"]})'
|
||||||
|
|
||||||
serializer = ExampleSerializer({'example_field': 123})
|
serializer = ExampleSerializer({'example_field': 123})
|
||||||
assert serializer.data == {
|
assert serializer.data == {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user