From 290b6ed2bd665f0663b8ecf78d3e2d41c5f2a952 Mon Sep 17 00:00:00 2001 From: tomas Date: Sat, 2 Jan 2021 16:24:04 +0800 Subject: [PATCH] Remove six lib Change-Id: I7f278088722a3e0e0fd502be45337c485d9f282b --- cyborgclient/common/apiclient/exceptions.py | 3 +-- cyborgclient/common/base.py | 2 +- cyborgclient/common/cliutils.py | 23 +++++++-------------- cyborgclient/common/http.py | 5 ++--- cyborgclient/common/httpclient.py | 18 +++++++++------- cyborgclient/exceptions.py | 6 +++--- cyborgclient/shell.py | 4 ++-- 7 files changed, 27 insertions(+), 34 deletions(-) diff --git a/cyborgclient/common/apiclient/exceptions.py b/cyborgclient/common/apiclient/exceptions.py index 47231a2..139476d 100644 --- a/cyborgclient/common/apiclient/exceptions.py +++ b/cyborgclient/common/apiclient/exceptions.py @@ -24,7 +24,6 @@ Exception definitions. import inspect import sys -import six from cyborgclient.i18n import _ @@ -444,7 +443,7 @@ def from_response(response, method, url): kwargs["message"] = (error.get("message") or error.get("faultstring")) kwargs["details"] = (error.get("details") or - six.text_type(body)) + str(body)) elif content_type.startswith("text/"): kwargs["details"] = getattr(response, 'text', '') diff --git a/cyborgclient/common/base.py b/cyborgclient/common/base.py index 72ecb54..6c87784 100644 --- a/cyborgclient/common/base.py +++ b/cyborgclient/common/base.py @@ -21,7 +21,7 @@ Base utilities to build API operation managers and objects on top of. import copy -import six.moves.urllib.parse as urlparse +import urllib.parse as urlparse from cyborgclient.common.apiclient import base diff --git a/cyborgclient/common/cliutils.py b/cyborgclient/common/cliutils.py index 2472ddb..0ac7693 100644 --- a/cyborgclient/common/cliutils.py +++ b/cyborgclient/common/cliutils.py @@ -26,8 +26,7 @@ import decorator from oslo_utils import encodeutils from oslo_utils import strutils import prettytable -import six -from six import moves + from cyborgclient.common.apiclient import exceptions from cyborgclient.i18n import _ @@ -299,10 +298,7 @@ def print_list(objs, fields, formatters=None, sortby_index=0, row.append(data) pt.add_row(row) - if six.PY3: - print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode()) - else: - print(encodeutils.safe_encode(pt.get_string(**kwargs))) + print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode()) def keys_and_vals_to_strs(dictionary): @@ -313,7 +309,7 @@ def keys_and_vals_to_strs(dictionary): def to_str(k_or_v): if isinstance(k_or_v, dict): return keys_and_vals_to_strs(k_or_v) - elif isinstance(k_or_v, six.text_type): + elif isinstance(k_or_v, str): return str(k_or_v) else: return k_or_v @@ -332,12 +328,12 @@ def print_dict(dct, dict_property="Property", wrap=0): for k, v in dct.items(): # convert dict to str to check length if isinstance(v, dict): - v = six.text_type(keys_and_vals_to_strs(v)) + v = str(keys_and_vals_to_strs(v)) if wrap > 0: - v = textwrap.fill(six.text_type(v), wrap) + v = textwrap.fill(str(v), wrap) # if value has a newline, add in multiple rows # e.g. fault with stacktrace - if v and isinstance(v, six.string_types) and r'\n' in v: + if v and isinstance(v, str) and r'\n' in v: lines = v.strip().split(r'\n') col1 = k for line in lines: @@ -353,10 +349,7 @@ def print_dict(dct, dict_property="Property", wrap=0): v = '-' pt.add_row([k, v]) - if six.PY3: - print(encodeutils.safe_encode(pt.get_string()).decode()) - else: - print(encodeutils.safe_encode(pt.get_string())) + print(encodeutils.safe_encode(pt.get_string()).decode()) def get_password(max_password_prompts=3): @@ -366,7 +359,7 @@ def get_password(max_password_prompts=3): if hasattr(sys.stdin, "isatty") and sys.stdin.isatty(): # Check for Ctrl-D try: - for __ in moves.range(max_password_prompts): + for __ in range(max_password_prompts): pw1 = getpass.getpass("OS Password: ") if verify: pw2 = getpass.getpass("Please verify: ") diff --git a/cyborgclient/common/http.py b/cyborgclient/common/http.py index c12d127..ceac173 100644 --- a/cyborgclient/common/http.py +++ b/cyborgclient/common/http.py @@ -24,8 +24,7 @@ from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import importutils import requests -import six -from six.moves.urllib import parse +from urllib import parse from cyborgclient.common import exceptions as exc from cyborgclient.common import utils @@ -137,7 +136,7 @@ class HTTPClient(object): dump.append('') if resp.content: content = resp.content - if isinstance(content, six.binary_type): + if isinstance(content, bytes): content = content.decode() dump.extend([content, '']) LOG.debug('\n'.join(dump)) diff --git a/cyborgclient/common/httpclient.py b/cyborgclient/common/httpclient.py index 3115b7f..fd57ced 100644 --- a/cyborgclient/common/httpclient.py +++ b/cyborgclient/common/httpclient.py @@ -16,16 +16,18 @@ # under the License. import copy +import io import json import logging import os import socket import ssl +import urllib.parse as urlparse +from http import client as http_client from keystoneauth1 import adapter from oslo_utils import importutils -import six -import six.moves.urllib.parse as urlparse + from cyborgclient import exceptions @@ -93,7 +95,7 @@ class HTTPClient(object): _kwargs['key_file'] = kwargs.get('key_file', None) _kwargs['insecure'] = kwargs.get('insecure', False) elif parts.scheme == 'http': - _class = six.moves.http_client.HTTPConnection + _class = http_client.HTTPConnection else: msg = 'Unsupported scheme: %s' % parts.scheme raise exceptions.EndpointException(msg) @@ -194,7 +196,7 @@ class HTTPClient(object): ] body_str = ''.join(body_list) self.log_http_response(resp, body_str) - body_iter = six.StringIO(body_str) + body_iter = io.StringIO(body_str) else: self.log_http_response(resp) @@ -245,7 +247,7 @@ class HTTPClient(object): return self._http_request(url, method, **kwargs) -class VerifiedHTTPSConnection(six.moves.http_client.HTTPSConnection): +class VerifiedHTTPSConnection(http_client.HTTPSConnection): """httplib-compatibile connection using client-side SSL authentication :see http://code.activestate.com/recipes/ @@ -254,9 +256,9 @@ class VerifiedHTTPSConnection(six.moves.http_client.HTTPSConnection): def __init__(self, host, port, key_file=None, cert_file=None, ca_file=None, timeout=None, insecure=False): - six.moves.http_client.HTTPSConnection.__init__(self, host, port, - key_file=key_file, - cert_file=cert_file) + http_client.HTTPSConnection.__init__(self, host, port, + key_file=key_file, + cert_file=cert_file) self.key_file = key_file self.cert_file = cert_file if ca_file is not None: diff --git a/cyborgclient/exceptions.py b/cyborgclient/exceptions.py index 72f9268..dd0ae31 100644 --- a/cyborgclient/exceptions.py +++ b/cyborgclient/exceptions.py @@ -17,7 +17,7 @@ import inspect import sys from oslo_serialization import jsonutils -import six + from cyborgclient.i18n import _ @@ -491,14 +491,14 @@ def from_response(response, method, url, message=None, traceback=None): # {u'error_message': u'{"debuginfo": null, "faultcode": # "Client", "faultstring": "error message"}'}, the # "error_message" in the body is also a json string. - if isinstance(error, six.string_types): + if isinstance(error, str): error = jsonutils.loads(error) if hasattr(error, 'keys'): kwargs['message'] = (error.get('message') or error.get('faultstring')) kwargs['details'] = (error.get('details') or - six.text_type(body)) + str(body)) elif content_type.startswith("text/"): kwargs["details"] = getattr(response, 'text', '') diff --git a/cyborgclient/shell.py b/cyborgclient/shell.py index 72ebec9..0d74308 100644 --- a/cyborgclient/shell.py +++ b/cyborgclient/shell.py @@ -30,7 +30,7 @@ import sys from oslo_utils import encodeutils from oslo_utils import importutils from oslo_utils import strutils -import six + profiler = importutils.try_import("osprofiler.profiler") @@ -638,7 +638,7 @@ def main(): except Exception as e: logger.debug(e, exc_info=1) - print("ERROR: %s" % encodeutils.safe_encode(six.text_type(e)), + print("ERROR: %s" % encodeutils.safe_encode(str(e)), file=sys.stderr) sys.exit(1)