# HG changeset patch # User Julien Cristau # Date 1444122956 -7200 # Node ID 6cef304aca4cf28d5d593712a4ccf79a914fc243 # Parent 04d24830581043eeb5c7e2f7a718de5fe78c7000 [web] base64 works on bytes not str (py3k) diff -r 04d248305810 -r 6cef304aca4c web/request.py --- a/web/request.py Tue Oct 06 11:14:15 2015 +0200 +++ b/web/request.py Tue Oct 06 11:15:56 2015 +0200 @@ -846,7 +846,7 @@ scheme = scheme.lower() try: assert scheme == "basic" - user, passwd = base64.decodestring(rest).split(":", 1) + user, passwd = base64.decodestring(rest.encode('ascii')).split(b":", 1) # XXX HTTP header encoding: use email.Header? return user.decode('UTF8'), passwd except Exception as ex: diff -r 04d248305810 -r 6cef304aca4c web/test/unittest_application.py --- a/web/test/unittest_application.py Tue Oct 06 11:14:15 2015 +0200 +++ b/web/test/unittest_application.py Tue Oct 06 11:15:56 2015 +0200 @@ -317,8 +317,8 @@ self.app.handle_request(req, 'login') self.assertEqual(401, req.status_out) clear_cache(req, 'get_authorization') - authstr = base64.encodestring('%s:%s' % (self.admlogin, self.admpassword)) - req.set_request_header('Authorization', 'basic %s' % authstr) + authstr = base64.encodestring(('%s:%s' % (self.admlogin, self.admpassword)).encode('ascii')) + req.set_request_header('Authorization', 'basic %s' % authstr.decode('ascii')) self.assertAuthSuccess(req, origsession) self.assertRaises(LogOut, self.app_handle_request, req, 'logout') self.assertEqual(len(self.open_sessions), 0) @@ -393,11 +393,11 @@ def test_http_auth_anon_allowed(self): req, origsession = self.init_authentication('http', 'anon') self._test_auth_anon(req) - authstr = base64.encodestring('toto:pouet') - req.set_request_header('Authorization', 'basic %s' % authstr) + authstr = base64.encodestring(b'toto:pouet') + req.set_request_header('Authorization', 'basic %s' % authstr.decode('ascii')) self._test_anon_auth_fail(req) - authstr = base64.encodestring('%s:%s' % (self.admlogin, self.admpassword)) - req.set_request_header('Authorization', 'basic %s' % authstr) + authstr = base64.encodestring(('%s:%s' % (self.admlogin, self.admpassword)).encode('ascii')) + req.set_request_header('Authorization', 'basic %s' % authstr.decode('ascii')) self.assertAuthSuccess(req, origsession) self.assertRaises(LogOut, self.app_handle_request, req, 'logout') self.assertEqual(len(self.open_sessions), 0)