Commit dfaa9872 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

Encode/decode strings/bytes when necessary

With Python 3 we have strong distinction between strings and bytes
objects and we have to use explicit encode/decode operations to deal
with them.
Signed-off-by: Arkadiusz Hiler's avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent 92af6d48
......@@ -114,7 +114,8 @@ class MboxPatchworkLink(TestCase):
response = self.client.get('/patch/%d/mbox/' % self.patch.id,
{'link': 'Patchwork'})
m = re.search(r'^Patchwork:.*/%d/$' % self.patch.pk, response.content,
m = re.search(r'^Patchwork:.*/%d/$' % self.patch.pk,
response.content.decode('utf-8'),
re.M)
self.assertTrue(m)
......
......@@ -143,9 +143,13 @@ class APITestBase(test_series.Series0010):
# will depend on the previous tests run. Make sure to canonicalize
# the mbox file so we can compare md5sums
content = re.sub('^X-Patchwork-Id: .*$', 'X-Patchwork-Id: 1',
response.content, flags=re.M)
response.content.decode('utf-8'), flags=re.M)
with open("/tmp/python36", "w") as fi:
fi.write(content)
content_hash = hashlib.md5()
content_hash.update(content)
content_hash.update(content.encode('utf-8'))
self.assertEqual(content_hash.hexdigest(), md5sum)
def get(self, url, params={}):
......@@ -242,7 +246,8 @@ class APITest(APITestBase):
def _check_mbox_link(self, url, n):
response = self.client.get('/api/1.0' + url, {'link': 'Patchwork'})
m = re.findall('^Patchwork:.*http.*$', response.content, re.M)
m = re.findall('^Patchwork:.*http.*$',
response.content.decode('utf-8'), re.M)
self.assertEqual(len(m), n)
def testSeriesMboxPatchworkLink(self):
......
......@@ -44,8 +44,8 @@ class TestUser(object):
self.username, self.email, self.password)
def basic_auth_header(self):
userpass = "%s:%s" % (self.username, self.password)
return 'Basic ' + base64.b64encode(userpass)
userpass = ("%s:%s" % (self.username, self.password)).encode('utf-8')
return 'Basic ' + base64.b64encode(userpass).decode('utf-8')
def add_to_maintainers(self, project):
profile = self.user.profile
......
......@@ -90,8 +90,8 @@ class PatchworkXMLRPCDispatcher(SimpleXMLRPCDispatcher,
header = header[len('Basic '):].strip()
try:
decoded = base64.decodestring(header)
username, password = decoded.split(':', 1)
decoded = base64.decodestring(header.encode())
username, password = decoded.decode().split(':', 1)
except Exception:
raise Exception('Invalid authentication credentials')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment