← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-externalbugtracker into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-externalbugtracker into launchpad:master.

Commit message:
Fix the rest of externalbugtracker for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/399030

There were just a few remaining bytes/text issues, and externalbugtracker-debbugs.txt needs to use message_from_bytes rather than email.message_from_string in two more places.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-externalbugtracker into launchpad:master.
diff --git a/lib/lp/bugs/doc/externalbugtracker-bugzilla-oddities.txt b/lib/lp/bugs/doc/externalbugtracker-bugzilla-oddities.txt
index b91e7ee..b6d2f3a 100644
--- a/lib/lp/bugs/doc/externalbugtracker-bugzilla-oddities.txt
+++ b/lib/lp/bugs/doc/externalbugtracker-bugzilla-oddities.txt
@@ -109,10 +109,10 @@ Some Bugzillas have some weird properties that we need to cater for:
 
   b) The content is non-ascii:
 
-    >>> bug_item_file.decode("ascii")
+    >>> six.ensure_text(bug_item_file).encode("ascii")
     Traceback (most recent call last):
     ...
-    UnicodeDecodeError: 'ascii' codec can't decode byte...
+    UnicodeEncodeError: 'ascii' codec can't encode character...
 
 Yet everything still works as expected:
 
diff --git a/lib/lp/bugs/doc/externalbugtracker-debbugs.txt b/lib/lp/bugs/doc/externalbugtracker-debbugs.txt
index 9d97e70..3ed2b15 100644
--- a/lib/lp/bugs/doc/externalbugtracker-debbugs.txt
+++ b/lib/lp/bugs/doc/externalbugtracker-debbugs.txt
@@ -495,8 +495,9 @@ datecreated comes not from the Date header but from the Received header.
 
     >>> from lp.bugs.tests.externalbugtracker import (
     ...     read_test_file)
-    >>> parsed_message = email.message_from_string(
-    ...     read_test_file('debbugs-comment-with-received-date.txt'))
+    >>> parsed_message = message_from_bytes(
+    ...     read_test_file('debbugs-comment-with-received-date.txt').encode(
+    ...         'UTF-8'))
 
     >>> print(parsed_message['date'])
     Fri, 14 Dec 2007 18:54:30 +0000
@@ -520,8 +521,9 @@ default to using the Date header again.
     >>> print(message.datecreated)
     2007-12-14 18:54:30+00:00
 
-    >>> parsed_message = email.message_from_string(
-    ...     read_test_file('debbugs-comment-with-received-date.txt'))
+    >>> parsed_message = message_from_bytes(
+    ...     read_test_file('debbugs-comment-with-received-date.txt').encode(
+    ...         'UTF-8'))
 
     >>> print(parsed_message['date'])
     Fri, 14 Dec 2007 18:54:30 +0000
diff --git a/lib/lp/bugs/scripts/debbugs.py b/lib/lp/bugs/scripts/debbugs.py
index 0d3c3c8..c1c6b39 100644
--- a/lib/lp/bugs/scripts/debbugs.py
+++ b/lib/lp/bugs/scripts/debbugs.py
@@ -231,10 +231,10 @@ class Database:
             logreader = process.stdout
             comment = io.BytesIO()
             for line in logreader:
-                if line == '.\n':
+                if line == b'.\n':
                     comments.append(comment.getvalue())
                     comment = io.BytesIO()
-                elif line.startswith('.'):
+                elif line.startswith(b'.'):
                     comment.write(line[1:])
                 else:
                     comment.write(line)
diff --git a/lib/lp/bugs/tests/externalbugtracker.py b/lib/lp/bugs/tests/externalbugtracker.py
index b74e45c..fe969fe 100644
--- a/lib/lp/bugs/tests/externalbugtracker.py
+++ b/lib/lp/bugs/tests/externalbugtracker.py
@@ -100,8 +100,8 @@ def read_test_file(name):
     """Return the contents of the test file named :name:"""
     file_path = os.path.join(os.path.dirname(__file__), 'testfiles', name)
 
-    test_file = open(file_path, 'r')
-    return test_file.read()
+    with open(file_path) as test_file:
+        return test_file.read()
 
 
 def print_bugwatches(bug_watches, convert_remote_status=None):
@@ -303,9 +303,9 @@ class TestBugzilla(BugTrackerResponsesMixin, Bugzilla):
         url = urlsplit(request.url)
         if (url.path == urlsplit(self.baseurl).path + '/xml.cgi' and
                 parse_qs(url.query).get('id') == ['1']):
-            body = read_test_file(self.version_file)
+            body = read_test_file(self.version_file).encode('UTF-8')
             # Add some latin1 to test bug 61129
-            return 200, {}, body % {'non_ascii_latin1': b'\xe9'}
+            return 200, {}, body % {b'non_ascii_latin1': b'\xe9'}
         else:
             raise AssertionError('Unknown URL: %s' % request.url)
 
@@ -1670,11 +1670,11 @@ class TestDebBugsDB:
             raise debbugs.LogParseFailed(
                 'debbugs-log.pl exited with code 512')
 
-        with open(self.data_file) as f:
+        with open(self.data_file, 'rb') as f:
             comment_data = f.read()
         bug._emails = []
         bug.comments = [comment.strip() for comment in
-            comment_data.split('--\n')]
+            comment_data.split(b'--\n')]
 
 
 class TestDebBugs(DebBugs):