From: Eric Ball Date: Fri, 7 Jun 2019 13:59:20 +0000 (-0700) Subject: Use six.text_type rather than str.encode('utf-8') X-Git-Tag: v0.25.0~6^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=e99dca16eef12f2e09c7911cc145ed637f9584bc;p=releng%2Flftools.git Use six.text_type rather than str.encode('utf-8') 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 --- diff --git a/lftools/deploy.py b/lftools/deploy.py index 62665906..09099b9e 100644 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -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 index 00000000..4c9f2aa8 --- /dev/null +++ b/releasenotes/notes/no-encode-py3-44307e6fd97c2d0c.yaml @@ -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.