aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/authentication.py
diff options
context:
space:
mode:
authorCraig Blaszczyk2015-01-07 12:01:11 +0000
committerCraig Blaszczyk2015-01-07 12:01:11 +0000
commit4c32083b8b59a50877633910055313dad7bb117e (patch)
tree4de7729161f512c7c14beaafc4a6f776ce772cc1 /rest_framework/authentication.py
parentfe5d93c8cbc5f3a9b1b6715208c70f485be68bdf (diff)
downloaddjango-rest-framework-4c32083b8b59a50877633910055313dad7bb117e.tar.bz2
use double quotes for user visible strings; end user visible strings in full stops; add some missing translation tags
Diffstat (limited to 'rest_framework/authentication.py')
-rw-r--r--rest_framework/authentication.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py
index 124ef68a..7e86a7b9 100644
--- a/rest_framework/authentication.py
+++ b/rest_framework/authentication.py
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import base64
from django.contrib.auth import authenticate
from django.middleware.csrf import CsrfViewMiddleware
+from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions, HTTP_HEADER_ENCODING
from rest_framework.authtoken.models import Token
@@ -65,16 +66,16 @@ class BasicAuthentication(BaseAuthentication):
return None
if len(auth) == 1:
- msg = 'Invalid basic header. No credentials provided.'
+ msg = _("Invalid basic header. No credentials provided.")
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
- msg = 'Invalid basic header. Credentials string should not contain spaces.'
+ msg = _("Invalid basic header. Credentials string should not contain spaces.")
raise exceptions.AuthenticationFailed(msg)
try:
auth_parts = base64.b64decode(auth[1]).decode(HTTP_HEADER_ENCODING).partition(':')
except (TypeError, UnicodeDecodeError):
- msg = 'Invalid basic header. Credentials not correctly base64 encoded'
+ msg = _("Invalid basic header. Credentials not correctly base64 encoded.")
raise exceptions.AuthenticationFailed(msg)
userid, password = auth_parts[0], auth_parts[2]
@@ -86,7 +87,7 @@ class BasicAuthentication(BaseAuthentication):
"""
user = authenticate(username=userid, password=password)
if user is None or not user.is_active:
- raise exceptions.AuthenticationFailed('Invalid username/password')
+ raise exceptions.AuthenticationFailed(_("Invalid username/password."))
return (user, None)
def authenticate_header(self, request):
@@ -152,10 +153,10 @@ class TokenAuthentication(BaseAuthentication):
return None
if len(auth) == 1:
- msg = 'Invalid token header. No credentials provided.'
+ msg = _("Invalid token header. No credentials provided.")
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
- msg = 'Invalid token header. Token string should not contain spaces.'
+ msg = _("Invalid token header. Token string should not contain spaces.")
raise exceptions.AuthenticationFailed(msg)
return self.authenticate_credentials(auth[1])
@@ -164,10 +165,10 @@ class TokenAuthentication(BaseAuthentication):
try:
token = self.model.objects.get(key=key)
except self.model.DoesNotExist:
- raise exceptions.AuthenticationFailed('Invalid token')
+ raise exceptions.AuthenticationFailed(_("Invalid token"))
if not token.user.is_active:
- raise exceptions.AuthenticationFailed('User inactive or deleted')
+ raise exceptions.AuthenticationFailed(_("User inactive or deleted"))
return (token.user, token)