Merge "Remove six"

This commit is contained in:
Zuul 2020-05-15 06:36:04 +00:00 committed by Gerrit Code Review
commit 6dc88e69fd
11 changed files with 45 additions and 56 deletions

View File

@ -95,7 +95,6 @@ requestsexceptions==1.2.0
rfc3986==0.3.1
Routes==2.3.1
simplejson==3.5.1
six==1.10.0
smmap==0.9.0
snowballstemmer==1.2.1
Sphinx==1.6.5

View File

@ -36,7 +36,6 @@ Exception definitions.
import inspect
import sys
import six
from magnumclient.i18n import _
@ -456,7 +455,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

@ -20,8 +20,7 @@ Base utilities to build API operation managers and objects on top of.
"""
import copy
import six.moves.urllib.parse as urlparse
from urllib import parse as urlparse
from magnumclient.common.apiclient import base

View File

@ -29,8 +29,6 @@ from magnumclient.common.apiclient import exceptions
from oslo_utils import encodeutils
from oslo_utils import strutils
import prettytable
import six
from six import moves
from magnumclient.i18n import _
@ -301,10 +299,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):
@ -315,7 +310,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
@ -334,12 +329,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:
@ -355,10 +350,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):
@ -368,7 +360,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

@ -16,16 +16,17 @@
# under the License.
import copy
from http import client as http_client
import io
import logging
import os
import socket
import ssl
from urllib import parse as urlparse
from keystoneauth1 import adapter
from oslo_serialization import jsonutils
from oslo_utils import importutils
import six
import six.moves.urllib.parse as urlparse
from magnumclient import exceptions
@ -106,7 +107,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)
@ -207,7 +208,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)
@ -257,7 +258,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/
@ -266,7 +267,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

@ -31,7 +31,6 @@ import sys
from oslo_utils import encodeutils
from oslo_utils import importutils
from oslo_utils import strutils
import six
from magnumclient.common import cliutils
from magnumclient import exceptions as exc
@ -642,7 +641,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)

View File

@ -13,10 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
import io
from unittest import mock
from oslo_serialization import jsonutils
import six
import socket
from magnumclient.common.apiclient.exceptions import GatewayTimeout
@ -51,7 +52,7 @@ def _get_error_body(faultstring=None, debuginfo=None, err_type=NORMAL_ERROR):
return raw_body
HTTP_CLASS = six.moves.http_client.HTTPConnection
HTTP_CLASS = http_client.HTTPConnection
HTTPS_CLASS = http.VerifiedHTTPSConnection
DEFAULT_TIMEOUT = 600
@ -81,7 +82,7 @@ class HttpClientTest(utils.BaseTestCase):
def test_server_exception_empty_body(self):
error_body = _get_error_body()
fake_resp = utils.FakeResponse({'content-type': 'application/json'},
six.StringIO(error_body),
io.StringIO(error_body),
version=1,
status=500)
client = http.HTTPClient('http://localhost/')
@ -97,7 +98,7 @@ class HttpClientTest(utils.BaseTestCase):
error_msg = 'test error msg'
error_body = _get_error_body(error_msg, err_type=ERROR_DICT)
fake_resp = utils.FakeResponse({'content-type': 'application/json'},
six.StringIO(error_body),
io.StringIO(error_body),
version=1,
status=500)
client = http.HTTPClient('http://localhost/')
@ -116,7 +117,7 @@ class HttpClientTest(utils.BaseTestCase):
error_body = _get_error_body(error_msg, error_trace,
ERROR_LIST_WITH_DESC)
fake_resp = utils.FakeResponse({'content-type': 'application/json'},
six.StringIO(error_body),
io.StringIO(error_body),
version=1,
status=500)
client = http.HTTPClient('http://localhost/')
@ -270,7 +271,7 @@ class HttpClientTest(utils.BaseTestCase):
def test_401_unauthorized_exception(self):
error_body = _get_error_body(err_type=ERROR_LIST_WITH_DETAIL)
fake_resp = utils.FakeResponse({'content-type': 'text/plain'},
six.StringIO(error_body),
io.StringIO(error_body),
version=1,
status=401)
client = http.HTTPClient('http://localhost/')
@ -299,7 +300,7 @@ class HttpClientTest(utils.BaseTestCase):
err = "foo"
fake_resp = utils.FakeResponse(
{'content-type': 'application/json'},
six.StringIO(err), version=1, status=200)
io.StringIO(err), version=1, status=200)
client = http.HTTPClient('http://localhost/')
conn = utils.FakeConnection(fake_resp)
client.get_connection = (lambda *a, **kw: conn)
@ -325,7 +326,7 @@ class HttpClientTest(utils.BaseTestCase):
def test_server_success_body_none(self):
fake_resp = utils.FakeResponse(
{'content-type': None},
six.StringIO('bar'), version=1, status=200)
io.StringIO('bar'), version=1, status=200)
client = http.HTTPClient('http://localhost/')
conn = utils.FakeConnection(fake_resp)
client.get_connection = (lambda *a, **kw: conn)
@ -339,7 +340,7 @@ class HttpClientTest(utils.BaseTestCase):
err = _get_error_body()
fake_resp = utils.FakeResponse(
{'content-type': 'application/json'},
six.StringIO(err), version=1, status=200)
io.StringIO(err), version=1, status=200)
client = http.HTTPClient('http://localhost/')
conn = utils.FakeConnection(fake_resp)
client.get_connection = (lambda *a, **kw: conn)

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import re
import sys
from unittest import mock
@ -19,7 +20,6 @@ from unittest import mock
import argparse
import fixtures
from keystoneauth1 import fixture
import six
from testtools import matchers
from magnumclient import exceptions
@ -231,8 +231,8 @@ class ShellTest(utils.TestCase):
self.assertEqual(False, session_kwargs['verify'])
@mock.patch('sys.argv', ['magnum'])
@mock.patch('sys.stdout', six.StringIO())
@mock.patch('sys.stderr', six.StringIO())
@mock.patch('sys.stdout', io.StringIO())
@mock.patch('sys.stderr', io.StringIO())
def test_main_noargs(self):
# Ensure that main works with no command-line arguments
try:

View File

@ -15,12 +15,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import builtins
import collections
from unittest import mock
from oslo_serialization import jsonutils
import six
import six.moves.builtins as __builtin__
import tempfile
from magnumclient.common import cliutils
@ -220,10 +219,10 @@ class FormatLabelsTest(test_utils.BaseTestCase):
class CliUtilsTest(test_utils.BaseTestCase):
def test_keys_and_vals_to_strs(self):
dict_in = {six.u('a'): six.u('1'),
six.u('b'): {six.u('x'): 1,
'y': six.u('2'),
six.u('z'): six.u('3')},
dict_in = {'a': '1',
'b': {'x': 1,
'y': '2',
'z': '3'},
'c': 7}
dict_exp = collections.OrderedDict([
@ -240,7 +239,7 @@ class CliUtilsTest(test_utils.BaseTestCase):
('b', collections.OrderedDict(sorted(dict_out['b'].items()))),
('c', dict_out['c'])])
self.assertEqual(six.text_type(dict_exp), six.text_type(dict_act))
self.assertEqual(str(dict_exp), str(dict_act))
class HandleJsonFromFileTest(test_utils.BaseTestCase):
@ -264,7 +263,7 @@ class HandleJsonFromFileTest(test_utils.BaseTestCase):
self.assertEqual(jsonutils.loads(contents), steps)
@mock.patch.object(__builtin__, 'open', autospec=True)
@mock.patch.object(builtins, 'open', autospec=True)
def test_handle_json_from_file_open_fail(self, mock_open):
mock_file_object = mock.MagicMock()
mock_file_handle = mock.MagicMock()

View File

@ -15,12 +15,13 @@
import copy
import datetime
import io
import os
from oslo_serialization import jsonutils
import queue
import sys
import fixtures
import six
import testtools
from magnumclient.common import httpclient as http
@ -51,7 +52,7 @@ class FakeAPI(object):
def raw_request(self, *args, **kwargs):
response = self._request(*args, **kwargs)
body_iter = http.ResponseBodyIterator(six.StringIO(response[1]))
body_iter = http.ResponseBodyIterator(io.StringIO(response[1]))
return FakeResponse(response[0]), body_iter
def json_request(self, *args, **kwargs):
@ -61,7 +62,7 @@ class FakeAPI(object):
class FakeConnection(object):
def __init__(self, response=None, **kwargs):
self._response = six.moves.queue.Queue()
self._response = queue.Queue()
self._response.put(response)
self._last_request = None
self._exc = kwargs['exc'] if 'exc' in kwargs else None
@ -156,8 +157,8 @@ class TestCase(testtools.TestCase):
orig = sys.stdout
orig_stderr = sys.stderr
try:
sys.stdout = six.StringIO()
sys.stderr = six.StringIO()
sys.stdout = io.StringIO()
sys.stderr = io.StringIO()
_shell = shell.OpenStackMagnumShell()
_shell.main(argstr.split())
except SystemExit:

View File

@ -4,7 +4,6 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
Babel!=2.4.0,>=2.3.4 # BSD
six>=1.10.0 # MIT
keystoneauth1>=3.4.0 # Apache-2.0
stevedore>=1.20.0 # Apache-2.0
requests>=2.14.2 # Apache-2.0