aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/authentication.py
diff options
context:
space:
mode:
authorXavier Ordoquy2012-11-22 07:48:41 +0100
committerXavier Ordoquy2012-11-22 07:48:41 +0100
commitbe003145ca120708db51db4e85f6088bde8dce1c (patch)
tree9df0e343b9adc196ddd7e5fbc1b93e4c339260b2 /rest_framework/authentication.py
parent91190487b747f0c9c09ecd5678f719bb2e745d27 (diff)
parent606c20f012c5a1fdcfd661eb280bab22b94afcf5 (diff)
downloaddjango-rest-framework-be003145ca120708db51db4e85f6088bde8dce1c.tar.bz2
Merge branch 'p3k' of github.com:linovia/django-rest-framework into p3k
Diffstat (limited to 'rest_framework/authentication.py')
-rw-r--r--rest_framework/authentication.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py
index 30c78ebc..d283959d 100644
--- a/rest_framework/authentication.py
+++ b/rest_framework/authentication.py
@@ -3,7 +3,11 @@ Provides a set of pluggable authentication policies.
"""
from django.contrib.auth import authenticate
-from django.utils.encoding import smart_unicode, DjangoUnicodeDecodeError
+from django.utils.encoding import DjangoUnicodeDecodeError
+try:
+ from django.utils.encoding import smart_text
+except ImportError:
+ from django.utils.encoding import smart_unicode as smart_text
from rest_framework import exceptions
from rest_framework.compat import CsrfViewMiddleware
from rest_framework.authtoken.models import Token
@@ -36,13 +40,13 @@ class BasicAuthentication(BaseAuthentication):
auth = request.META['HTTP_AUTHORIZATION'].split()
if len(auth) == 2 and auth[0].lower() == "basic":
try:
- auth_parts = base64.b64decode(auth[1]).partition(':')
+ auth_parts = base64.b64decode(auth[1].encode('utf8')).decode('utf8').partition(':')
except TypeError:
return None
try:
- userid = smart_unicode(auth_parts[0])
- password = smart_unicode(auth_parts[2])
+ userid = smart_text(auth_parts[0])
+ password = smart_text(auth_parts[2])
except DjangoUnicodeDecodeError:
return None