Remove six and python 2.7 full support

Six is in use to help us to keep support for python 2.7.
Since the ussuri cycle we decide to remove the python 2.7
support so we can go ahead and also remove six usage from
the python code.

Review process and help
-----------------------
Removing six introduce a lot of changes and an huge amount of modified files
To simplify reviews we decided to split changes into several patches to avoid
painful reviews and avoid mistakes.

To review this patch you can use the six documentation [1] to obtain help and
understand choices.

Additional informations
-----------------------
Changes related to 'six.b(data)' [2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

six.b [2] encode the given datas in latin-1 in python3 so I did the same
things in this patch.

Latin-1 is equal to iso-8859-1 [3].

This encoding is the default encoding [4] of certain descriptive HTTP
headers.

I suggest to keep latin-1 for the moment and to move to another encoding
in a follow-up patch if needed to move to most powerful encoding (utf8).

HTML4 support utf8 charset and utf8 is the default charset for HTML5 [5].

Note that this commit message is autogenerated and not necesserly contains
changes related to 'six.b'

[1] https://six.readthedocs.io/
[2] https://six.readthedocs.io/#six.b
[3] https://docs.python.org/3/library/codecs.html#standard-encodings
[4] https://www.w3schools.com/charsets/ref_html_8859.asp
[5] https://www.w3schools.com/html/html_charset.asp

Patch 1 of a serie of 28 patches

Change-Id: Ia310a58ffdc688302b32d57a6bef6b1b8f5d9950
This commit is contained in:
Hervé Beraud 2019-11-20 19:37:25 +01:00
parent c9eaca9e59
commit 991e967846
10 changed files with 13 additions and 23 deletions

View File

@ -17,7 +17,6 @@
import distutils
from oslo_log import log as logging
import six
from heat.common import exception
from heat.common.i18n import _
@ -340,7 +339,7 @@ class DockerContainer(resource.Resource):
def _parse_networkinfo_ports(self, networkinfo):
tcp = []
udp = []
for port, info in six.iteritems(networkinfo['Ports']):
for port, info in networkinfo['Ports'].items():
p = port.split('/')
if not info or len(p) != 2 or 'HostPort' not in info[0]:
continue

View File

@ -15,7 +15,6 @@
# under the License.
import mock
import six
from heat.common import exception
from heat.common.i18n import _
@ -126,7 +125,7 @@ class DockerContainerTest(common.HeatTestCase):
exc = self.assertRaises(exception.ResourceInError,
docker_res.check_create_complete,
'foo')
self.assertIn("Container startup failed", six.text_type(exc))
self.assertIn("Container startup failed", str(exc))
def test_start_with_bindings_and_links(self):
t = template_format.parse(template)
@ -331,7 +330,7 @@ class DockerContainerTest(common.HeatTestCase):
args = dict(arg=arg, min_version=min_version)
expected = _('"%(arg)s" is not supported for API version '
'< "%(min_version)s"') % args
self.assertEqual(expected, six.text_type(msg))
self.assertEqual(expected, str(msg))
def test_start_with_read_only_for_low_api_version(self):
self.arg_for_low_api_version('read_only', True, '1.16')

View File

@ -19,7 +19,6 @@ import pydoc
from docutils import core
from docutils import nodes
from docutils.parsers import rst
import six
from heat.common.i18n import _
from heat.engine import attributes
@ -433,7 +432,7 @@ def _filter_resources(prefix=None, path=None, statuses=None):
else:
filtered_resources[name] = [cls]
return sorted(six.iteritems(filtered_resources))
return sorted(filtered_resources.items())
def _load_all_resources():

View File

@ -17,7 +17,6 @@
"""Heat API exception subclasses - maps API response errors to AWS Errors."""
from oslo_utils import reflection
import six
import webob.exc
from heat.common.i18n import _
@ -322,7 +321,7 @@ def map_remote_error(ex):
ex_type = ex_type[:-len('_Remote')]
safe = getattr(ex, 'safe', False)
detail = six.text_type(ex) if safe else None
detail = str(ex) if safe else None
if ex_type in inval_param_errors:
return HeatInvalidParameterValueError(detail=detail)

View File

@ -24,7 +24,6 @@ import traceback
from oslo_config import cfg
from oslo_utils import reflection
import six
import webob
from heat.common import exception
@ -127,7 +126,7 @@ class FaultWrapper(wsgi.Middleware):
if is_remote:
ex_type = ex_type[:-len('_Remote')]
full_message = six.text_type(ex)
full_message = str(ex)
if '\n' in full_message and is_remote:
message, msg_trace = full_message.split('\n', 1)
elif traceback_marker in full_message:

View File

@ -12,7 +12,6 @@
# under the License.
import routes
import six
from heat.api.openstack.v1 import actions
from heat.api.openstack.v1 import build_info
@ -51,7 +50,7 @@ class API(wsgi.Router):
for r in routes:
url = path_prefix + r['url']
methods = r['method']
if isinstance(methods, six.string_types):
if isinstance(methods, str):
methods = [methods]
methods_str = ','.join(methods)
mapper.connect(r['name'], url, controller=controller,

View File

@ -11,7 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from webob import exc
from heat.api.openstack.v1 import util
@ -57,7 +56,7 @@ class ActionController(object):
if len(body) > 1:
raise exc.HTTPBadRequest(_("Multiple actions specified"))
ac = next(six.iterkeys(body))
ac = next(iter(body.keys()))
if ac not in self.ACTIONS:
raise exc.HTTPBadRequest(_("Invalid action %s specified") % ac)

View File

@ -13,7 +13,6 @@
import itertools
import six
from webob import exc
from heat.api.openstack.v1 import util
@ -133,7 +132,7 @@ class EventController(object):
params[key] = param_utils.extract_int(
key, params[key], allow_zero=True)
except ValueError as e:
raise exc.HTTPBadRequest(six.text_type(e))
raise exc.HTTPBadRequest(str(e))
if resource_name is None:
if not filter_params:

View File

@ -13,7 +13,6 @@
import itertools
import six
from webob import exc
from heat.api.openstack.v1 import util
@ -89,7 +88,7 @@ class ResourceController(object):
try:
return extractor(key, req.params[key])
except ValueError as e:
raise exc.HTTPBadRequest(six.text_type(e))
raise exc.HTTPBadRequest(str(e))
else:
return default
@ -111,7 +110,7 @@ class ResourceController(object):
rpc_api.PARAM_WITH_DETAIL]))
if invalid_keys:
raise exc.HTTPBadRequest(_('Invalid filter parameters %s') %
six.text_type(list(invalid_keys)))
str(list(invalid_keys)))
nested_depth = self._extract_to_param(req,
rpc_api.PARAM_NESTED_DEPTH,
@ -186,7 +185,7 @@ class ResourceController(object):
RES_UPDATE_MARK_UNHEALTHY,
body[RES_UPDATE_MARK_UNHEALTHY])
except ValueError as e:
raise exc.HTTPBadRequest(six.text_type(e))
raise exc.HTTPBadRequest(str(e))
data[RES_UPDATE_STATUS_REASON] = body.get(RES_UPDATE_STATUS_REASON, "")
self.rpc_client.resource_mark_unhealthy(req.context,

View File

@ -11,7 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from webob import exc
from heat.api.openstack.v1 import util
@ -42,7 +41,7 @@ class SoftwareConfigController(object):
try:
return param_utils.extract_bool(name, value)
except ValueError as e:
raise exc.HTTPBadRequest(six.text_type(e))
raise exc.HTTPBadRequest(str(e))
def _index(self, req, use_admin_cnxt=False):
whitelist = {