Skip to content

Commit 1c1509a

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: Do not encode report for stdout
Summary: Daily report and run comparison are both output to stdout and sent by email as attachment. Under Python 3's strict separation between text and binary data the former needs to be done as a string while the latter needs to be an encoded text, i.e. as binary data. This commit implements that separation. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls, leandron, PrzemekWirkus Reviewed By: PrzemekWirkus Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D68797
1 parent b2e114b commit 1c1509a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lnt/lnttool/main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ def action_send_daily_report(instance_path, address, database, testsuite, host,
270270
% (config.zorgURL, database, testsuite)
271271
subject = "Daily Report: %04d-%02d-%02d" % (
272272
report.year, report.month, report.day)
273-
html_report = report.render(ts_url, only_html_body=False).encode('utf-8')
273+
html_report = report.render(ts_url, only_html_body=False)
274+
utf8_html_report = html_report.encode('utf-8')
274275

275276
if subject_prefix is not None:
276277
subject = "%s %s" % (subject_prefix, subject)
@@ -280,7 +281,7 @@ def action_send_daily_report(instance_path, address, database, testsuite, host,
280281
msg['Subject'] = subject
281282
msg['From'] = from_address
282283
msg['To'] = address
283-
msg.attach(email.mime.text.MIMEText(html_report, 'html', 'utf-8'))
284+
msg.attach(email.mime.text.MIMEText(utf8_html_report, 'html', 'utf-8'))
284285

285286
# Send the report.
286287
if not dry_run:
@@ -355,9 +356,11 @@ def action_send_run_comparison(instance_path, run_a_id, run_b_id, database,
355356

356357
env = lnt.server.ui.app.create_jinja_environment()
357358
text_template = env.get_template('reporting/run_report.txt')
358-
text_report = text_template.render(data).encode('utf-8')
359+
text_report = text_template.render(data)
360+
utf8_text_report = text_report.encode('utf-8')
359361
html_template = env.get_template('reporting/run_report.html')
360-
html_report = html_template.render(data).encode('utf-8')
362+
html_report = html_template.render(data)
363+
utf8_html_report = html_report.encode('utf-8')
361364

362365
subject = data['subject']
363366
if subject_prefix is not None:
@@ -368,8 +371,8 @@ def action_send_run_comparison(instance_path, run_a_id, run_b_id, database,
368371
msg['Subject'] = subject
369372
msg['From'] = from_address
370373
msg['To'] = to_address
371-
msg.attach(email.mime.text.MIMEText(text_report, 'plain', 'utf-8'))
372-
msg.attach(email.mime.text.MIMEText(html_report, 'html', 'utf-8'))
374+
msg.attach(email.mime.text.MIMEText(utf8_text_report, 'plain', 'utf-8'))
375+
msg.attach(email.mime.text.MIMEText(utf8_html_report, 'html', 'utf-8'))
373376

374377
# Send the report.
375378
if not dry_run:

0 commit comments

Comments
 (0)