launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26229
[Merge] ~cjwatson/launchpad:py3-use-message-as-bytes into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-use-message-as-bytes into launchpad:master.
Commit message:
Use message_as_bytes instead of earlier attempts
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397582
In earlier stages of porting to Python 3 I added version-dependent conditionals that called message.as_bytes() or message.as_string() as appropriate. message_as_bytes is now known to behave properly, so use that instead.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-use-message-as-bytes into launchpad:master.
diff --git a/lib/lp/bugs/externalbugtracker/tests/test_debbugs.py b/lib/lp/bugs/externalbugtracker/tests/test_debbugs.py
index 9c0a0e1..76e576e 100644
--- a/lib/lp/bugs/externalbugtracker/tests/test_debbugs.py
+++ b/lib/lp/bugs/externalbugtracker/tests/test_debbugs.py
@@ -6,7 +6,6 @@
import email.message
import errno
import os
-import sys
from testtools.matchers import (
Equals,
@@ -26,6 +25,7 @@ from lp.bugs.scripts.debbugs import (
SummaryParseError,
SummaryVersionError,
)
+from lp.services.compat import message_as_bytes
from lp.testing import TestCase
@@ -57,10 +57,7 @@ class TestDebBugs(TestCase):
for h in headers:
m[h] = headers[h]
with open(os.path.join(bucket, "%s.summary" % (bug_id,)), "wb") as f:
- if sys.version_info[:2] >= (3, 5):
- f.write(m.as_bytes())
- else:
- f.write(m.as_string())
+ f.write(message_as_bytes(m))
def test_no_db_dir(self):
err = self.assertRaises(DebBugsDatabaseNotFound, self.get_tracker)
diff --git a/lib/lp/services/mail/sendmail.py b/lib/lp/services/mail/sendmail.py
index a8ea76e..300d698 100644
--- a/lib/lp/services/mail/sendmail.py
+++ b/lib/lp/services/mail/sendmail.py
@@ -55,6 +55,7 @@ from zope.security.proxy import (
from zope.sendmail.interfaces import IMailDelivery
from lp.app import versioninfo
+from lp.services.compat import message_as_bytes
from lp.services.config import config
from lp.services.encoding import is_ascii_only
from lp.services.mail.stub import TestMailer
@@ -448,10 +449,7 @@ def sendmail(message, to_addrs=None, bulk=True):
hash.update(six.ensure_binary(message['message-id']))
message['X-Launchpad-Hash'] = hash.hexdigest()
- if sys.version_info[:2] >= (3, 4):
- raw_message = message.as_bytes()
- else:
- raw_message = message.as_string()
+ raw_message = message_as_bytes(message)
message_detail = message['Subject']
if not isinstance(message_detail, six.string_types):
# Might be a Header object; can be squashed.