Remove six lib

Change-Id: I7f278088722a3e0e0fd502be45337c485d9f282b
This commit is contained in:
tomas 2021-01-02 16:24:04 +08:00
parent 991e46c1c9
commit 290b6ed2bd
7 changed files with 27 additions and 34 deletions

View File

@ -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', '')

View File

@ -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

View File

@ -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)))
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()))
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: ")

View File

@ -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))

View File

@ -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,7 +256,7 @@ 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,
http_client.HTTPSConnection.__init__(self, host, port,
key_file=key_file,
cert_file=cert_file)
self.key_file = key_file

View File

@ -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', '')

View File

@ -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)