aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchojoyce <chojoyce@google.com>2022-04-13 10:41:36 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-13 10:41:36 +0000
commitf5d75f9e4b602833370b75628d8f00db8fadd2c3 (patch)
treebe4f97439e0d7a2aa188cb6328e8128a25718c42
parentb3f40f6fa57a19dd9d3d3e636db68d60b6f02166 (diff)
parente5176eb297fb7fc0e08d0cd9c35eddda9fc75bc3 (diff)
downloadacloud-f5d75f9e4b602833370b75628d8f00db8fadd2c3.tar.gz
Remove py-six dependencies from utils. am: b54c5e6a60 am: e5176eb297
Original change: https://android-review.googlesource.com/c/platform/tools/acloud/+/2019233 Change-Id: I419577e3327e733e3d23da95214693b33809f9d0 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-xinternal/lib/utils.py18
-rw-r--r--internal/lib/utils_test.py5
2 files changed, 9 insertions, 14 deletions
diff --git a/internal/lib/utils.py b/internal/lib/utils.py
index cf501128..0295b292 100755
--- a/internal/lib/utils.py
+++ b/internal/lib/utils.py
@@ -40,8 +40,6 @@ import uuid
import webbrowser
import zipfile
-import six
-
from acloud import errors
from acloud.internal import constants
@@ -330,7 +328,7 @@ def MakeTarFile(src_dict, dest):
"""
logger.info("Compressing %s into %s.", src_dict.keys(), dest)
with tarfile.open(dest, "w:gz") as tar:
- for src, arcname in six.iteritems(src_dict):
+ for src, arcname in src_dict.items():
tar.add(src, arcname=arcname)
def CreateSshKeyPairIfNotExist(private_key_path, public_key_path):
@@ -427,7 +425,7 @@ def VerifyRsaPubKey(rsa):
key_type, data, _ = elements
try:
- binary_data = base64.decodebytes(six.b(data))
+ binary_data = base64.decodebytes(data.encode())
# number of bytes of int type
int_length = 4
# binary_data is like "7ssh-key..." in a binary format.
@@ -437,7 +435,7 @@ def VerifyRsaPubKey(rsa):
# We will verify that the rsa conforms to this format.
# ">I" in the following line means "big-endian unsigned integer".
type_length = struct.unpack(">I", binary_data[:int_length])[0]
- if binary_data[int_length:int_length + type_length] != six.b(key_type):
+ if binary_data[int_length:int_length + type_length] != key_type.encode():
raise errors.DriverError("rsa key is invalid: %s" % rsa)
except (struct.error, binascii.Error) as e:
raise errors.DriverError(
@@ -514,7 +512,7 @@ def InteractWithQuestion(question, colors=TextColors.WARNING):
Returns:
String, input from user.
"""
- return str(six.moves.input(colors + question + TextColors.ENDC).strip())
+ return str(input(colors + question + TextColors.ENDC).strip())
def GetUserAnswerYes(question):
@@ -602,7 +600,7 @@ class BatchHttpRequestExecutor:
self._final_results.update(results)
# Clear pending_requests
self._pending_requests.clear()
- for request_id, result in six.iteritems(results):
+ for request_id, result in results.items():
exception = result[1]
if exception is not None and self._ShoudRetry(exception):
# If this is a retriable exception, put it in pending_requests
@@ -1037,7 +1035,7 @@ def GetAnswerFromList(answer_list, enable_choose_all=False):
while True:
try:
- choice = six.moves.input("Enter your choice[0-%d]: " % max_choice)
+ choice = input("Enter your choice[0-%d]: " % max_choice)
choice = int(choice)
except ValueError:
print("'%s' is not a valid integer.", choice)
@@ -1471,11 +1469,9 @@ def GetDictItems(namedtuple_object):
namedtuple_object: namedtuple object.
Returns:
- collections.namedtuple.__dict__.items() when using python2.
collections.namedtuple._asdict().items() when using python3.
"""
- return (namedtuple_object.__dict__.items() if six.PY2
- else namedtuple_object._asdict().items())
+ return namedtuple_object._asdict().items()
def CleanupSSVncviewer(vnc_port):
diff --git a/internal/lib/utils_test.py b/internal/lib/utils_test.py
index ed5bf4a2..ccbca330 100644
--- a/internal/lib/utils_test.py
+++ b/internal/lib/utils_test.py
@@ -29,7 +29,6 @@ import webbrowser
import unittest
from unittest import mock
-import six
from acloud import errors
from acloud.internal.lib import driver_test_lib
@@ -191,7 +190,7 @@ class UtilsTest(driver_test_lib.BaseDriverTest):
mock_open = mock.mock_open(read_data=public_key)
self.Patch(subprocess, "check_output")
self.Patch(os, "rename")
- with mock.patch.object(six.moves.builtins, "open", mock_open):
+ with mock.patch("builtins.open", mock_open):
utils.CreateSshKeyPairIfNotExist(private_key, public_key)
self.assertEqual(subprocess.check_output.call_count, 1) #pylint: disable=no-member
subprocess.check_output.assert_called_with( #pylint: disable=no-member
@@ -262,7 +261,7 @@ class UtilsTest(driver_test_lib.BaseDriverTest):
mock.call(16)
])
- @mock.patch.object(six.moves, "input")
+ @mock.patch("builtins.input")
def testGetAnswerFromList(self, mock_raw_input):
"""Test GetAnswerFromList."""
answer_list = ["image1.zip", "image2.zip", "image3.zip"]