Remove six

This library no longer supports Python 2, thus usage of six can be
removed.

Change-Id: I8d0c1cfd6dff375b3b7756a5b36c95a2df3f04c6
This commit is contained in:
Takashi Kajinami 2022-05-09 14:48:19 +09:00
parent a12456c17c
commit 23e647539c
39 changed files with 180 additions and 229 deletions

View File

@ -24,8 +24,7 @@ import copy
from oslo_utils import reflection from oslo_utils import reflection
from oslo_utils import strutils from oslo_utils import strutils
import six from urllib import parse
from six.moves.urllib import parse
from heatclient._i18n import _ from heatclient._i18n import _
from heatclient import exc as exceptions from heatclient import exc as exceptions
@ -207,8 +206,7 @@ class BaseManager(HookableMixin):
return self.client.delete(url) return self.client.delete(url)
@six.add_metaclass(abc.ABCMeta) class ManagerWithFind(BaseManager, metaclass=abc.ABCMeta):
class ManagerWithFind(BaseManager):
"""Manager with additional `find()`/`findall()` methods.""" """Manager with additional `find()`/`findall()` methods."""
@abc.abstractmethod @abc.abstractmethod

View File

@ -13,10 +13,9 @@
import copy import copy
import uuid import uuid
import six
from six.moves.urllib import parse as urlparse
from swiftclient import client as sc from swiftclient import client as sc
from swiftclient import utils as swiftclient_utils from swiftclient import utils as swiftclient_utils
from urllib import parse as urlparse
from heatclient._i18n import _ from heatclient._i18n import _
from heatclient import exc from heatclient import exc
@ -102,7 +101,7 @@ def create_temp_url(swift_client, name, timeout, container=None):
key_header = 'x-account-meta-temp-url-key' key_header = 'x-account-meta-temp-url-key'
if key_header not in swift_client.head_account(): if key_header not in swift_client.head_account():
swift_client.post_account({ swift_client.post_account({
key_header: six.text_type(uuid.uuid4())[:32]}) key_header: str(uuid.uuid4())[:32]})
key = swift_client.head_account()[key_header] key = swift_client.head_account()[key_header]
project_path = swift_client.url.split('/')[-1] project_path = swift_client.url.split('/')[-1]

View File

@ -15,7 +15,6 @@
import sys import sys
from osc_lib.command import command from osc_lib.command import command
import six
class RawFormat(command.ShowOne): class RawFormat(command.ShowOne):
@ -63,7 +62,7 @@ def indent_and_truncate(txt, spaces=0, truncate=False, truncate_limit=10,
""" """
if txt is None: if txt is None:
return return
lines = six.text_type(txt).splitlines() lines = str(txt).splitlines()
if truncate and len(lines) > truncate_limit: if truncate and len(lines) > truncate_limit:
lines = lines[-truncate_limit:] lines = lines[-truncate_limit:]
if truncate_prefix is not None: if truncate_prefix is not None:

View File

@ -24,8 +24,7 @@ from oslo_serialization import jsonutils
from oslo_utils import encodeutils from oslo_utils import encodeutils
from oslo_utils import importutils from oslo_utils import importutils
import requests import requests
import six from urllib import parse
from six.moves.urllib import parse
from heatclient._i18n import _ from heatclient._i18n import _
from heatclient.common import utils from heatclient.common import utils
@ -151,7 +150,7 @@ class HTTPClient(object):
dump.append('') dump.append('')
if resp.content: if resp.content:
content = resp.content content = resp.content
if isinstance(content, six.binary_type): if isinstance(content, bytes):
content = content.decode() content = content.decode()
dump.extend([content, '']) dump.extend([content, ''])
LOG.debug('\n'.join(dump)) LOG.debug('\n'.join(dump))

View File

@ -15,10 +15,9 @@
from collections import abc from collections import abc
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six from urllib import error
from six.moves.urllib import error from urllib import parse
from six.moves.urllib import parse from urllib import request
from six.moves.urllib import request
from heatclient._i18n import _ from heatclient._i18n import _
from heatclient.common import environment_format from heatclient.common import environment_format
@ -92,7 +91,7 @@ def get_template_contents(template_file=None, template_url=None,
% template_url) % template_url)
try: try:
if isinstance(tpl, six.binary_type): if isinstance(tpl, bytes):
tpl = tpl.decode('utf-8') tpl = tpl.decode('utf-8')
template = template_format.parse(tpl) template = template_format.parse(tpl)
except ValueError as e: except ValueError as e:
@ -114,7 +113,7 @@ def resolve_template_get_files(template, files, template_base_url,
def ignore_if(key, value): def ignore_if(key, value):
if key != 'get_file' and key != 'type': if key != 'get_file' and key != 'type':
return True return True
if not isinstance(value, six.string_types): if not isinstance(value, str):
return True return True
if (key == 'type' and if (key == 'type' and
not value.endswith(('.yaml', '.template'))): not value.endswith(('.yaml', '.template'))):
@ -130,7 +129,7 @@ def resolve_template_get_files(template, files, template_base_url,
def is_template(file_content): def is_template(file_content):
try: try:
if isinstance(file_content, six.binary_type): if isinstance(file_content, bytes):
file_content = file_content.decode('utf-8') file_content = file_content.decode('utf-8')
template_format.parse(file_content) template_format.parse(file_content)
except (ValueError, TypeError): except (ValueError, TypeError):
@ -144,7 +143,7 @@ def get_file_contents(from_data, files, base_url=None,
if recurse_if and recurse_if(from_data): if recurse_if and recurse_if(from_data):
if isinstance(from_data, dict): if isinstance(from_data, dict):
recurse_data = six.itervalues(from_data) recurse_data = from_data.values()
else: else:
recurse_data = from_data recurse_data = from_data
for value in recurse_data: for value in recurse_data:

View File

@ -22,10 +22,9 @@ import uuid
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import encodeutils from oslo_utils import encodeutils
import prettytable import prettytable
import six from urllib import error
from six.moves.urllib import error from urllib import parse
from six.moves.urllib import parse from urllib import request
from six.moves.urllib import request
import yaml import yaml
from heatclient._i18n import _ from heatclient._i18n import _
@ -123,10 +122,7 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
row.append(data) row.append(data)
pt.add_row(row) pt.add_row(row)
if six.PY3: print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode())
print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode())
else:
print(encodeutils.safe_encode(pt.get_string(**kwargs)))
def link_formatter(links): def link_formatter(links):
@ -286,10 +282,7 @@ def print_update_list(lst, fields, formatters=None):
pt.add_row(row) pt.add_row(row)
if six.PY3: print(encodeutils.safe_encode(pt.get_string()).decode())
print(encodeutils.safe_encode(pt.get_string()).decode())
else:
print(encodeutils.safe_encode(pt.get_string()))
def find_resource(manager, name_or_id): def find_resource(manager, name_or_id):

View File

@ -17,7 +17,6 @@ import logging
from osc_lib.command import command from osc_lib.command import command
from osc_lib import utils from osc_lib import utils
import six
from heatclient.common import utils as heat_utils from heatclient.common import utils as heat_utils
@ -41,6 +40,6 @@ class BuildInfo(command.ShowOne):
'api': heat_utils.json_formatter, 'api': heat_utils.json_formatter,
'engine': heat_utils.json_formatter, 'engine': heat_utils.json_formatter,
} }
columns = sorted(list(six.iterkeys(result))) columns = sorted(list(result.keys()))
return columns, utils.get_dict_properties(result, columns, return columns, utils.get_dict_properties(result, columns,
formatters=formatters) formatters=formatters)

View File

@ -20,8 +20,7 @@ from osc_lib import exceptions as exc
from osc_lib.i18n import _ from osc_lib.i18n import _
from osc_lib import utils from osc_lib import utils
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six from urllib import request
from six.moves.urllib import request
from heatclient.common import format_utils from heatclient.common import format_utils
from heatclient.common import utils as heat_utils from heatclient.common import utils as heat_utils
@ -184,8 +183,8 @@ def _resource_metadata(heat_client, args):
{'stack': args.stack, {'stack': args.stack,
'resource': args.resource}) 'resource': args.resource})
data = list(six.itervalues(metadata)) data = list(metadata.values())
columns = list(six.iterkeys(metadata)) columns = list(metadata.keys())
return columns, data return columns, data

View File

@ -18,7 +18,6 @@ import logging
from osc_lib.command import command from osc_lib.command import command
from osc_lib import exceptions as exc from osc_lib import exceptions as exc
from osc_lib.i18n import _ from osc_lib.i18n import _
import six
from heatclient.common import format_utils from heatclient.common import format_utils
from heatclient.common import utils as heat_utils from heatclient.common import utils as heat_utils
@ -80,8 +79,8 @@ def _show_resourcetype(heat_client, parsed_args):
raise exc.CommandError( raise exc.CommandError(
_('Resource type not found: %s') % parsed_args.resource_type) _('Resource type not found: %s') % parsed_args.resource_type)
rows = list(six.itervalues(data)) rows = list(data.values())
columns = list(six.iterkeys(data)) columns = list(data.keys())
return columns, rows return columns, rows

View File

@ -20,7 +20,6 @@ from osc_lib.command import command
from osc_lib import exceptions as exc from osc_lib import exceptions as exc
from osc_lib.i18n import _ from osc_lib.i18n import _
from osc_lib import utils from osc_lib import utils
import six
from heatclient.common import format_utils from heatclient.common import format_utils
from heatclient import exc as heat_exc from heatclient import exc as heat_exc
@ -95,8 +94,8 @@ class ShowSnapshot(format_utils.YamlFormat):
% {'snapshot_id': snapshot_id, % {'snapshot_id': snapshot_id,
'stack_id': stack_id}) 'stack_id': stack_id})
rows = list(six.itervalues(data)) rows = list(data.values())
columns = list(six.iterkeys(data)) columns = list(data.keys())
return columns, rows return columns, rows

View File

@ -18,8 +18,7 @@ import logging
from osc_lib.command import command from osc_lib.command import command
from osc_lib import exceptions as exc from osc_lib import exceptions as exc
from osc_lib import utils from osc_lib import utils
import six from urllib import request
from six.moves.urllib import request
import yaml import yaml
from heatclient._i18n import _ from heatclient._i18n import _
@ -181,8 +180,8 @@ def _create_config(heat_client, args):
config['name'] = args.name config['name'] = args.name
sc = heat_client.software_configs.create(**config).to_dict() sc = heat_client.software_configs.create(**config).to_dict()
rows = list(six.itervalues(sc)) rows = list(sc.values())
columns = list(six.iterkeys(sc)) columns = list(sc.keys())
return columns, rows return columns, rows

View File

@ -20,8 +20,7 @@ from osc_lib.command import command
from osc_lib import exceptions as exc from osc_lib import exceptions as exc
from osc_lib import utils from osc_lib import utils
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six from urllib import request
from six.moves.urllib import request
import yaml import yaml
from heatclient._i18n import _ from heatclient._i18n import _
@ -733,7 +732,7 @@ class DeleteStack(command.Command):
try: try:
if not parsed_args.yes and sys.stdin.isatty(): if not parsed_args.yes and sys.stdin.isatty():
prompt_response = six.moves.input( prompt_response = input(
_("Are you sure you want to delete this stack(s) [y/N]? ") _("Are you sure you want to delete this stack(s) [y/N]? ")
).lower() ).lower()
if not prompt_response.startswith('y'): if not prompt_response.startswith('y'):
@ -919,8 +918,8 @@ class AbandonStack(format_utils.JsonFormat):
except IOError as e: except IOError as e:
raise exc.CommandError(str(e)) raise exc.CommandError(str(e))
data = list(six.itervalues(stack)) data = list(stack.values())
columns = list(six.iterkeys(stack)) columns = list(stack.keys())
return columns, data return columns, data
@ -963,8 +962,8 @@ class ExportStack(format_utils.JsonFormat):
except IOError as e: except IOError as e:
raise exc.CommandError(str(e)) raise exc.CommandError(str(e))
data = list(six.itervalues(data_info)) data = list(data_info.values())
columns = list(six.iterkeys(data_info)) columns = list(data_info.keys())
return columns, data return columns, data

View File

@ -16,7 +16,6 @@ import logging
from osc_lib.command import command from osc_lib.command import command
from osc_lib import utils from osc_lib import utils
import six
from heatclient._i18n import _ from heatclient._i18n import _
from heatclient.common import format_utils from heatclient.common import format_utils
@ -181,6 +180,6 @@ def _validate(heat_client, args):
fields['files_container'] = args.files_container fields['files_container'] = args.files_container
validation = heat_client.stacks.validate(**fields) validation = heat_client.stacks.validate(**fields)
data = list(six.itervalues(validation)) data = list(validation.values())
columns = list(six.iterkeys(validation)) columns = list(validation.keys())
return columns, data return columns, data

View File

@ -22,7 +22,6 @@ from keystoneauth1.identity import generic
from keystoneauth1 import session as kssession from keystoneauth1 import session as kssession
from oslo_utils import encodeutils from oslo_utils import encodeutils
from oslo_utils import importutils from oslo_utils import importutils
import six
import heatclient import heatclient
from heatclient._i18n import _ from heatclient._i18n import _
@ -610,7 +609,7 @@ def main(args=None):
if '--debug' in args or '-d' in args: if '--debug' in args or '-d' in args:
raise raise
else: else:
print(encodeutils.safe_encode(six.text_type(e)), file=sys.stderr) print(encodeutils.safe_encode(str(e)), file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -12,7 +12,6 @@
import os import os
import six
from tempest.lib.cli import base from tempest.lib.cli import base
from tempest.lib.cli import output_parser from tempest.lib.cli import output_parser
from tempest.lib import exceptions as tempest_exc from tempest.lib import exceptions as tempest_exc
@ -48,7 +47,7 @@ class OpenStackClientTestBase(base.ClientTestBase):
obj = {} obj = {}
items = self.parser.listing(output) items = self.parser.listing(output)
for item in items: for item in items:
obj[item['Field']] = six.text_type(item['Value']) obj[item['Field']] = str(item['Value'])
return dict((self._key_name(k), v) for k, v in obj.items()) return dict((self._key_name(k), v) for k, v in obj.items())
def _key_name(self, key): def _key_name(self, key):
@ -86,7 +85,7 @@ class OpenStackClientTestBase(base.ClientTestBase):
self.openstack(cmd) self.openstack(cmd)
except tempest_exc.CommandFailed as e: except tempest_exc.CommandFailed as e:
msg = "Stack not found: %s" % id msg = "Stack not found: %s" % id
if msg in six.text_type(e.stdout): if msg in str(e.stdout):
return return
raise raise

View File

@ -16,7 +16,6 @@
import json import json
import requests import requests
import six
class FakeStdout(object): class FakeStdout(object):
@ -41,5 +40,5 @@ class FakeResponse(requests.Response):
self.headers.update(headers) self.headers.update(headers)
self._content = json.dumps(data) self._content = json.dumps(data)
if not isinstance(self._content, six.binary_type): if not isinstance(self._content, bytes):
self._content = self._content.encode() self._content = self._content.encode()

View File

@ -305,7 +305,7 @@ class TestResourceSignal(TestResource):
self.assertEqual('Should only specify one of data or data-file', self.assertEqual('Should only specify one of data or data-file',
str(error)) str(error))
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_resource_signal_file(self, urlopen): def test_resource_signal_file(self, urlopen):
data = mock.Mock() data = mock.Mock()
data.read.side_effect = ['{"message":"Content"}'] data.read.side_effect = ['{"message":"Content"}']

View File

@ -12,8 +12,8 @@
from unittest import mock from unittest import mock
import io
from osc_lib import exceptions as exc from osc_lib import exceptions as exc
import six
from heatclient import exc as heat_exc from heatclient import exc as heat_exc
from heatclient.osc.v1 import snapshot from heatclient.osc.v1 import snapshot
@ -160,7 +160,7 @@ class TestSnapshotDelete(TestStack):
self.cmd.take_action, self.cmd.take_action,
parsed_args) parsed_args)
@mock.patch('sys.stdin', spec=six.StringIO) @mock.patch('sys.stdin', spec=io.StringIO)
def test_snapshot_delete_prompt(self, mock_stdin): def test_snapshot_delete_prompt(self, mock_stdin):
arglist = ['my_stack', 'snapshot_id'] arglist = ['my_stack', 'snapshot_id']
mock_stdin.isatty.return_value = True mock_stdin.isatty.return_value = True
@ -173,7 +173,7 @@ class TestSnapshotDelete(TestStack):
self.stack_client.snapshot_delete.assert_called_with('my_stack', self.stack_client.snapshot_delete.assert_called_with('my_stack',
'snapshot_id') 'snapshot_id')
@mock.patch('sys.stdin', spec=six.StringIO) @mock.patch('sys.stdin', spec=io.StringIO)
def test_snapshot_delete_prompt_no(self, mock_stdin): def test_snapshot_delete_prompt_no(self, mock_stdin):
arglist = ['my_stack', 'snapshot_id'] arglist = ['my_stack', 'snapshot_id']
mock_stdin.isatty.return_value = True mock_stdin.isatty.return_value = True

View File

@ -145,7 +145,7 @@ class TestCreateConfig(TestConfig):
self.mock_client.software_configs.create.assert_called_with( self.mock_client.software_configs.create.assert_called_with(
**properties) **properties)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_config_create_config_file(self, urlopen): def test_config_create_config_file(self, urlopen):
properties = { properties = {
'config': 'config', 'config': 'config',
@ -172,7 +172,7 @@ class TestCreateConfig(TestConfig):
self.mock_client.software_configs.create.assert_called_with( self.mock_client.software_configs.create.assert_called_with(
**properties) **properties)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_config_create_definition_file(self, urlopen): def test_config_create_definition_file(self, urlopen):
definition = { definition = {
'inputs': [ 'inputs': [

View File

@ -17,7 +17,6 @@ from unittest import mock
from osc_lib import exceptions as exc from osc_lib import exceptions as exc
from osc_lib import utils from osc_lib import utils
import six
import testscenarios import testscenarios
import yaml import yaml
@ -274,7 +273,7 @@ class TestStackUpdate(TestStack):
ex = self.assertRaises(exc.CommandError, self.cmd.take_action, ex = self.assertRaises(exc.CommandError, self.cmd.take_action,
parsed_args) parsed_args)
self.assertEqual("--rollback invalid value: foo", six.text_type(ex)) self.assertEqual("--rollback invalid value: foo", str(ex))
def test_stack_update_parameters(self): def test_stack_update_parameters(self):
template_path = ('/'.join(self.template_path.split('/')[:-1]) + template_path = ('/'.join(self.template_path.split('/')[:-1]) +
@ -720,7 +719,7 @@ class TestStackDelete(TestStack):
self.stack_client.delete.assert_any_call('stack3') self.stack_client.delete.assert_any_call('stack3')
self.assertEqual('Unable to delete 1 of the 3 stacks.', str(error)) self.assertEqual('Unable to delete 1 of the 3 stacks.', str(error))
@mock.patch('sys.stdin', spec=six.StringIO) @mock.patch('sys.stdin', spec=io.StringIO)
def test_stack_delete_prompt(self, mock_stdin): def test_stack_delete_prompt(self, mock_stdin):
arglist = ['my_stack'] arglist = ['my_stack']
mock_stdin.isatty.return_value = True mock_stdin.isatty.return_value = True
@ -732,7 +731,7 @@ class TestStackDelete(TestStack):
mock_stdin.readline.assert_called_with() mock_stdin.readline.assert_called_with()
self.stack_client.delete.assert_called_with('my_stack') self.stack_client.delete.assert_called_with('my_stack')
@mock.patch('sys.stdin', spec=six.StringIO) @mock.patch('sys.stdin', spec=io.StringIO)
def test_stack_delete_prompt_no(self, mock_stdin): def test_stack_delete_prompt_no(self, mock_stdin):
arglist = ['my_stack'] arglist = ['my_stack']
mock_stdin.isatty.return_value = True mock_stdin.isatty.return_value = True

View File

@ -15,9 +15,9 @@
import socket import socket
from unittest import mock from unittest import mock
import io
from keystoneauth1 import adapter from keystoneauth1 import adapter
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six
import testtools import testtools
from heatclient.common import http from heatclient.common import http
@ -608,7 +608,7 @@ class SessionClientTest(testtools.TestCase):
e = self.assertRaises(exc.HTTPNotFound, e = self.assertRaises(exc.HTTPNotFound,
client.request, '', 'GET') client.request, '', 'GET')
# Assert that the raised exception can be converted to string # Assert that the raised exception can be converted to string
self.assertIsNotNone(six.text_type(e)) self.assertIsNotNone(str(e))
def test_redirect_302_location(self): def test_redirect_302_location(self):
fake1 = fakes.FakeHTTPResponse( fake1 = fakes.FakeHTTPResponse(
@ -687,7 +687,7 @@ class SessionClientTest(testtools.TestCase):
auth=mock.ANY) auth=mock.ANY)
e = self.assertRaises(exc.InvalidEndpoint, e = self.assertRaises(exc.InvalidEndpoint,
client.request, '', 'GET', redirect=True) client.request, '', 'GET', redirect=True)
self.assertEqual("Location not returned with 302", six.text_type(e)) self.assertEqual("Location not returned with 302", str(e))
def test_no_redirect_302_no_location(self): def test_no_redirect_302_no_location(self):
fake = fakes.FakeHTTPResponse( fake = fakes.FakeHTTPResponse(
@ -716,7 +716,7 @@ class SessionClientTest(testtools.TestCase):
e = self.assertRaises(exc.HTTPMultipleChoices, e = self.assertRaises(exc.HTTPMultipleChoices,
client.request, '', 'GET') client.request, '', 'GET')
# Assert that the raised exception can be converted to string # Assert that the raised exception can be converted to string
self.assertIsNotNone(six.text_type(e)) self.assertIsNotNone(str(e))
def test_504_error_response(self): def test_504_error_response(self):
# for 504 we don't have specific exception type # for 504 we don't have specific exception type
@ -766,7 +766,7 @@ class SessionClientTest(testtools.TestCase):
{} {}
) )
mock_dumps.return_value = "{'files': test}}" mock_dumps.return_value = "{'files': test}}"
data = six.BytesIO(b'test') data = io.BytesIO(b'test')
kwargs = {'endpoint_override': 'http://no.where/', kwargs = {'endpoint_override': 'http://no.where/',
'data': {'files': data}} 'data': {'files': data}}
client = http.SessionClient(mock.ANY) client = http.SessionClient(mock.ANY)

View File

@ -13,7 +13,6 @@
from unittest import mock from unittest import mock
import six
import swiftclient.client import swiftclient.client
import testscenarios import testscenarios
import testtools import testtools
@ -231,7 +230,7 @@ class DerivedConfigTest(testtools.TestCase):
if not self.result_error: if not self.result_error:
raise e raise e
self.assertIsInstance(e, self.result_error) self.assertIsInstance(e, self.result_error)
self.assertEqual(self.result_error_msg, six.text_type(e)) self.assertEqual(self.result_error_msg, str(e))
class TempURLSignalTest(testtools.TestCase): class TempURLSignalTest(testtools.TestCase):
@ -331,7 +330,7 @@ class TempURLSignalTest(testtools.TestCase):
self.assertEqual(( self.assertEqual((
'Cannot use --os-no-client-auth, auth required to create ' 'Cannot use --os-no-client-auth, auth required to create '
'a Swift TempURL.'), 'a Swift TempURL.'),
six.text_type(e)) str(e))
@mock.patch.object(deployment_utils, 'create_temp_url') @mock.patch.object(deployment_utils, 'create_temp_url')
@mock.patch.object(deployment_utils, 'create_swift_client') @mock.patch.object(deployment_utils, 'create_swift_client')

View File

@ -12,7 +12,6 @@
from unittest import mock from unittest import mock
import six
import testscenarios import testscenarios
import testtools import testtools
import yaml import yaml
@ -106,4 +105,4 @@ but very:
- incorrect - incorrect
""" """
ex = self.assertRaises(ValueError, environment_format.parse, yaml) ex = self.assertRaises(ValueError, environment_format.parse, yaml)
self.assertIn('but very:\n ^', six.text_type(ex)) self.assertIn('but very:\n ^', str(ex))

View File

@ -12,8 +12,8 @@
# #
# Copyright 2015 IBM Corp. # Copyright 2015 IBM Corp.
import io
import json import json
import six
import yaml import yaml
from heatclient.common import format_utils from heatclient.common import format_utils
@ -128,7 +128,7 @@ abcde
truncate_postfix='truncated')) truncate_postfix='truncated'))
def test_print_software_deployment_output(self): def test_print_software_deployment_output(self):
out = six.StringIO() out = io.StringIO()
format_utils.print_software_deployment_output( format_utils.print_software_deployment_output(
{'deploy_stdout': ''}, out=out, name='deploy_stdout') {'deploy_stdout': ''}, out=out, name='deploy_stdout')
self.assertEqual( self.assertEqual(
@ -137,7 +137,7 @@ abcde
ov = {'deploy_stdout': '', 'deploy_stderr': '1\n2\n3\n4\n5\n6\n7\n8\n9' ov = {'deploy_stdout': '', 'deploy_stderr': '1\n2\n3\n4\n5\n6\n7\n8\n9'
'\n10\n11', '\n10\n11',
'deploy_status_code': 0} 'deploy_status_code': 0}
out = six.StringIO() out = io.StringIO()
format_utils.print_software_deployment_output(ov, out=out, format_utils.print_software_deployment_output(ov, out=out,
name='deploy_stderr') name='deploy_stderr')
self.assertEqual( self.assertEqual(
@ -156,7 +156,7 @@ abcde
11 11
(truncated, view all with --long) (truncated, view all with --long)
''', out.getvalue()) ''', out.getvalue())
out = six.StringIO() out = io.StringIO()
format_utils.print_software_deployment_output(ov, out=out, format_utils.print_software_deployment_output(ov, out=out,
name='deploy_stderr', name='deploy_stderr',
long=True) long=True)

View File

@ -14,7 +14,7 @@
import json import json
import os import os
import six import io
from heatclient.common import resource_formatter from heatclient.common import resource_formatter
from heatclient.osc.v1 import resource from heatclient.osc.v1 import resource
@ -94,7 +94,7 @@ OS::Heat::RandomString" ];
self.resources.append(v1_resources.Resource(None, r)) self.resources.append(v1_resources.Resource(None, r))
def test_resource_list(self): def test_resource_list(self):
out = six.StringIO() out = io.StringIO()
formatter = resource_formatter.ResourceDotFormatter() formatter = resource_formatter.ResourceDotFormatter()
formatter.emit_list(None, self.resources, out, None) formatter.emit_list(None, self.resources, out, None)

View File

@ -14,8 +14,8 @@
from unittest import mock from unittest import mock
from six.moves.urllib import parse
import testtools import testtools
from urllib import parse
from heatclient.common import utils from heatclient.common import utils
from heatclient.v1 import resources from heatclient.v1 import resources

View File

@ -18,15 +18,15 @@ from unittest import mock
import uuid import uuid
import fixtures import fixtures
import io
from keystoneauth1 import fixture as keystone_fixture from keystoneauth1 import fixture as keystone_fixture
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import encodeutils from oslo_utils import encodeutils
from requests_mock.contrib import fixture as rm_fixture from requests_mock.contrib import fixture as rm_fixture
import six
from six.moves.urllib import parse
from six.moves.urllib import request
import testscenarios import testscenarios
import testtools import testtools
from urllib import parse
from urllib import request
import yaml import yaml
from heatclient._i18n import _ from heatclient._i18n import _
@ -411,7 +411,7 @@ class ShellBase(TestCase):
def shell(self, argstr): def shell(self, argstr):
orig = sys.stdout orig = sys.stdout
try: try:
sys.stdout = six.StringIO() sys.stdout = io.StringIO()
_shell = heatclient.shell.HeatShell() _shell = heatclient.shell.HeatShell()
_shell.main(argstr.split()) _shell.main(argstr.split())
self.subcommands = _shell.subcommands.keys() self.subcommands = _shell.subcommands.keys()
@ -525,7 +525,7 @@ class ShellTestNoMoxBase(TestCase):
def shell(self, argstr): def shell(self, argstr):
orig = sys.stdout orig = sys.stdout
try: try:
sys.stdout = six.StringIO() sys.stdout = io.StringIO()
_shell = heatclient.shell.HeatShell() _shell = heatclient.shell.HeatShell()
_shell.main(argstr.split()) _shell.main(argstr.split())
self.subcommands = _shell.subcommands.keys() self.subcommands = _shell.subcommands.keys()
@ -1354,7 +1354,7 @@ class ShellTestUserPass(ShellBase):
def test_stack_create_url(self): def test_stack_create_url(self):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()
url_content = six.StringIO( url_content = io.StringIO(
'{"AWSTemplateFormatVersion" : "2010-09-09"}') '{"AWSTemplateFormatVersion" : "2010-09-09"}')
self.useFixture(fixtures.MockPatchObject(request, 'urlopen', self.useFixture(fixtures.MockPatchObject(request, 'urlopen',
return_value=url_content)) return_value=url_content))
@ -2001,7 +2001,7 @@ class ShellTestUserPass(ShellBase):
# the main thing this @mock.patch is doing here is keeping # the main thing this @mock.patch is doing here is keeping
# sys.stdin untouched for later tests # sys.stdin untouched for later tests
@mock.patch('sys.stdin', new_callable=six.StringIO) @mock.patch('sys.stdin', new_callable=io.StringIO)
def test_stack_delete_prompt_with_tty(self, ms): def test_stack_delete_prompt_with_tty(self, ms):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()
mock_stdin = mock.Mock() mock_stdin = mock.Mock()
@ -2025,7 +2025,7 @@ class ShellTestUserPass(ShellBase):
# the main thing this @mock.patch is doing here is keeping # the main thing this @mock.patch is doing here is keeping
# sys.stdin untouched for later tests # sys.stdin untouched for later tests
@mock.patch('sys.stdin', new_callable=six.StringIO) @mock.patch('sys.stdin', new_callable=io.StringIO)
def test_stack_delete_prompt_with_tty_y(self, ms): def test_stack_delete_prompt_with_tty_y(self, ms):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()
mock_stdin = mock.Mock() mock_stdin = mock.Mock()
@ -2159,7 +2159,7 @@ class ShellTestUserPass(ShellBase):
# the main thing this @mock.patch is doing here is keeping # the main thing this @mock.patch is doing here is keeping
# sys.stdin untouched for later tests # sys.stdin untouched for later tests
@mock.patch('sys.stdin', new_callable=six.StringIO) @mock.patch('sys.stdin', new_callable=io.StringIO)
def test_snapshot_delete_prompt_with_tty(self, ms): def test_snapshot_delete_prompt_with_tty(self, ms):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()
resp_dict = {"snapshot": { resp_dict = {"snapshot": {
@ -2189,7 +2189,7 @@ class ShellTestUserPass(ShellBase):
# the main thing this @mock.patch is doing here is keeping # the main thing this @mock.patch is doing here is keeping
# sys.stdin untouched for later tests # sys.stdin untouched for later tests
@mock.patch('sys.stdin', new_callable=six.StringIO) @mock.patch('sys.stdin', new_callable=io.StringIO)
def test_snapshot_delete_prompt_with_tty_y(self, ms): def test_snapshot_delete_prompt_with_tty_y(self, ms):
self.register_keystone_auth_fixture() self.register_keystone_auth_fixture()
resp_dict = {"snapshot": { resp_dict = {"snapshot": {
@ -2477,7 +2477,7 @@ class ShellTestUserPass(ShellBase):
exc.CommandError, self.shell, exc.CommandError, self.shell,
'output-show teststack/1 output1') 'output-show teststack/1 output1')
self.assertIn('The Referenced Attribute (0 PublicIP) is incorrect.', self.assertIn('The Referenced Attribute (0 PublicIP) is incorrect.',
six.text_type(error)) str(error))
class ShellTestActions(ShellBase): class ShellTestActions(ShellBase):
@ -3548,8 +3548,8 @@ class ShellTestConfig(ShellBase):
}} }}
output = [ output = [
six.StringIO(yaml.safe_dump(definition, indent=2)), io.StringIO(yaml.safe_dump(definition, indent=2)),
six.StringIO('the config script'), io.StringIO('the config script'),
] ]
self.useFixture(fixtures.MockPatchObject(request, 'urlopen', self.useFixture(fixtures.MockPatchObject(request, 'urlopen',
side_effect=output)) side_effect=output))
@ -4082,7 +4082,7 @@ class MockShellBase(TestCase):
def shell(self, argstr): def shell(self, argstr):
orig = sys.stdout orig = sys.stdout
try: try:
sys.stdout = six.StringIO() sys.stdout = io.StringIO()
_shell = heatclient.shell.HeatShell() _shell = heatclient.shell.HeatShell()
_shell.main(argstr.split()) _shell.main(argstr.split())
self.subcommands = _shell.subcommands.keys() self.subcommands = _shell.subcommands.keys()

View File

@ -12,7 +12,6 @@
from unittest import mock from unittest import mock
import six
import testscenarios import testscenarios
import testtools import testtools
import yaml import yaml
@ -60,4 +59,4 @@ but very:
- incorrect - incorrect
""" """
ex = self.assertRaises(ValueError, template_format.parse, yaml) ex = self.assertRaises(ValueError, template_format.parse, yaml)
self.assertIn('but very:\n ^', six.text_type(ex)) self.assertIn('but very:\n ^', str(ex))

View File

@ -15,11 +15,11 @@ import json
import tempfile import tempfile
from unittest import mock from unittest import mock
import io
from oslo_serialization import base64 from oslo_serialization import base64
import six
from six.moves.urllib import error
import testtools import testtools
from testtools import matchers from testtools import matchers
from urllib import error
import yaml import yaml
from heatclient.common import template_utils from heatclient.common import template_utils
@ -37,8 +37,8 @@ class ShellEnvironmentTest(testtools.TestCase):
if url: if url:
def side_effect(args): def side_effect(args):
if url == args: if url == args:
return six.BytesIO(content) return io.BytesIO(content)
with mock.patch('six.moves.urllib.request.urlopen') as mock_url: with mock.patch('urllib.request.urlopen') as mock_url:
mock_url.side_effect = side_effect mock_url.side_effect = side_effect
template_utils.resolve_environment_urls( template_utils.resolve_environment_urls(
jenv.get('resource_registry'), files, env_base_url) jenv.get('resource_registry'), files, env_base_url)
@ -47,7 +47,7 @@ class ShellEnvironmentTest(testtools.TestCase):
template_utils.resolve_environment_urls( template_utils.resolve_environment_urls(
jenv.get('resource_registry'), files, env_base_url) jenv.get('resource_registry'), files, env_base_url)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_ignore_env_keys(self, mock_url): def test_ignore_env_keys(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env = b''' env = b'''
@ -57,7 +57,7 @@ class ShellEnvironmentTest(testtools.TestCase):
hooks: pre_create hooks: pre_create
restricted_actions: replace restricted_actions: replace
''' '''
mock_url.return_value = six.BytesIO(env) mock_url.return_value = io.BytesIO(env)
_, env_dict = template_utils.process_environment_and_files( _, env_dict = template_utils.process_environment_and_files(
env_file) env_file)
self.assertEqual( self.assertEqual(
@ -67,7 +67,7 @@ class ShellEnvironmentTest(testtools.TestCase):
env_dict) env_dict)
mock_url.assert_called_with('file://%s' % env_file) mock_url.assert_called_with('file://%s' % env_file)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_environment_file(self, mock_url): def test_process_environment_file(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
@ -75,8 +75,8 @@ class ShellEnvironmentTest(testtools.TestCase):
resource_registry: resource_registry:
"OS::Thingy": "file:///home/b/a.yaml" "OS::Thingy": "file:///home/b/a.yaml"
''' '''
mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
files, env_dict = template_utils.process_environment_and_files( files, env_dict = template_utils.process_environment_and_files(
env_file) env_file)
@ -92,7 +92,7 @@ class ShellEnvironmentTest(testtools.TestCase):
mock.call('file:///home/b/a.yaml') mock.call('file:///home/b/a.yaml')
]) ])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_environment_relative_file(self, mock_url): def test_process_environment_relative_file(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
@ -102,8 +102,8 @@ class ShellEnvironmentTest(testtools.TestCase):
"OS::Thingy": a.yaml "OS::Thingy": a.yaml
''' '''
mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
self.assertEqual( self.assertEqual(
env_url, env_url,
@ -139,7 +139,7 @@ class ShellEnvironmentTest(testtools.TestCase):
self.assertEqual({}, files) self.assertEqual({}, files)
self.assertEqual({}, env) self.assertEqual({}, env)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_environment_relative_file_up(self, mock_url): def test_process_environment_relative_file_up(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
@ -148,8 +148,8 @@ class ShellEnvironmentTest(testtools.TestCase):
resource_registry: resource_registry:
"OS::Thingy": ../bar/a.yaml "OS::Thingy": ../bar/a.yaml
''' '''
mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
env_url = 'file://%s' % env_file env_url = 'file://%s' % env_file
self.assertEqual( self.assertEqual(
@ -174,7 +174,7 @@ class ShellEnvironmentTest(testtools.TestCase):
mock.call('file:///home/my/bar/a.yaml') mock.call('file:///home/my/bar/a.yaml')
]) ])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_environment_url(self, mock_url): def test_process_environment_url(self, mock_url):
env = b''' env = b'''
resource_registry: resource_registry:
@ -182,8 +182,8 @@ class ShellEnvironmentTest(testtools.TestCase):
''' '''
url = 'http://no.where/some/path/to/file.yaml' url = 'http://no.where/some/path/to/file.yaml'
tmpl_url = 'http://no.where/some/path/to/a.yaml' tmpl_url = 'http://no.where/some/path/to/a.yaml'
mock_url.side_effect = [six.BytesIO(env), six.BytesIO(self.template_a), mock_url.side_effect = [io.BytesIO(env), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
files, env_dict = template_utils.process_environment_and_files( files, env_dict = template_utils.process_environment_and_files(
url) url)
@ -197,12 +197,12 @@ class ShellEnvironmentTest(testtools.TestCase):
mock.call(tmpl_url) mock.call(tmpl_url)
]) ])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_environment_empty_file(self, mock_url): def test_process_environment_empty_file(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env = b'' env = b''
mock_url.return_value = six.BytesIO(env) mock_url.return_value = io.BytesIO(env)
files, env_dict = template_utils.process_environment_and_files( files, env_dict = template_utils.process_environment_and_files(
env_file) env_file)
@ -216,7 +216,7 @@ class ShellEnvironmentTest(testtools.TestCase):
self.assertEqual({}, env) self.assertEqual({}, env)
self.assertEqual({}, files) self.assertEqual({}, files)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_multiple_environments_and_files(self, mock_url): def test_process_multiple_environments_and_files(self, mock_url):
env_file1 = '/home/my/dir/env1.yaml' env_file1 = '/home/my/dir/env1.yaml'
@ -235,12 +235,12 @@ class ShellEnvironmentTest(testtools.TestCase):
"OS::Thingy2": "file:///home/b/b.yaml" "OS::Thingy2": "file:///home/b/b.yaml"
''' '''
mock_url.side_effect = [six.BytesIO(env1), mock_url.side_effect = [io.BytesIO(env1),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(env2), io.BytesIO(env2),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
files, env = template_utils.process_multiple_environments_and_files( files, env = template_utils.process_multiple_environments_and_files(
[env_file1, env_file2]) [env_file1, env_file2])
@ -267,7 +267,7 @@ class ShellEnvironmentTest(testtools.TestCase):
mock.call('file:///home/b/b.yaml') mock.call('file:///home/b/b.yaml')
]) ])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_multiple_environments_default_resources(self, mock_url): def test_process_multiple_environments_default_resources(self, mock_url):
env_file1 = '/home/my/dir/env1.yaml' env_file1 = '/home/my/dir/env1.yaml'
@ -289,16 +289,16 @@ class ShellEnvironmentTest(testtools.TestCase):
resource2: resource2:
"OS::Thingy4": "file:///home/b/b.yaml" "OS::Thingy4": "file:///home/b/b.yaml"
''' '''
mock_url.side_effect = [six.BytesIO(env1), mock_url.side_effect = [io.BytesIO(env1),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(env2), io.BytesIO(env2),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
files, env = template_utils.process_multiple_environments_and_files( files, env = template_utils.process_multiple_environments_and_files(
[env_file1, env_file2]) [env_file1, env_file2])
@ -378,7 +378,7 @@ class ShellEnvironmentTest(testtools.TestCase):
self.assertEqual(self.template_a.decode('utf-8'), self.assertEqual(self.template_a.decode('utf-8'),
files['http://no.where/path/to/b/a.yaml']) files['http://no.where/path/to/b/a.yaml'])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_multiple_environments_and_files_tracker(self, mock_url): def test_process_multiple_environments_and_files_tracker(self, mock_url):
# Setup # Setup
env_file1 = '/home/my/dir/env1.yaml' env_file1 = '/home/my/dir/env1.yaml'
@ -389,9 +389,9 @@ class ShellEnvironmentTest(testtools.TestCase):
resource_registry: resource_registry:
"OS::Thingy1": "file:///home/b/a.yaml" "OS::Thingy1": "file:///home/b/a.yaml"
''' '''
mock_url.side_effect = [six.BytesIO(env1), mock_url.side_effect = [io.BytesIO(env1),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
# Test # Test
env_file_list = [] env_file_list = []
@ -419,7 +419,7 @@ class ShellEnvironmentTest(testtools.TestCase):
]) ])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_environment_relative_file_tracker(self, mock_url): def test_process_environment_relative_file_tracker(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
@ -428,9 +428,9 @@ class ShellEnvironmentTest(testtools.TestCase):
resource_registry: resource_registry:
"OS::Thingy": a.yaml "OS::Thingy": a.yaml
''' '''
mock_url.side_effect = [six.BytesIO(env), mock_url.side_effect = [io.BytesIO(env),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a)] io.BytesIO(self.template_a)]
self.assertEqual( self.assertEqual(
env_url, env_url,
@ -460,7 +460,7 @@ class ShellEnvironmentTest(testtools.TestCase):
]) ])
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_process_multiple_environments_empty_registry(self, mock_url): def test_process_multiple_environments_empty_registry(self, mock_url):
# Setup # Setup
env_file1 = '/home/my/dir/env1.yaml' env_file1 = '/home/my/dir/env1.yaml'
@ -473,10 +473,10 @@ class ShellEnvironmentTest(testtools.TestCase):
env2 = b''' env2 = b'''
resource_registry: resource_registry:
''' '''
mock_url.side_effect = [six.BytesIO(env1), mock_url.side_effect = [io.BytesIO(env1),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(self.template_a), io.BytesIO(self.template_a),
six.BytesIO(env2)] io.BytesIO(env2)]
# Test # Test
env_file_list = [] env_file_list = []
@ -654,11 +654,11 @@ class TestGetTemplateContents(testtools.TestCase):
matchers.MatchesRegex( matchers.MatchesRegex(
'Error parsing template file://%s ' % tmpl_file.name)) 'Error parsing template file://%s ' % tmpl_file.name))
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_get_template_contents_url(self, mock_url): def test_get_template_contents_url(self, mock_url):
tmpl = b'{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}' tmpl = b'{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}'
url = 'http://no.where/path/to/a.yaml' url = 'http://no.where/path/to/a.yaml'
mock_url.return_value = six.BytesIO(tmpl) mock_url.return_value = io.BytesIO(tmpl)
files, tmpl_parsed = template_utils.get_template_contents( files, tmpl_parsed = template_utils.get_template_contents(
template_url=url) template_url=url)
@ -726,9 +726,9 @@ class TestGetTemplateContents(testtools.TestCase):
[{'path': '/tmp/%s' % filename, [{'path': '/tmp/%s' % filename,
'content': {'get_file': url}, 'content': {'get_file': url},
'encoding': 'b64'}]}}}}} 'encoding': 'b64'}]}}}}}
with mock.patch('six.moves.urllib.request.urlopen') as mock_url: with mock.patch('urllib.request.urlopen') as mock_url:
raw_content = base64.decode_as_bytes(content) raw_content = base64.decode_as_bytes(content)
response = six.BytesIO(raw_content) response = io.BytesIO(raw_content)
mock_url.return_value = response mock_url.return_value = response
files = {} files = {}
template_utils.resolve_template_get_files( template_utils.resolve_template_get_files(
@ -746,13 +746,7 @@ ABOkDAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA\n'''
# zip has '\0' in stream # zip has '\0' in stream
self.assertIn(b'\0', base64.decode_as_bytes(content)) self.assertIn(b'\0', base64.decode_as_bytes(content))
decoded_content = base64.decode_as_bytes(content) decoded_content = base64.decode_as_bytes(content)
if six.PY3: self.assertRaises(UnicodeDecodeError, decoded_content.decode)
self.assertRaises(UnicodeDecodeError, decoded_content.decode)
else:
self.assertRaises(
UnicodeDecodeError,
json.dumps,
{'content': decoded_content})
self.check_non_utf8_content( self.check_non_utf8_content(
filename=filename, content=content) filename=filename, content=content)
@ -762,13 +756,7 @@ ABOkDAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA\n'''
# utf6 has '\0' in stream # utf6 has '\0' in stream
self.assertIn(b'\0', base64.decode_as_bytes(content)) self.assertIn(b'\0', base64.decode_as_bytes(content))
decoded_content = base64.decode_as_bytes(content) decoded_content = base64.decode_as_bytes(content)
if six.PY3: self.assertRaises(UnicodeDecodeError, decoded_content.decode)
self.assertRaises(UnicodeDecodeError, decoded_content.decode)
else:
self.assertRaises(
UnicodeDecodeError,
json.dumps,
{'content': decoded_content})
self.check_non_utf8_content(filename=filename, content=content) self.check_non_utf8_content(filename=filename, content=content)
def test_get_gb18030_content(self): def test_get_gb18030_content(self):
@ -777,17 +765,11 @@ ABOkDAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA\n'''
# gb18030 has no '\0' in stream # gb18030 has no '\0' in stream
self.assertNotIn('\0', base64.decode_as_bytes(content)) self.assertNotIn('\0', base64.decode_as_bytes(content))
decoded_content = base64.decode_as_bytes(content) decoded_content = base64.decode_as_bytes(content)
if six.PY3: self.assertRaises(UnicodeDecodeError, decoded_content.decode)
self.assertRaises(UnicodeDecodeError, decoded_content.decode)
else:
self.assertRaises(
UnicodeDecodeError,
json.dumps,
{'content': decoded_content})
self.check_non_utf8_content(filename=filename, content=content) self.check_non_utf8_content(filename=filename, content=content)
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
class TestTemplateGetFileFunctions(testtools.TestCase): class TestTemplateGetFileFunctions(testtools.TestCase):
hot_template = b'''heat_template_version: 2013-05-23 hot_template = b'''heat_template_version: 2013-05-23
@ -815,12 +797,12 @@ resources:
tmpl_file = '/home/my/dir/template.yaml' tmpl_file = '/home/my/dir/template.yaml'
url = 'file:///home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml'
mock_url.side_effect = [six.BytesIO(self.hot_template), mock_url.side_effect = [io.BytesIO(self.hot_template),
six.BytesIO(b'bar contents'), io.BytesIO(b'bar contents'),
six.BytesIO(b'foo contents'), io.BytesIO(b'foo contents'),
six.BytesIO(b'baz1 contents'), io.BytesIO(b'baz1 contents'),
six.BytesIO(b'baz2 contents'), io.BytesIO(b'baz2 contents'),
six.BytesIO(b'baz3 contents')] io.BytesIO(b'baz3 contents')]
files, tmpl_parsed = template_utils.get_template_contents( files, tmpl_parsed = template_utils.get_template_contents(
template_file=tmpl_file) template_file=tmpl_file)
@ -869,8 +851,8 @@ outputs:\n\
contents:\n\ contents:\n\
value:\n\ value:\n\
get_file: foo.yaml\n''' get_file: foo.yaml\n'''
mock_url.side_effect = [six.BytesIO(contents), mock_url.side_effect = [io.BytesIO(contents),
six.BytesIO(b'foo contents')] io.BytesIO(b'foo contents')]
files = template_utils.get_template_contents( files = template_utils.get_template_contents(
template_file=tmpl_file)[0] template_file=tmpl_file)[0]
self.assertEqual({foo_url: b'foo contents'}, files) self.assertEqual({foo_url: b'foo contents'}, files)
@ -892,8 +874,8 @@ outputs:\n\
template:\n\ template:\n\
value:\n\ value:\n\
get_file: foo.yaml\n''' get_file: foo.yaml\n'''
mock_url.side_effect = [six.BytesIO(contents), mock_url.side_effect = [io.BytesIO(contents),
six.BytesIO(b'foo contents')] io.BytesIO(b'foo contents')]
# asserts that is fetched only once even though it is # asserts that is fetched only once even though it is
# referenced in the template twice # referenced in the template twice
files = template_utils.get_template_contents( files = template_utils.get_template_contents(
@ -935,18 +917,18 @@ parameters:
type: string type: string
''' '''
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_hot_template(self, mock_url): def test_hot_template(self, mock_url):
tmpl_file = '/home/my/dir/template.yaml' tmpl_file = '/home/my/dir/template.yaml'
url = 'file:///home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml'
def side_effect(args): def side_effect(args):
if url == args: if url == args:
return six.BytesIO(self.hot_template) return io.BytesIO(self.hot_template)
if 'file:///home/my/dir/foo.yaml' == args: if 'file:///home/my/dir/foo.yaml' == args:
return six.BytesIO(self.foo_template) return io.BytesIO(self.foo_template)
if 'file:///home/my/dir/spam/egg.yaml' == args: if 'file:///home/my/dir/spam/egg.yaml' == args:
return six.BytesIO(self.egg_template) return io.BytesIO(self.egg_template)
mock_url.side_effect = side_effect mock_url.side_effect = side_effect
files, tmpl_parsed = template_utils.get_template_contents( files, tmpl_parsed = template_utils.get_template_contents(
@ -1013,7 +995,7 @@ parameters:
type: string type: string
''' '''
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_hot_template(self, mock_url): def test_hot_template(self, mock_url):
tmpl_file = '/home/my/dir/template.yaml' tmpl_file = '/home/my/dir/template.yaml'
url = 'file:///home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml'
@ -1022,11 +1004,11 @@ parameters:
def side_effect(args): def side_effect(args):
if url == args: if url == args:
return six.BytesIO(self.hot_template) return io.BytesIO(self.hot_template)
if foo_url == args: if foo_url == args:
return six.BytesIO(self.foo_template) return io.BytesIO(self.foo_template)
if bar_url == args: if bar_url == args:
return six.BytesIO(self.bar_template) return io.BytesIO(self.bar_template)
mock_url.side_effect = side_effect mock_url.side_effect = side_effect
files, tmpl_parsed = template_utils.get_template_contents( files, tmpl_parsed = template_utils.get_template_contents(
@ -1112,7 +1094,7 @@ parameters:
type: string type: string
''' '''
@mock.patch('six.moves.urllib.request.urlopen') @mock.patch('urllib.request.urlopen')
def test_env_nested_includes(self, mock_url): def test_env_nested_includes(self, mock_url):
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env_url = 'file:///home/my/dir/env.yaml' env_url = 'file:///home/my/dir/env.yaml'
@ -1130,21 +1112,21 @@ parameters:
def side_effect(args): def side_effect(args):
if env_url == args: if env_url == args:
return six.BytesIO(env) return io.BytesIO(env)
if template_url == args: if template_url == args:
return six.BytesIO(self.hot_template) return io.BytesIO(self.hot_template)
if foo_url == args: if foo_url == args:
return six.BytesIO(self.foo_template) return io.BytesIO(self.foo_template)
if egg_url == args: if egg_url == args:
return six.BytesIO(self.egg_template) return io.BytesIO(self.egg_template)
if ham_url == args: if ham_url == args:
return six.BytesIO(b'ham contents') return io.BytesIO(b'ham contents')
if one_url == args: if one_url == args:
return six.BytesIO(self.foo_template) return io.BytesIO(self.foo_template)
if two_url == args: if two_url == args:
return six.BytesIO(self.foo_template) return io.BytesIO(self.foo_template)
if three_url == args: if three_url == args:
return six.BytesIO(b'three contents') return io.BytesIO(b'three contents')
mock_url.side_effect = side_effect mock_url.side_effect = side_effect
files, env_dict = template_utils.process_environment_and_files( files, env_dict = template_utils.process_environment_and_files(

View File

@ -15,7 +15,7 @@
import collections import collections
from oslo_utils import encodeutils from oslo_utils import encodeutils
from six.moves.urllib import parse from urllib import parse
from heatclient.common import base from heatclient.common import base
from heatclient.common import utils from heatclient.common import utils

View File

@ -12,8 +12,7 @@
# under the License. # under the License.
from oslo_utils import encodeutils from oslo_utils import encodeutils
import six from urllib import parse
from six.moves.urllib import parse
from heatclient.common import base from heatclient.common import base
from heatclient.common import utils from heatclient.common import utils
@ -21,7 +20,7 @@ from heatclient.common import utils
class ResourceType(base.Resource): class ResourceType(base.Resource):
def __repr__(self): def __repr__(self):
if isinstance(self._info, six.string_types): if isinstance(self._info, str):
return "<ResourceType %s>" % self._info return "<ResourceType %s>" % self._info
else: else:
return "<ResourceType %s>" % self._info.get('resource_type') return "<ResourceType %s>" % self._info.get('resource_type')
@ -30,7 +29,7 @@ class ResourceType(base.Resource):
return self.manager.data(self, **kwargs) return self.manager.data(self, **kwargs)
def _add_details(self, info): def _add_details(self, info):
if isinstance(info, six.string_types): if isinstance(info, str):
self.resource_type = info self.resource_type = info
elif isinstance(info, dict): elif isinstance(info, dict):
self.resource_type = info.get('resource_type') self.resource_type = info.get('resource_type')

View File

@ -14,7 +14,7 @@
# under the License. # under the License.
from oslo_utils import encodeutils from oslo_utils import encodeutils
from six.moves.urllib import parse from urllib import parse
from heatclient.common import base from heatclient.common import base
from heatclient.common import utils from heatclient.common import utils

View File

@ -18,8 +18,7 @@ import sys
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import strutils from oslo_utils import strutils
import six from urllib import request
from six.moves.urllib import request
import yaml import yaml
from heatclient._i18n import _ from heatclient._i18n import _
@ -306,7 +305,7 @@ def do_stack_delete(hc, args):
try: try:
if not args.yes and sys.stdin.isatty(): if not args.yes and sys.stdin.isatty():
prompt_response = six.moves.input( prompt_response = input(
_("Are you sure you want to delete this stack(s) [y/N]? ") _("Are you sure you want to delete this stack(s) [y/N]? ")
).lower() ).lower()
if not prompt_response.startswith('y'): if not prompt_response.startswith('y'):
@ -542,7 +541,7 @@ def do_stack_update(hc, args):
try: try:
rollback = strutils.bool_from_string(args.rollback, strict=True) rollback = strutils.bool_from_string(args.rollback, strict=True)
except ValueError as ex: except ValueError as ex:
raise exc.CommandError(six.text_type(ex)) raise exc.CommandError(str(ex))
else: else:
fields['disable_rollback'] = not(rollback) fields['disable_rollback'] = not(rollback)
# TODO(pshchelo): remove the following 'else' clause after deprecation # TODO(pshchelo): remove the following 'else' clause after deprecation
@ -1067,7 +1066,7 @@ def do_resource_signal(hc, args):
data_url = utils.normalise_file_path_to_url(data_file) data_url = utils.normalise_file_path_to_url(data_file)
data = request.urlopen(data_url).read() data = request.urlopen(data_url).read()
if data: if data:
if isinstance(data, six.binary_type): if isinstance(data, bytes):
data = data.decode('utf-8') data = data.decode('utf-8')
try: try:
data = jsonutils.loads(data) data = jsonutils.loads(data)

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse from urllib import parse
from heatclient.common import base from heatclient.common import base
from heatclient.common import utils from heatclient.common import utils

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse from urllib import parse
from heatclient.common import base from heatclient.common import base
from heatclient.common import utils from heatclient.common import utils

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse from urllib import parse
from heatclient._i18n import _ from heatclient._i18n import _
from heatclient.common import base from heatclient.common import base

View File

@ -12,7 +12,7 @@
# under the License. # under the License.
from oslo_utils import encodeutils from oslo_utils import encodeutils
from six.moves.urllib import parse from urllib import parse
from heatclient.common import base from heatclient.common import base

View File

@ -76,7 +76,6 @@ requests==2.14.2
requestsexceptions==1.2.0 requestsexceptions==1.2.0
rfc3986==0.3.1 rfc3986==0.3.1
simplejson==3.5.1 simplejson==3.5.1
six==1.10.0
snowballstemmer==1.2.1 snowballstemmer==1.2.1
stestr==2.0.0 stestr==2.0.0
stevedore==1.20.0 stevedore==1.20.0

View File

@ -15,4 +15,3 @@ keystoneauth1>=3.8.0 # Apache-2.0
python-swiftclient>=3.2.0 # Apache-2.0 python-swiftclient>=3.2.0 # Apache-2.0
PyYAML>=3.13 # MIT PyYAML>=3.13 # MIT
requests>=2.14.2 # Apache-2.0 requests>=2.14.2 # Apache-2.0
six>=1.10.0 # MIT