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 10 of a serie of 28 patches

Change-Id: Ic745ceced9989497c489f3df3ee9ff84fe507b88
This commit is contained in:
Hervé Beraud 2019-11-20 19:37:26 +01:00
parent 3e28c8e76b
commit e6a6468eef
10 changed files with 16 additions and 29 deletions

View File

@ -15,8 +15,6 @@ import collections
import copy
import functools
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import constraints
@ -150,8 +148,8 @@ class StructuredDeployment(sd.SoftwareDeployment):
def get_input_key_arg(snippet, input_key):
if len(snippet) != 1:
return None
fn_name, fn_arg = next(six.iteritems(snippet))
if (fn_name == input_key and isinstance(fn_arg, six.string_types)):
fn_name, fn_arg = next(iter(snippet.items()))
if (fn_name == input_key and isinstance(fn_arg, str)):
return fn_arg
@staticmethod
@ -175,8 +173,8 @@ class StructuredDeployment(sd.SoftwareDeployment):
check_input_val
)
return dict((k, parse(v)) for k, v in six.iteritems(snippet))
elif (not isinstance(snippet, six.string_types) and
return dict((k, parse(v)) for k, v in snippet.items())
elif (not isinstance(snippet, str) and
isinstance(snippet, collections.Iterable)):
return [parse(v) for v in snippet]
else:

View File

@ -14,8 +14,7 @@
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import timeutils
import six
from six.moves.urllib import parse
from urllib import parse
from heat.common import exception
from heat.common.i18n import _
@ -344,7 +343,7 @@ class SwiftSignal(resource.Resource):
def _resolve_attribute(self, key):
if key == self.DATA:
return six.text_type(jsonutils.dumps(self.get_data()))
return str(jsonutils.dumps(self.get_data()))
def resource_mapping():

View File

@ -14,7 +14,6 @@
import datetime
import eventlet
from oslo_utils import timeutils
import six
from heat.common.i18n import _
from heat.engine import attributes
@ -218,12 +217,12 @@ class TestResource(resource.Resource):
obj.get(entity_id)
except Exception as exc:
LOG.debug('%s.%s(%s) %s' % (client_name, self.entity,
entity_id, six.text_type(exc)))
entity_id, str(exc)))
else:
# just sleep some more
eventlet.sleep(1)
if isinstance(started_at, six.string_types):
if isinstance(started_at, str):
started_at = timeutils.parse_isotime(started_at)
started_at = timeutils.normalize_time(started_at)

View File

@ -14,7 +14,6 @@
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import timeutils
import six
from heat.common.i18n import _
from heat.engine import attributes
@ -158,7 +157,7 @@ class HeatWaitCondition(resource.Resource):
'key': key,
'res': res})
return six.text_type(jsonutils.dumps(res))
return str(jsonutils.dumps(res))
def resource_mapping():

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from six.moves.urllib import parse
from urllib import parse
from heat.common.i18n import _
from heat.engine import constraints

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import constraints
@ -129,7 +127,7 @@ class Bay(resource.Resource):
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
patch = [{'op': 'replace', 'path': '/' + k, 'value': v}
for k, v in six.iteritems(prop_diff)]
for k, v in prop_diff.items()]
self.client().bays.update(self.resource_id, patch)
return self.resource_id

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import attributes
@ -218,7 +216,7 @@ class Cluster(resource.Resource):
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
patch = [{'op': 'replace', 'path': '/' + k, 'value': v}
for k, v in six.iteritems(prop_diff)]
for k, v in prop_diff.items()]
self.client().clusters.update(self.resource_id, patch)
return self.resource_id

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import constraints
@ -290,7 +288,7 @@ class ClusterTemplate(resource.Resource):
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
patch = [{'op': 'replace', 'path': '/' + k, 'value': v}
for k, v in six.iteritems(prop_diff)]
for k, v in prop_diff.items()]
self.client().cluster_templates.update(self.resource_id, patch)
return self.resource_id

View File

@ -13,7 +13,6 @@
from oslo_log import log as logging
from oslo_utils import encodeutils
import six
from heat.common import exception
from heat.common.i18n import _
@ -197,7 +196,7 @@ class ManilaShare(resource.Resource):
if self.resource_id is None:
return
share = self._request_share()
return six.text_type(getattr(share, name))
return str(getattr(share, name))
def handle_create(self):
# Request IDs of entities from manila
@ -345,7 +344,7 @@ class ManilaShare(resource.Resource):
result[self.ACCESS_RULES] = []
for rule in rules:
result[self.ACCESS_RULES].append(
{(k, v) for (k, v) in six.iteritems(rule)
{(k, v) for (k, v) in rule.items()
if k in self._ACCESS_RULE_PROPERTIES})
return result

View File

@ -13,7 +13,6 @@
from oslo_log import log as logging
from oslo_serialization import jsonutils
import six
from heat.common import exception
from heat.common.i18n import _
@ -212,7 +211,7 @@ class MistralExternalResource(resource.Resource):
LOG.debug('ExternalResource id set to %(rid)s from Mistral '
'execution %(eid)s output' % {'eid': execution_id,
'rid': rsrc_id})
self.resource_id_set(six.text_type(rsrc_id)[:255])
self.resource_id_set(str(rsrc_id)[:255])
return success
def _resolve_attribute(self, name):