From b3698acb6c0b9eaa04189599e27014c788a75adc Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 22 Nov 2012 00:20:49 +0100 Subject: First passing test under p3k \o/ --- rest_framework/authentication.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'rest_framework/authentication.py') diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 30c78ebc..4b18b40c 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 @@ -41,8 +45,8 @@ class BasicAuthentication(BaseAuthentication): 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 -- cgit v1.2.3 From 606c20f012c5a1fdcfd661eb280bab22b94afcf5 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 22 Nov 2012 02:08:00 +0100 Subject: 6 first tests passes under python 3.2 --- rest_framework/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/authentication.py') diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 4b18b40c..d283959d 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -40,7 +40,7 @@ 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 -- cgit v1.2.3 From b68263fb652172c5dd74bb7a1c99f0c1230d76bc Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Fri, 23 Nov 2012 01:11:09 +0100 Subject: Default encoding should probably be latin-1 as some RFC seems to imply it. --- rest_framework/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/authentication.py') diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index d283959d..15e531bf 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -40,7 +40,7 @@ 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].encode('utf8')).decode('utf8').partition(':') + auth_parts = base64.b64decode(auth[1].encode('iso-8859-1')).decode('iso-8859-1').partition(':') except TypeError: return None -- cgit v1.2.3 From 06ae47752f8e6fb1605e887b613441f0f72918e6 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 3 Jan 2013 12:49:57 +0100 Subject: Also use the compat module in that file. --- rest_framework/authentication.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'rest_framework/authentication.py') diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 15e531bf..42f6f02b 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -4,12 +4,9 @@ Provides a set of pluggable authentication policies. from django.contrib.auth import authenticate 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.compat import smart_text from rest_framework.authtoken.models import Token import base64 -- cgit v1.2.3 From 510d6a3c5540bbc20406ff79ce5f95d97b2a63f3 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Mon, 7 Jan 2013 23:26:14 +0100 Subject: Introduced HTTP_HEADER_ENCODING. --- rest_framework/authentication.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'rest_framework/authentication.py') diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 42f6f02b..c50bf944 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -8,6 +8,7 @@ from rest_framework import exceptions from rest_framework.compat import CsrfViewMiddleware from rest_framework.compat import smart_text from rest_framework.authtoken.models import Token +from rest_framework.settings import api_settings import base64 @@ -37,7 +38,9 @@ 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].encode('iso-8859-1')).decode('iso-8859-1').partition(':') + encoding = api_settings.HTTP_HEADER_ENCODING + b = base64.b64decode(auth[1].encode(encoding)) + auth_parts = b.decode(encoding).partition(':') except TypeError: return None -- cgit v1.2.3