Browse files

Fixes for Python 3.

  • Loading branch information...
1 parent 1f85ed0 commit 407e302250d9020c3c0a13f63f9252e766d3286a @chrisrossi chrisrossi committed Oct 14, 2012
Showing with 5 additions and 5 deletions.
  1. +2 −2 pyramid/authentication.py
  2. +3 −3 pyramid/tests/test_authentication.py
View
4 pyramid/authentication.py
@@ -890,8 +890,8 @@ def _get_credentials(self, request):
if authmeth.lower() != 'basic':
return None
try:
- auth = auth.strip().decode('base64')
- except binascii.Error: # can't decode
+ auth = b64decode(auth.strip()).decode('ascii')
+ except (TypeError, binascii.Error): # can't decode
return None
try:
username, password = auth.split(':', 1)
View
6 pyramid/tests/test_authentication.py
@@ -1123,7 +1123,7 @@ def test_unauthenticated_userid(self):
import base64
request = testing.DummyRequest()
request.headers['Authorization'] = 'Basic %s' % base64.b64encode(
- 'chrisr:password')
+ bytes_('chrisr:password')).decode('ascii')
policy = self._makeOne(None)
self.assertEqual(policy.unauthenticated_userid(request), 'chrisr')
@@ -1154,7 +1154,7 @@ def test_authenticated_userid(self):
import base64
request = testing.DummyRequest()
request.headers['Authorization'] = 'Basic %s' % base64.b64encode(
- 'chrisr:password')
+ bytes_('chrisr:password')).decode('ascii')
def check(username, password, request):
return []
policy = self._makeOne(check)
@@ -1164,7 +1164,7 @@ def test_unauthenticated_userid_invalid_payload(self):
import base64
request = testing.DummyRequest()
request.headers['Authorization'] = 'Basic %s' % base64.b64encode(
- 'chrisrpassword')
+ bytes_('chrisrpassword')).decode('ascii')
policy = self._makeOne(None)
self.assertEqual(policy.unauthenticated_userid(request), None)

0 comments on commit 407e302

Please sign in to comment.