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
diff --git a/lib/lp/bugs/browser/bug.py b/lib/lp/bugs/browser/bug.py
index eedf9b4..b1909e7 100644
--- a/lib/lp/bugs/browser/bug.py
+++ b/lib/lp/bugs/browser/bug.py
@@ -105,6 +105,7 @@ from lp.bugs.model.structuralsubscription import (
105 get_structural_subscriptions_for_bug,105 get_structural_subscriptions_for_bug,
106 )106 )
107from lp.registry.interfaces.person import IPersonSet107from lp.registry.interfaces.person import IPersonSet
108from lp.services.compat import message_as_bytes
108from lp.services.features import getFeatureFlag109from lp.services.features import getFeatureFlag
109from lp.services.fields import DuplicateBug110from lp.services.fields import DuplicateBug
110from lp.services.librarian.browser import ProxiedLibraryFileAlias111from lp.services.librarian.browser import ProxiedLibraryFileAlias
@@ -1163,13 +1164,12 @@ class BugTextView(LaunchpadView):
11631164
1164 for comment in comments:1165 for comment in comments:
1165 message = build_message(comment.text_for_display)1166 message = build_message(comment.text_for_display)
1166 message['Author'] = comment.owner.unique_displayname.encode(1167 message['Author'] = comment.owner.unique_displayname
1167 'utf-8')
1168 message['Date'] = format_rfc2822_date(comment.datecreated)1168 message['Date'] = format_rfc2822_date(comment.datecreated)
1169 message['Message-Id'] = comment.rfc822msgid1169 message['Message-Id'] = comment.rfc822msgid
1170 comment_mime.attach(message)1170 comment_mime.attach(message)
11711171
1172 return comment_mime.as_string().decode('utf-8')1172 return message_as_bytes(comment_mime).decode('utf-8')
11731173
1174 def render(self):1174 def render(self):
1175 """Return a text representation of the bug."""1175 """Return a text representation of the bug."""
diff --git a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
index 6d16ca2..aedbffd 100644
--- a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
+++ b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
@@ -95,7 +95,7 @@ all tasks related to that bug, presented in an easy-to-digest format:
95 date-left-closed: ...95 date-left-closed: ...
96 reporter: Sample Person (name12)96 reporter: Sample Person (name12)
97 importance: Low97 importance: Low
98 assignee: M...rk Sh...ttlew...rth (mark)98 assignee: Márk Shúttlewòrth (mark)
99 milestone: 99 milestone:
100 <BLANKLINE>100 <BLANKLINE>
101 task: mozilla-firefox (Ubuntu)101 task: mozilla-firefox (Ubuntu)
@@ -119,31 +119,6 @@ all tasks related to that bug, presented in an easy-to-digest format:
119 milestone: 119 milestone:
120 <BLANKLINE>120 <BLANKLINE>
121 Content-Type: multipart/mixed; boundary="...121 Content-Type: multipart/mixed; boundary="...
122 MIME-Version: 1.0
123 <BLANKLINE>
124 --...
125 Content-Type: text/plain; charset="utf-8"
126 Content-Transfer-Encoding: quoted-printable
127 <BLANKLINE>
128 Firefox needs to support embedded SVG images, now that the standard has
129 been finalised.
130 <BLANKLINE>
131 The SVG standard 1.0 is complete, and draft implementations for Firefox
132 exist. One of these implementations needs to be integrated with the base
133 install of Firefox. Ideally, the implementation needs to include support
134 for the manipulation of SVG objects from JavaScript to enable interactive
135 and dynamic SVG drawings.
136 --...
137 ...
138 --...
139 Content-Type: text/plain; charset="utf-8"
140 Content-Transfer-Encoding: quoted-printable
141 Author: ... (mark)
142 Date: ...
143 Message-Id: ...
144 <BLANKLINE>
145 comment for file with space
146 --...
147122
148The multiple white spaces in the mime type of the second attachment123The multiple white spaces in the mime type of the second attachment
149are replaced by a single space.124are replaced by a single space.
@@ -154,6 +129,43 @@ are replaced by a single space.
154 ' http://bugs.launchpad.test/.../file%20with%20space.txt text/plain;129 ' http://bugs.launchpad.test/.../file%20with%20space.txt text/plain;
155 name="file with space.txt"'130 name="file with space.txt"'
156131
132The comments are represented as a MIME message.
133
134 >>> import email
135 >>> from email.header import decode_header
136 >>> comments = email.message_from_string(
137 ... text_bug[text_bug.find('Content-Type:'):]).get_payload()
138
139 >>> print(comments[0]['Content-Type'])
140 text/plain; charset="utf-8"
141 >>> 'Author' in comments[0]
142 False
143 >>> 'Date' in comments[0]
144 False
145 >>> 'Message-Id' in comments[0]
146 False
147 >>> print(comments[0].get_payload())
148 Firefox needs to support embedded SVG images, now that the standard has
149 been finalised.
150 <BLANKLINE>
151 The SVG standard 1.0 is complete, and draft implementations for Firefox
152 exist. One of these implementations needs to be integrated with the base
153 install of Firefox. Ideally, the implementation needs to include support
154 for the manipulation of SVG objects from JavaScript to enable interactive
155 and dynamic SVG drawings.
156
157 >>> print(comments[3]['Content-Type'])
158 text/plain; charset="utf-8"
159 >>> [(author_bytes, author_charset)] = decode_header(comments[3]['Author'])
160 >>> print(author_bytes.decode(author_charset))
161 Márk Shúttlewòrth (mark)
162 >>> 'Date' in comments[3]
163 True
164 >>> 'Message-Id' in comments[3]
165 True
166 >>> print(comments[3].get_payload())
167 comment for file with space
168
157169
158== Text Pages from a Bug Task Context ==170== Text Pages from a Bug Task Context ==
159171

Subscribers

People subscribed via source and target branches

to status/vote changes: