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 2 of a serie of 28 patches Change-Id: I2795dee87f0e27b64820686acfc614ac2ba19a4f
This commit is contained in:
parent
991e967846
commit
bb02b2b5f1
@ -15,8 +15,7 @@
|
|||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
from urllib import parse
|
||||||
from six.moves.urllib import parse
|
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
|
||||||
from heat.api.openstack.v1 import util
|
from heat.api.openstack.v1 import util
|
||||||
@ -79,7 +78,7 @@ class InstantiationData(object):
|
|||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
except ValueError as parse_ex:
|
except ValueError as parse_ex:
|
||||||
mdict = {'type': data_type, 'error': six.text_type(parse_ex)}
|
mdict = {'type': data_type, 'error': str(parse_ex)}
|
||||||
msg = _("%(type)s not in valid format: %(error)s") % mdict
|
msg = _("%(type)s not in valid format: %(error)s") % mdict
|
||||||
raise exc.HTTPBadRequest(msg)
|
raise exc.HTTPBadRequest(msg)
|
||||||
|
|
||||||
@ -101,7 +100,7 @@ class InstantiationData(object):
|
|||||||
try:
|
try:
|
||||||
adopt_data = template_format.simple_parse(adopt_data)
|
adopt_data = template_format.simple_parse(adopt_data)
|
||||||
template_format.validate_template_limit(
|
template_format.validate_template_limit(
|
||||||
six.text_type(adopt_data['template']))
|
str(adopt_data['template']))
|
||||||
return adopt_data['template']
|
return adopt_data['template']
|
||||||
except (ValueError, KeyError) as ex:
|
except (ValueError, KeyError) as ex:
|
||||||
err_reason = _('Invalid adopt data: %s') % ex
|
err_reason = _('Invalid adopt data: %s') % ex
|
||||||
@ -109,7 +108,7 @@ class InstantiationData(object):
|
|||||||
elif self.PARAM_TEMPLATE in self.data:
|
elif self.PARAM_TEMPLATE in self.data:
|
||||||
template_data = self.data[self.PARAM_TEMPLATE]
|
template_data = self.data[self.PARAM_TEMPLATE]
|
||||||
if isinstance(template_data, dict):
|
if isinstance(template_data, dict):
|
||||||
template_format.validate_template_limit(six.text_type(
|
template_format.validate_template_limit(str(
|
||||||
template_data))
|
template_data))
|
||||||
return template_data
|
return template_data
|
||||||
|
|
||||||
@ -188,7 +187,7 @@ class StackController(object):
|
|||||||
try:
|
try:
|
||||||
return param_utils.extract_bool(name, value)
|
return param_utils.extract_bool(name, value)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise exc.HTTPBadRequest(six.text_type(e))
|
raise exc.HTTPBadRequest(str(e))
|
||||||
|
|
||||||
def _extract_int_param(self, name, value,
|
def _extract_int_param(self, name, value,
|
||||||
allow_zero=True, allow_negative=False):
|
allow_zero=True, allow_negative=False):
|
||||||
@ -196,13 +195,13 @@ class StackController(object):
|
|||||||
return param_utils.extract_int(name, value,
|
return param_utils.extract_int(name, value,
|
||||||
allow_zero, allow_negative)
|
allow_zero, allow_negative)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise exc.HTTPBadRequest(six.text_type(e))
|
raise exc.HTTPBadRequest(str(e))
|
||||||
|
|
||||||
def _extract_tags_param(self, tags):
|
def _extract_tags_param(self, tags):
|
||||||
try:
|
try:
|
||||||
return param_utils.extract_tags(tags)
|
return param_utils.extract_tags(tags)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise exc.HTTPBadRequest(six.text_type(e))
|
raise exc.HTTPBadRequest(str(e))
|
||||||
|
|
||||||
def _index(self, req, use_admin_cnxt=False):
|
def _index(self, req, use_admin_cnxt=False):
|
||||||
filter_whitelist = {
|
filter_whitelist = {
|
||||||
@ -392,7 +391,7 @@ class StackController(object):
|
|||||||
if not is_update and key in args:
|
if not is_update and key in args:
|
||||||
msg = _("%s flag only supported in stack update (or update "
|
msg = _("%s flag only supported in stack update (or update "
|
||||||
"preview) request.") % key
|
"preview) request.") % key
|
||||||
raise exc.HTTPBadRequest(six.text_type(msg))
|
raise exc.HTTPBadRequest(str(msg))
|
||||||
return args
|
return args
|
||||||
|
|
||||||
@util.registered_policy_enforce
|
@util.registered_policy_enforce
|
||||||
@ -700,7 +699,7 @@ class StackController(object):
|
|||||||
req.params.get(rpc_api.TEMPLATE_TYPE))
|
req.params.get(rpc_api.TEMPLATE_TYPE))
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
msg = _("Template type is not supported: %s") % ex
|
msg = _("Template type is not supported: %s") % ex
|
||||||
raise exc.HTTPBadRequest(six.text_type(msg))
|
raise exc.HTTPBadRequest(str(msg))
|
||||||
|
|
||||||
return self.rpc_client.generate_template(req.context,
|
return self.rpc_client.generate_template(req.context,
|
||||||
type_name,
|
type_name,
|
||||||
@ -753,10 +752,7 @@ class StackSerializer(serializers.JSONResponseSerializer):
|
|||||||
|
|
||||||
def _populate_response_header(self, response, location, status):
|
def _populate_response_header(self, response, location, status):
|
||||||
response.status = status
|
response.status = status
|
||||||
if six.PY2:
|
response.headers['Location'] = location
|
||||||
response.headers['Location'] = location.encode('utf-8')
|
|
||||||
else:
|
|
||||||
response.headers['Location'] = location
|
|
||||||
response.headers['Content-Type'] = 'application/json'
|
response.headers['Content-Type'] = 'application/json'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -764,7 +760,7 @@ class StackSerializer(serializers.JSONResponseSerializer):
|
|||||||
self._populate_response_header(response,
|
self._populate_response_header(response,
|
||||||
result['stack']['links'][0]['href'],
|
result['stack']['links'][0]['href'],
|
||||||
201)
|
201)
|
||||||
response.body = six.b(self.to_json(result))
|
response.body = self.to_json(result).encode('latin-1')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
import functools
|
||||||
|
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
@ -41,7 +42,7 @@ def registered_policy_enforce(handler):
|
|||||||
|
|
||||||
|
|
||||||
def _policy_enforce(handler, is_registered_policy=False):
|
def _policy_enforce(handler, is_registered_policy=False):
|
||||||
@six.wraps(handler)
|
@functools.wraps(handler)
|
||||||
def handle_stack_method(controller, req, tenant_id, **kwargs):
|
def handle_stack_method(controller, req, tenant_id, **kwargs):
|
||||||
if req.context.tenant_id != tenant_id and not req.context.is_admin:
|
if req.context.tenant_id != tenant_id and not req.context.is_admin:
|
||||||
raise exc.HTTPForbidden()
|
raise exc.HTTPForbidden()
|
||||||
@ -77,7 +78,7 @@ def registered_identified_stack(handler):
|
|||||||
|
|
||||||
def _identified_stack(handler, is_registered_policy=False):
|
def _identified_stack(handler, is_registered_policy=False):
|
||||||
|
|
||||||
@six.wraps(handler)
|
@functools.wraps(handler)
|
||||||
def handle_stack_method(controller, req, stack_name, stack_id, **kwargs):
|
def handle_stack_method(controller, req, stack_name, stack_id, **kwargs):
|
||||||
stack_identity = identifier.HeatIdentifier(req.context.tenant_id,
|
stack_identity = identifier.HeatIdentifier(req.context.tenant_id,
|
||||||
stack_name,
|
stack_name,
|
||||||
@ -126,7 +127,7 @@ def get_allowed_params(params, whitelist):
|
|||||||
"""
|
"""
|
||||||
allowed_params = {}
|
allowed_params = {}
|
||||||
|
|
||||||
for key, get_type in six.iteritems(whitelist):
|
for key, get_type in whitelist.items():
|
||||||
assert get_type in PARAM_TYPES
|
assert get_type in PARAM_TYPES
|
||||||
|
|
||||||
value = None
|
value = None
|
||||||
|
@ -11,7 +11,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 as urlparse
|
from urllib import parse as urlparse
|
||||||
|
|
||||||
|
|
||||||
def get_collection_links(request, items):
|
def get_collection_links(request, items):
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
"""Controller that returns information on the heat API versions."""
|
"""Controller that returns information on the heat API versions."""
|
||||||
|
|
||||||
|
import http.client
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
|
||||||
from six.moves import http_client
|
|
||||||
import webob.dec
|
import webob.dec
|
||||||
|
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ class Controller(object):
|
|||||||
body = jsonutils.dumps(dict(versions=version_objs))
|
body = jsonutils.dumps(dict(versions=version_objs))
|
||||||
|
|
||||||
response = webob.Response(request=req,
|
response = webob.Response(request=req,
|
||||||
status=http_client.MULTIPLE_CHOICES,
|
status=http.client.MULTIPLE_CHOICES,
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
# NOTE(pas-ha) in WebOb, Response.body accepts only bytes,
|
# NOTE(pas-ha) in WebOb, Response.body accepts only bytes,
|
||||||
# and Response.text accepts only unicode.
|
# and Response.text accepts only unicode.
|
||||||
response.text = six.text_type(body)
|
response.text = str(body)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ from oslo_config import cfg
|
|||||||
import oslo_i18n as i18n
|
import oslo_i18n as i18n
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_service import systemd
|
from oslo_service import systemd
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.cmd import api
|
from heat.cmd import api
|
||||||
from heat.cmd import api_cfn
|
from heat.cmd import api_cfn
|
||||||
@ -86,5 +85,5 @@ def main():
|
|||||||
systemd.notify_once()
|
systemd.notify_once()
|
||||||
[service.wait() for service in services]
|
[service.wait() for service in services]
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
msg = six.text_type(e)
|
msg = str(e)
|
||||||
sys.exit("ERROR: %s" % msg)
|
sys.exit("ERROR: %s" % msg)
|
||||||
|
@ -28,7 +28,6 @@ import oslo_i18n as i18n
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_reports import guru_meditation_report as gmr
|
from oslo_reports import guru_meditation_report as gmr
|
||||||
from oslo_service import systemd
|
from oslo_service import systemd
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import config
|
from heat.common import config
|
||||||
from heat.common import messaging
|
from heat.common import messaging
|
||||||
@ -72,5 +71,5 @@ def main():
|
|||||||
systemd.notify_once()
|
systemd.notify_once()
|
||||||
server.wait()
|
server.wait()
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
msg = six.text_type(e)
|
msg = str(e)
|
||||||
sys.exit("ERROR: %s" % msg)
|
sys.exit("ERROR: %s" % msg)
|
||||||
|
@ -30,7 +30,6 @@ import oslo_i18n as i18n
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_reports import guru_meditation_report as gmr
|
from oslo_reports import guru_meditation_report as gmr
|
||||||
from oslo_service import systemd
|
from oslo_service import systemd
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import config
|
from heat.common import config
|
||||||
from heat.common import messaging
|
from heat.common import messaging
|
||||||
@ -76,5 +75,5 @@ def main():
|
|||||||
systemd.notify_once()
|
systemd.notify_once()
|
||||||
server.wait()
|
server.wait()
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
msg = six.text_type(e)
|
msg = str(e)
|
||||||
sys.exit("ERROR: %s" % msg)
|
sys.exit("ERROR: %s" % msg)
|
||||||
|
@ -19,7 +19,6 @@ import sys
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from six import moves
|
|
||||||
|
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
@ -106,7 +105,7 @@ def do_reset_stack_status():
|
|||||||
"intended to recover from specific crashes."))
|
"intended to recover from specific crashes."))
|
||||||
print(_("It is advised to shutdown all Heat engines beforehand."))
|
print(_("It is advised to shutdown all Heat engines beforehand."))
|
||||||
print(_("Continue ? [y/N]"))
|
print(_("Continue ? [y/N]"))
|
||||||
data = moves.input()
|
data = input()
|
||||||
if not data.lower().startswith('y'):
|
if not data.lower().startswith('y'):
|
||||||
return
|
return
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import functools
|
||||||
|
|
||||||
from keystoneauth1 import access
|
from keystoneauth1 import access
|
||||||
from keystoneauth1.identity import access as access_plugin
|
from keystoneauth1.identity import access as access_plugin
|
||||||
from keystoneauth1.identity import generic
|
from keystoneauth1.identity import generic
|
||||||
@ -23,7 +25,6 @@ from oslo_log import log as logging
|
|||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
from oslo_middleware import request_id as oslo_request_id
|
from oslo_middleware import request_id as oslo_request_id
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import config
|
from heat.common import config
|
||||||
from heat.common import endpoint_utils
|
from heat.common import endpoint_utils
|
||||||
@ -407,7 +408,7 @@ def ContextMiddleware_filter_factory(global_conf, **local_conf):
|
|||||||
|
|
||||||
|
|
||||||
def request_context(func):
|
def request_context(func):
|
||||||
@six.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapped(self, ctx, *args, **kwargs):
|
def wrapped(self, ctx, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return func(self, ctx, *args, **kwargs)
|
return func(self, ctx, *args, **kwargs)
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
import collections
|
import collections
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import environment_format as env_fmt
|
from heat.common import environment_format as env_fmt
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
@ -62,10 +61,10 @@ def merge_map(old, new, deep_merge=False):
|
|||||||
old_v = old.get(k)
|
old_v = old.get(k)
|
||||||
old[k] = merge_map(old_v, v, deep_merge) if old_v else v
|
old[k] = merge_map(old_v, v, deep_merge) if old_v else v
|
||||||
elif (isinstance(v, collections.Sequence) and
|
elif (isinstance(v, collections.Sequence) and
|
||||||
not isinstance(v, six.string_types)):
|
not isinstance(v, str)):
|
||||||
old_v = old.get(k)
|
old_v = old.get(k)
|
||||||
old[k] = merge_list(old_v, v) if old_v else v
|
old[k] = merge_list(old_v, v) if old_v else v
|
||||||
elif isinstance(v, six.string_types):
|
elif isinstance(v, str):
|
||||||
old[k] = ''.join([old.get(k, ''), v])
|
old[k] = ''.join([old.get(k, ''), v])
|
||||||
else:
|
else:
|
||||||
old[k] = v
|
old[k] = v
|
||||||
@ -76,14 +75,14 @@ def merge_map(old, new, deep_merge=False):
|
|||||||
def parse_param(p_val, p_schema):
|
def parse_param(p_val, p_schema):
|
||||||
try:
|
try:
|
||||||
if p_schema.type == p_schema.MAP:
|
if p_schema.type == p_schema.MAP:
|
||||||
if not isinstance(p_val, six.string_types):
|
if not isinstance(p_val, str):
|
||||||
p_val = jsonutils.dumps(p_val)
|
p_val = jsonutils.dumps(p_val)
|
||||||
if p_val:
|
if p_val:
|
||||||
return jsonutils.loads(p_val)
|
return jsonutils.loads(p_val)
|
||||||
elif not isinstance(p_val, collections.Sequence):
|
elif not isinstance(p_val, collections.Sequence):
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except (ValueError, TypeError) as err:
|
except (ValueError, TypeError) as err:
|
||||||
msg = _("Invalid parameter in environment %s.") % six.text_type(err)
|
msg = _("Invalid parameter in environment %s.") % str(err)
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
return p_val
|
return p_val
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user