Fixed a Py2/3 issue with review.mailarchive.construct_query_url().
- Legacy-Id: 17379
This commit is contained in:
parent
1017c21167
commit
941a27bf72
|
@ -1,4 +1,4 @@
|
|||
# Copyright The IETF Trust 2016-2019, All Rights Reserved
|
||||
# Copyright The IETF Trust 2016-2020, All Rights Reserved
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
|
@ -8,14 +8,14 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
# various utilities for working with the mailarch mail archive at
|
||||
# mailarchive.ietf.org
|
||||
|
||||
import base64
|
||||
import contextlib
|
||||
import datetime
|
||||
import tarfile
|
||||
import mailbox
|
||||
import tempfile
|
||||
import hashlib
|
||||
import base64
|
||||
import email.utils
|
||||
import hashlib
|
||||
import mailbox
|
||||
import tarfile
|
||||
import tempfile
|
||||
|
||||
from six.moves.urllib.parse import urlencode
|
||||
from six.moves.urllib.request import urlopen
|
||||
|
@ -25,7 +25,7 @@ import debug # pyflakes:ignore
|
|||
from pyquery import PyQuery
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.encoding import force_bytes, force_str
|
||||
|
||||
def list_name_from_email(list_email):
|
||||
if not list_email.endswith("@ietf.org"):
|
||||
|
@ -40,7 +40,7 @@ def hash_list_message_id(list_name, msgid):
|
|||
# and rightmost "=" signs are (optionally) stripped
|
||||
sha = hashlib.sha1(force_bytes(msgid))
|
||||
sha.update(force_bytes(list_name))
|
||||
return base64.urlsafe_b64encode(sha.digest()).rstrip(b"=")
|
||||
return force_str(base64.urlsafe_b64encode(sha.digest()).rstrip(b"="))
|
||||
|
||||
def construct_query_urls(doc, team, query=None):
|
||||
list_name = list_name_from_email(team.list_email)
|
||||
|
@ -109,6 +109,8 @@ def retrieve_messages(query_data_url):
|
|||
"""Retrieve and return selected content from mailarch."""
|
||||
res = []
|
||||
|
||||
# This has not been rewritten to use requests.get() because get() does
|
||||
# not handle file URLs out of the box, which we need for tesing
|
||||
with contextlib.closing(urlopen(query_data_url, timeout=15)) as fileobj:
|
||||
content_type = fileobj.info()["Content-type"]
|
||||
if not content_type.startswith("application/x-tar"):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright The IETF Trust 2019, All Rights Reserved
|
||||
# Copyright The IETF Trust 2019-2020, All Rights Reserved
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
|
@ -12,15 +12,15 @@ class HashTest(TestCase):
|
|||
|
||||
def test_hash_list_message_id(self):
|
||||
for list, msgid, hash in (
|
||||
('ietf', '156182196167.12901.11966487185176024571@ietfa.amsl.com', b'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
|
||||
('codesprints', 'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', b'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
|
||||
('xml2rfc', '3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org', b'g6DN4SxJGDrlSuKsubwb6rRSePU'),
|
||||
(u'ietf', u'156182196167.12901.11966487185176024571@ietfa.amsl.com',b'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
|
||||
(u'codesprints', u'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', b'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
|
||||
(u'xml2rfc', u'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org',b'g6DN4SxJGDrlSuKsubwb6rRSePU'),
|
||||
(b'ietf', b'156182196167.12901.11966487185176024571@ietfa.amsl.com',b'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
|
||||
(b'codesprints', b'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', b'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
|
||||
(b'xml2rfc', b'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org',b'g6DN4SxJGDrlSuKsubwb6rRSePU'),
|
||||
('ietf', '156182196167.12901.11966487185176024571@ietfa.amsl.com', 'lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
|
||||
('codesprints', 'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', 'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
|
||||
('xml2rfc', '3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org', 'g6DN4SxJGDrlSuKsubwb6rRSePU'),
|
||||
(u'ietf', u'156182196167.12901.11966487185176024571@ietfa.amsl.com','lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
|
||||
(u'codesprints', u'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', 'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
|
||||
(u'xml2rfc', u'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org','g6DN4SxJGDrlSuKsubwb6rRSePU'),
|
||||
(b'ietf', b'156182196167.12901.11966487185176024571@ietfa.amsl.com','lr6RtZ4TiVMZn1fZbykhkXeKhEk'),
|
||||
(b'codesprints', b'E1hNffl-0004RM-Dh@zinfandel.tools.ietf.org', 'N1nFHHUXiFWYtdzBgjtqzzILFHI'),
|
||||
(b'xml2rfc', b'3A0F4CD6-451F-44E2-9DA4-28235C638588@rfc-editor.org','g6DN4SxJGDrlSuKsubwb6rRSePU'),
|
||||
):
|
||||
self.assertEqual(hash, hash_list_message_id(list, msgid))
|
||||
|
||||
|
|
Loading…
Reference in a new issue