releasetools: Fix the use of StringIO.

Based on the actual semantics, it actually wants an in-memory _bytes_
buffer (io.BytesIO), especially when running with Python 3. This CL
fixes the issue and adds a unittest.

Bug: 131631303
Test: python -m unittest test_sign_target_files_apks
Test: python3 -m unittest test_sign_target_files_apks
Change-Id: I3fb067acc26713f1842e831225607779fd0d1b7e
This commit is contained in:
Tao Bao
2019-07-24 23:31:19 -07:00
parent 6722de1277
commit bb73388acf
2 changed files with 20 additions and 7 deletions

View File

@@ -111,6 +111,7 @@ import base64
import copy
import errno
import gzip
import io
import itertools
import logging
import os
@@ -746,12 +747,7 @@ def WriteOtacerts(output_zip, filename, keys):
filename: The archive name in the output zip.
keys: A list of public keys to use during OTA package verification.
"""
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
temp_file = StringIO()
temp_file = io.BytesIO()
certs_zip = zipfile.ZipFile(temp_file, "w")
for k in keys:
common.ZipWrite(certs_zip, k)