Use six.text_type rather than str.encode('utf-8') 40/15840/3
authorEric Ball <eball@linuxfoundation.org>
Fri, 7 Jun 2019 13:59:20 +0000 (06:59 -0700)
committerEric Ball <eball@linuxfoundation.org>
Tue, 11 Jun 2019 00:41:37 +0000 (17:41 -0700)
Encoding the string in Python 3 results in a bytes object rather
than str. To avoid this, use six.text_type method, which is designed
to safely perform this function in Python 2 and 3.

Change-Id: Ice7f02f4c02fd71d115af627d5b15622cd04d35d
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
lftools/deploy.py
releasenotes/notes/no-encode-py3-44307e6fd97c2d0c.yaml [new file with mode: 0644]

index 6266590..09099b9 100644 (file)
@@ -28,6 +28,7 @@ import zipfile
 from defusedxml.minidom import parseString
 import glob2  # Switch to glob when Python < 3.5 support is dropped
 import requests
+import six
 
 log = logging.getLogger(__name__)
 
@@ -307,11 +308,11 @@ def deploy_logs(nexus_url, nexus_path, build_url):
 
     resp = requests.get('{}/consoleText'.format(_format_url(build_url)))
     with open('console.log', 'w+') as f:
-        f.write(str(resp.text.split(MAGIC_STRING)[0].encode('utf-8')))
+        f.write(str(six.text_type(resp.text.split(MAGIC_STRING)[0])))
 
     resp = requests.get('{}/timestamps?time=HH:mm:ss&appendLog'.format(_format_url(build_url)))
     with open('console-timestamp.log', 'w+') as f:
-        f.write(str(resp.text.split(MAGIC_STRING)[0].encode('utf-8')))
+        f.write(str(six.text_type(resp.text.split(MAGIC_STRING)[0])))
 
     _compress_text(work_dir)
 
diff --git a/releasenotes/notes/no-encode-py3-44307e6fd97c2d0c.yaml b/releasenotes/notes/no-encode-py3-44307e6fd97c2d0c.yaml
new file mode 100644 (file)
index 0000000..4c9f2aa
--- /dev/null
@@ -0,0 +1,5 @@
+---
+fixes:
+  - |
+    Use six.text_type() rather than str.encode('utf-8') in deploy_logs, so that
+    strings are no longer rewritten as bytes objects in Python 3.