Merge ~cjwatson/launchpad:py3-bug-text into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c98a25e8ad50684aef87262f0076693e1bc9cf49
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-bug-text
Merge into: launchpad:master
Diff against target: 116 lines (+41/-29)
2 files modified
lib/lp/bugs/browser/bug.py (+3/-3)
lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt (+38/-26)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398810@code.launchpad.net

Commit message

Fix Bug:+text for Python 3

Description of the change

After converting BugTextView to message_as_bytes, we still find that Python 3 encodes email headers slightly differently, causing xx-bug-text-pages.txt to fail; so also rearrange the test to parse the comments as an email message and test the bits of them that we care about.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/browser/bug.py b/lib/lp/bugs/browser/bug.py
2index eedf9b4..b1909e7 100644
3--- a/lib/lp/bugs/browser/bug.py
4+++ b/lib/lp/bugs/browser/bug.py
5@@ -105,6 +105,7 @@ from lp.bugs.model.structuralsubscription import (
6 get_structural_subscriptions_for_bug,
7 )
8 from lp.registry.interfaces.person import IPersonSet
9+from lp.services.compat import message_as_bytes
10 from lp.services.features import getFeatureFlag
11 from lp.services.fields import DuplicateBug
12 from lp.services.librarian.browser import ProxiedLibraryFileAlias
13@@ -1163,13 +1164,12 @@ class BugTextView(LaunchpadView):
14
15 for comment in comments:
16 message = build_message(comment.text_for_display)
17- message['Author'] = comment.owner.unique_displayname.encode(
18- 'utf-8')
19+ message['Author'] = comment.owner.unique_displayname
20 message['Date'] = format_rfc2822_date(comment.datecreated)
21 message['Message-Id'] = comment.rfc822msgid
22 comment_mime.attach(message)
23
24- return comment_mime.as_string().decode('utf-8')
25+ return message_as_bytes(comment_mime).decode('utf-8')
26
27 def render(self):
28 """Return a text representation of the bug."""
29diff --git a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
30index 6d16ca2..aedbffd 100644
31--- a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
32+++ b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
33@@ -95,7 +95,7 @@ all tasks related to that bug, presented in an easy-to-digest format:
34 date-left-closed: ...
35 reporter: Sample Person (name12)
36 importance: Low
37- assignee: M...rk Sh...ttlew...rth (mark)
38+ assignee: Márk Shúttlewòrth (mark)
39 milestone:
40 <BLANKLINE>
41 task: mozilla-firefox (Ubuntu)
42@@ -119,31 +119,6 @@ all tasks related to that bug, presented in an easy-to-digest format:
43 milestone:
44 <BLANKLINE>
45 Content-Type: multipart/mixed; boundary="...
46- MIME-Version: 1.0
47- <BLANKLINE>
48- --...
49- Content-Type: text/plain; charset="utf-8"
50- Content-Transfer-Encoding: quoted-printable
51- <BLANKLINE>
52- Firefox needs to support embedded SVG images, now that the standard has
53- been finalised.
54- <BLANKLINE>
55- The SVG standard 1.0 is complete, and draft implementations for Firefox
56- exist. One of these implementations needs to be integrated with the base
57- install of Firefox. Ideally, the implementation needs to include support
58- for the manipulation of SVG objects from JavaScript to enable interactive
59- and dynamic SVG drawings.
60- --...
61- ...
62- --...
63- Content-Type: text/plain; charset="utf-8"
64- Content-Transfer-Encoding: quoted-printable
65- Author: ... (mark)
66- Date: ...
67- Message-Id: ...
68- <BLANKLINE>
69- comment for file with space
70- --...
71
72 The multiple white spaces in the mime type of the second attachment
73 are replaced by a single space.
74@@ -154,6 +129,43 @@ are replaced by a single space.
75 ' http://bugs.launchpad.test/.../file%20with%20space.txt text/plain;
76 name="file with space.txt"'
77
78+The comments are represented as a MIME message.
79+
80+ >>> import email
81+ >>> from email.header import decode_header
82+ >>> comments = email.message_from_string(
83+ ... text_bug[text_bug.find('Content-Type:'):]).get_payload()
84+
85+ >>> print(comments[0]['Content-Type'])
86+ text/plain; charset="utf-8"
87+ >>> 'Author' in comments[0]
88+ False
89+ >>> 'Date' in comments[0]
90+ False
91+ >>> 'Message-Id' in comments[0]
92+ False
93+ >>> print(comments[0].get_payload())
94+ Firefox needs to support embedded SVG images, now that the standard has
95+ been finalised.
96+ <BLANKLINE>
97+ The SVG standard 1.0 is complete, and draft implementations for Firefox
98+ exist. One of these implementations needs to be integrated with the base
99+ install of Firefox. Ideally, the implementation needs to include support
100+ for the manipulation of SVG objects from JavaScript to enable interactive
101+ and dynamic SVG drawings.
102+
103+ >>> print(comments[3]['Content-Type'])
104+ text/plain; charset="utf-8"
105+ >>> [(author_bytes, author_charset)] = decode_header(comments[3]['Author'])
106+ >>> print(author_bytes.decode(author_charset))
107+ Márk Shúttlewòrth (mark)
108+ >>> 'Date' in comments[3]
109+ True
110+ >>> 'Message-Id' in comments[3]
111+ True
112+ >>> print(comments[3].get_payload())
113+ comment for file with space
114+
115
116 == Text Pages from a Bug Task Context ==
117

Subscribers

People subscribed via source and target branches

to status/vote changes: