[PATCH] D68797: [LNT] Python 3 support: Do not encode report for stdout

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 08:42:33 PDT 2019


thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.

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.


https://reviews.llvm.org/D68797

Files:
  lnt/lnttool/main.py


Index: lnt/lnttool/main.py
===================================================================
--- lnt/lnttool/main.py
+++ lnt/lnttool/main.py
@@ -270,7 +270,8 @@
             % (config.zorgURL, database, testsuite)
         subject = "Daily Report: %04d-%02d-%02d" % (
             report.year, report.month, report.day)
-        html_report = report.render(ts_url, only_html_body=False).encode('utf-8')
+        html_report = report.render(ts_url, only_html_body=False)
+        utf8_html_report = html_report.encode('utf-8')
 
         if subject_prefix is not None:
             subject = "%s %s" % (subject_prefix, subject)
@@ -280,7 +281,7 @@
         msg['Subject'] = subject
         msg['From'] = from_address
         msg['To'] = address
-        msg.attach(email.mime.text.MIMEText(html_report, 'html', 'utf-8'))
+        msg.attach(email.mime.text.MIMEText(utf8_html_report, 'html', 'utf-8'))
 
         # Send the report.
         if not dry_run:
@@ -355,9 +356,11 @@
 
         env = lnt.server.ui.app.create_jinja_environment()
         text_template = env.get_template('reporting/run_report.txt')
-        text_report = text_template.render(data).encode('utf-8')
+        text_report = text_template.render(data)
+        utf8_text_report = text_report.encode('utf-8')
         html_template = env.get_template('reporting/run_report.html')
-        html_report = html_template.render(data).encode('utf-8')
+        html_report = html_template.render(data)
+        utf8_html_report = html_report.encode('utf-8')
 
         subject = data['subject']
         if subject_prefix is not None:
@@ -368,8 +371,8 @@
         msg['Subject'] = subject
         msg['From'] = from_address
         msg['To'] = to_address
-        msg.attach(email.mime.text.MIMEText(text_report, 'plain', 'utf-8'))
-        msg.attach(email.mime.text.MIMEText(html_report, 'html', 'utf-8'))
+        msg.attach(email.mime.text.MIMEText(utf8_text_report, 'plain', 'utf-8'))
+        msg.attach(email.mime.text.MIMEText(utf8_html_report, 'html', 'utf-8'))
 
         # Send the report.
         if not dry_run:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68797.224362.patch
Type: text/x-patch
Size: 2098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/4e6e3c52/attachment.bin>


More information about the llvm-commits mailing list