Skip to content

Commit 941a27b

Browse files
committed
Fixed a Py2/3 issue with review.mailarchive.construct_query_url().
- Legacy-Id: 17379
1 parent 1017c21 commit 941a27b

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

ietf/review/mailarch.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2016-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2016-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -8,14 +8,14 @@
88
# various utilities for working with the mailarch mail archive at
99
# mailarchive.ietf.org
1010

11+
import base64
1112
import contextlib
1213
import datetime
13-
import tarfile
14+
import email.utils
15+
import hashlib
1416
import mailbox
17+
import tarfile
1518
import tempfile
16-
import hashlib
17-
import base64
18-
import email.utils
1919

2020
from six.moves.urllib.parse import urlencode
2121
from six.moves.urllib.request import urlopen
@@ -25,7 +25,7 @@
2525
from pyquery import PyQuery
2626

2727
from django.conf import settings
28-
from django.utils.encoding import force_bytes
28+
from django.utils.encoding import force_bytes, force_str
2929

3030
def list_name_from_email(list_email):
3131
if not list_email.endswith("@ietf.org"):
@@ -40,7 +40,7 @@ def hash_list_message_id(list_name, msgid):
4040
# and rightmost "=" signs are (optionally) stripped
4141
sha = hashlib.sha1(force_bytes(msgid))
4242
sha.update(force_bytes(list_name))
43-
return base64.urlsafe_b64encode(sha.digest()).rstrip(b"=")
43+
return force_str(base64.urlsafe_b64encode(sha.digest()).rstrip(b"="))
4444

4545
def construct_query_urls(doc, team, query=None):
4646
list_name = list_name_from_email(team.list_email)
@@ -109,6 +109,8 @@ def retrieve_messages(query_data_url):
109109
"""Retrieve and return selected content from mailarch."""
110110
res = []
111111

112+
# This has not been rewritten to use requests.get() because get() does
113+
# not handle file URLs out of the box, which we need for tesing
112114
with contextlib.closing(urlopen(query_data_url, timeout=15)) as fileobj:
113115
content_type = fileobj.info()["Content-type"]
114116
if not content_type.startswith("application/x-tar"):

ietf/review/tests.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2019, All Rights Reserved
1+
# Copyright The IETF Trust 2019-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -12,15 +12,15 @@ class HashTest(TestCase):
1212

1313
def test_hash_list_message_id(self):
1414
for list, msgid, hash in (
15-
('ietf', '156182196167.12901.11966487185176024571@ietfa.amsl.com', b'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
16-
('codesprints', 'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', b'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
17-
('xml2rfc', '3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org', b'g6DN4SxJGDrlSuKsubwb6rRSePU'),
18-
(u'ietf', u'156182196167.12901.11966487185176024571@ietfa.amsl.com',b'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
19-
(u'codesprints', u'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', b'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
20-
(u'xml2rfc', u'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org',b'g6DN4SxJGDrlSuKsubwb6rRSePU'),
21-
(b'ietf', b'156182196167.12901.11966487185176024571@ietfa.amsl.com',b'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
22-
(b'codesprints', b'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', b'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
23-
(b'xml2rfc', b'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org',b'g6DN4SxJGDrlSuKsubwb6rRSePU'),
15+
('ietf', '156182196167.12901.11966487185176024571@ietfa.amsl.com', 'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
16+
('codesprints', 'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', 'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
17+
('xml2rfc', '3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org', 'g6DN4SxJGDrlSuKsubwb6rRSePU'),
18+
(u'ietf', u'156182196167.12901.11966487185176024571@ietfa.amsl.com','lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
19+
(u'codesprints', u'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', 'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
20+
(u'xml2rfc', u'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org','g6DN4SxJGDrlSuKsubwb6rRSePU'),
21+
(b'ietf', b'156182196167.12901.11966487185176024571@ietfa.amsl.com','lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
22+
(b'codesprints', b'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', 'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
23+
(b'xml2rfc', b'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org','g6DN4SxJGDrlSuKsubwb6rRSePU'),
2424
):
2525
self.assertEqual(hash, hash_list_message_id(list, msgid))
2626

0 commit comments

Comments
 (0)