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 6 of a serie of 28 patches Change-Id: Ic56cf6da5ff9ab8f4bd218e6516b87f47165206d
This commit is contained in:
parent
6ccd16cc32
commit
8c0d58075b
@ -14,8 +14,6 @@
|
|||||||
import collections
|
import collections
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
|
|
||||||
@ -24,7 +22,6 @@ class CircularDependencyException(exception.HeatException):
|
|||||||
msg_fmt = _("Circular Dependency Found: %(cycle)s")
|
msg_fmt = _("Circular Dependency Found: %(cycle)s")
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Node(object):
|
class Node(object):
|
||||||
"""A node in a dependency graph."""
|
"""A node in a dependency graph."""
|
||||||
|
|
||||||
@ -92,15 +89,14 @@ class Node(object):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return a human-readable string representation of the node."""
|
"""Return a human-readable string representation of the node."""
|
||||||
text = '{%s}' % ', '.join(six.text_type(n) for n in self)
|
text = '{%s}' % ', '.join(str(n) for n in self)
|
||||||
return six.text_type(text)
|
return str(text)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Return a string representation of the node."""
|
"""Return a string representation of the node."""
|
||||||
return repr(self.require)
|
return repr(self.require)
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Graph(collections.defaultdict):
|
class Graph(collections.defaultdict):
|
||||||
"""A mutable mapping of objects to nodes in a dependency graph."""
|
"""A mutable mapping of objects to nodes in a dependency graph."""
|
||||||
|
|
||||||
@ -132,7 +128,7 @@ class Graph(collections.defaultdict):
|
|||||||
for rqd in node:
|
for rqd in node:
|
||||||
yield (rqr, rqd)
|
yield (rqr, rqd)
|
||||||
return itertools.chain.from_iterable(outgoing_edges(*i)
|
return itertools.chain.from_iterable(outgoing_edges(*i)
|
||||||
for i in six.iteritems(self))
|
for i in self.items())
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
"""Delete the node given by the specified key from the graph."""
|
"""Delete the node given by the specified key from the graph."""
|
||||||
@ -147,10 +143,10 @@ class Graph(collections.defaultdict):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Convert the graph to a human-readable string."""
|
"""Convert the graph to a human-readable string."""
|
||||||
pairs = ('%s: %s' % (six.text_type(k), six.text_type(v))
|
pairs = ('%s: %s' % (str(k), str(v))
|
||||||
for k, v in six.iteritems(self))
|
for k, v in self.items())
|
||||||
text = '{%s}' % ', '.join(pairs)
|
text = '{%s}' % ', '.join(pairs)
|
||||||
return six.text_type(text)
|
return str(text)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def toposort(graph):
|
def toposort(graph):
|
||||||
@ -158,8 +154,8 @@ class Graph(collections.defaultdict):
|
|||||||
|
|
||||||
This is a destructive operation for the graph.
|
This is a destructive operation for the graph.
|
||||||
"""
|
"""
|
||||||
for iteration in six.moves.xrange(len(graph)):
|
for iteration in range(len(graph)):
|
||||||
for key, node in six.iteritems(graph):
|
for key, node in graph.items():
|
||||||
if not node:
|
if not node:
|
||||||
yield key
|
yield key
|
||||||
del graph[key]
|
del graph[key]
|
||||||
@ -167,10 +163,9 @@ class Graph(collections.defaultdict):
|
|||||||
else:
|
else:
|
||||||
# There are nodes remaining, but none without
|
# There are nodes remaining, but none without
|
||||||
# dependencies: a cycle
|
# dependencies: a cycle
|
||||||
raise CircularDependencyException(cycle=six.text_type(graph))
|
raise CircularDependencyException(cycle=str(graph))
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Dependencies(object):
|
class Dependencies(object):
|
||||||
"""Helper class for calculating a dependency graph."""
|
"""Helper class for calculating a dependency graph."""
|
||||||
|
|
||||||
@ -227,8 +222,8 @@ class Dependencies(object):
|
|||||||
return itertools.chain([(rqr, key)], get_edges(rqr))
|
return itertools.chain([(rqr, key)], get_edges(rqr))
|
||||||
|
|
||||||
# Get the edge list for each node that requires the current node
|
# Get the edge list for each node that requires the current node
|
||||||
edge_lists = six.moves.map(requirer_edges,
|
edge_lists = map(requirer_edges,
|
||||||
self._graph[key].required_by())
|
self._graph[key].required_by())
|
||||||
# Combine the lists into one long list
|
# Combine the lists into one long list
|
||||||
return itertools.chain.from_iterable(edge_lists)
|
return itertools.chain.from_iterable(edge_lists)
|
||||||
|
|
||||||
@ -263,7 +258,7 @@ class Dependencies(object):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return a human-readable string repr of the dependency graph."""
|
"""Return a human-readable string repr of the dependency graph."""
|
||||||
return six.text_type(self._graph)
|
return str(self._graph)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Return a consistent string representation of the object."""
|
"""Return a consistent string representation of the object."""
|
||||||
|
@ -21,7 +21,6 @@ import weakref
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import fnmatch
|
from oslo_utils import fnmatch
|
||||||
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
|
||||||
@ -54,7 +53,7 @@ def valid_restricted_actions(action):
|
|||||||
def is_hook_definition(key, value):
|
def is_hook_definition(key, value):
|
||||||
is_valid_hook = False
|
is_valid_hook = False
|
||||||
if key == 'hooks':
|
if key == 'hooks':
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
is_valid_hook = valid_hook_type(value)
|
is_valid_hook = valid_hook_type(value)
|
||||||
elif isinstance(value, collections.Sequence):
|
elif isinstance(value, collections.Sequence):
|
||||||
is_valid_hook = all(valid_hook_type(hook) for hook in value)
|
is_valid_hook = all(valid_hook_type(hook) for hook in value)
|
||||||
@ -71,7 +70,7 @@ def is_hook_definition(key, value):
|
|||||||
def is_valid_restricted_action(key, value):
|
def is_valid_restricted_action(key, value):
|
||||||
valid_action = False
|
valid_action = False
|
||||||
if key == 'restricted_actions':
|
if key == 'restricted_actions':
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
valid_action = valid_restricted_actions(value)
|
valid_action = valid_restricted_actions(value)
|
||||||
elif isinstance(value, collections.Sequence):
|
elif isinstance(value, collections.Sequence):
|
||||||
valid_action = all(valid_restricted_actions(
|
valid_action = all(valid_restricted_actions(
|
||||||
@ -101,7 +100,7 @@ class ResourceInfo(object):
|
|||||||
if name.endswith(('.yaml', '.template')):
|
if name.endswith(('.yaml', '.template')):
|
||||||
# a template url for the resource "Type"
|
# a template url for the resource "Type"
|
||||||
klass = TemplateResourceInfo
|
klass = TemplateResourceInfo
|
||||||
elif not isinstance(value, six.string_types):
|
elif not isinstance(value, str):
|
||||||
klass = ClassResourceInfo
|
klass = ClassResourceInfo
|
||||||
elif value.endswith(('.yaml', '.template')):
|
elif value.endswith(('.yaml', '.template')):
|
||||||
# a registered template
|
# a registered template
|
||||||
@ -344,10 +343,8 @@ class ResourceRegistry(object):
|
|||||||
if info.value.support_status.message is not None:
|
if info.value.support_status.message is not None:
|
||||||
details = {
|
details = {
|
||||||
'name': info.name,
|
'name': info.name,
|
||||||
'status': six.text_type(
|
'status': str(info.value.support_status.status),
|
||||||
info.value.support_status.status),
|
'message': str(info.value.support_status.message)
|
||||||
'message': six.text_type(
|
|
||||||
info.value.support_status.message)
|
|
||||||
}
|
}
|
||||||
LOG.warning('%(name)s is %(status)s. %(message)s',
|
LOG.warning('%(name)s is %(status)s. %(message)s',
|
||||||
details)
|
details)
|
||||||
@ -364,7 +361,7 @@ class ResourceRegistry(object):
|
|||||||
if show_all or isinstance(registry[name], TemplateResourceInfo):
|
if show_all or isinstance(registry[name], TemplateResourceInfo):
|
||||||
msg = ('%(p)sRegistered: %(t)s' %
|
msg = ('%(p)sRegistered: %(t)s' %
|
||||||
{'p': prefix,
|
{'p': prefix,
|
||||||
't': six.text_type(registry[name])})
|
't': str(registry[name])})
|
||||||
LOG.info(msg)
|
LOG.info(msg)
|
||||||
|
|
||||||
def remove_item(self, info):
|
def remove_item(self, info):
|
||||||
@ -394,11 +391,11 @@ class ResourceRegistry(object):
|
|||||||
"""
|
"""
|
||||||
ress = self._registry['resources']
|
ress = self._registry['resources']
|
||||||
restricted_actions = set()
|
restricted_actions = set()
|
||||||
for name_pattern, resource in six.iteritems(ress):
|
for name_pattern, resource in ress.items():
|
||||||
if fnmatch.fnmatchcase(resource_name, name_pattern):
|
if fnmatch.fnmatchcase(resource_name, name_pattern):
|
||||||
if 'restricted_actions' in resource:
|
if 'restricted_actions' in resource:
|
||||||
actions = resource['restricted_actions']
|
actions = resource['restricted_actions']
|
||||||
if isinstance(actions, six.string_types):
|
if isinstance(actions, str):
|
||||||
restricted_actions.add(actions)
|
restricted_actions.add(actions)
|
||||||
elif isinstance(actions, collections.Sequence):
|
elif isinstance(actions, collections.Sequence):
|
||||||
restricted_actions |= set(actions)
|
restricted_actions |= set(actions)
|
||||||
@ -429,11 +426,11 @@ class ResourceRegistry(object):
|
|||||||
everything.
|
everything.
|
||||||
"""
|
"""
|
||||||
ress = self._registry['resources']
|
ress = self._registry['resources']
|
||||||
for name_pattern, resource in six.iteritems(ress):
|
for name_pattern, resource in ress.items():
|
||||||
if fnmatch.fnmatchcase(resource_name, name_pattern):
|
if fnmatch.fnmatchcase(resource_name, name_pattern):
|
||||||
if 'hooks' in resource:
|
if 'hooks' in resource:
|
||||||
hooks = resource['hooks']
|
hooks = resource['hooks']
|
||||||
if isinstance(hooks, six.string_types):
|
if isinstance(hooks, str):
|
||||||
if hook == hooks:
|
if hook == hooks:
|
||||||
return True
|
return True
|
||||||
elif isinstance(hooks, collections.Sequence):
|
elif isinstance(hooks, collections.Sequence):
|
||||||
@ -444,7 +441,7 @@ class ResourceRegistry(object):
|
|||||||
def remove_resources_except(self, resource_name):
|
def remove_resources_except(self, resource_name):
|
||||||
ress = self._registry['resources']
|
ress = self._registry['resources']
|
||||||
new_resources = {}
|
new_resources = {}
|
||||||
for name, res in six.iteritems(ress):
|
for name, res in ress.items():
|
||||||
if fnmatch.fnmatchcase(resource_name, name):
|
if fnmatch.fnmatchcase(resource_name, name):
|
||||||
new_resources.update(res)
|
new_resources.update(res)
|
||||||
if resource_name in ress:
|
if resource_name in ress:
|
||||||
@ -477,7 +474,7 @@ class ResourceRegistry(object):
|
|||||||
# handle: "OS::*" -> "Dreamhost::*"
|
# handle: "OS::*" -> "Dreamhost::*"
|
||||||
def is_a_glob(resource_type):
|
def is_a_glob(resource_type):
|
||||||
return resource_type.endswith('*')
|
return resource_type.endswith('*')
|
||||||
globs = six.moves.filter(is_a_glob, iter(self._registry))
|
globs = filter(is_a_glob, iter(self._registry))
|
||||||
for pattern in globs:
|
for pattern in globs:
|
||||||
if self._registry[pattern].matches(resource_type):
|
if self._registry[pattern].matches(resource_type):
|
||||||
yield self._registry[pattern]
|
yield self._registry[pattern]
|
||||||
@ -550,7 +547,7 @@ class ResourceRegistry(object):
|
|||||||
msg = _('Non-empty resource type is required '
|
msg = _('Non-empty resource type is required '
|
||||||
'for resource "%s"') % resource_name
|
'for resource "%s"') % resource_name
|
||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
elif not isinstance(resource_type, six.string_types):
|
elif not isinstance(resource_type, str):
|
||||||
msg = _('Resource "%s" type is not a string') % resource_name
|
msg = _('Resource "%s" type is not a string') % resource_name
|
||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
|
|
||||||
@ -558,7 +555,7 @@ class ResourceRegistry(object):
|
|||||||
info = self.get_resource_info(resource_type,
|
info = self.get_resource_info(resource_type,
|
||||||
resource_name=resource_name)
|
resource_name=resource_name)
|
||||||
except exception.EntityNotFound as exc:
|
except exception.EntityNotFound as exc:
|
||||||
raise exception.StackValidationFailed(message=six.text_type(exc))
|
raise exception.StackValidationFailed(message=str(exc))
|
||||||
|
|
||||||
return info.get_class_to_instantiate()
|
return info.get_class_to_instantiate()
|
||||||
|
|
||||||
@ -590,7 +587,7 @@ class ResourceRegistry(object):
|
|||||||
if support_status is not None and not support.is_valid_status(
|
if support_status is not None and not support.is_valid_status(
|
||||||
support_status):
|
support_status):
|
||||||
msg = (_('Invalid support status and should be one of %s') %
|
msg = (_('Invalid support status and should be one of %s') %
|
||||||
six.text_type(support.SUPPORT_STATUSES))
|
str(support.SUPPORT_STATUSES))
|
||||||
raise exception.Invalid(reason=msg)
|
raise exception.Invalid(reason=msg)
|
||||||
|
|
||||||
def is_resource(key):
|
def is_resource(key):
|
||||||
@ -650,7 +647,7 @@ class ResourceRegistry(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [resource_description(name, cls, with_description)
|
return [resource_description(name, cls, with_description)
|
||||||
for name, cls in six.iteritems(self._registry)
|
for name, cls in self._registry.items()
|
||||||
if (is_resource(name) and
|
if (is_resource(name) and
|
||||||
name_matches(name) and
|
name_matches(name) and
|
||||||
status_matches(cls) and
|
status_matches(cls) and
|
||||||
@ -693,7 +690,7 @@ class Environment(object):
|
|||||||
if env_fmt.PARAMETERS in env:
|
if env_fmt.PARAMETERS in env:
|
||||||
self.params = env[env_fmt.PARAMETERS]
|
self.params = env[env_fmt.PARAMETERS]
|
||||||
else:
|
else:
|
||||||
self.params = dict((k, v) for (k, v) in six.iteritems(env)
|
self.params = dict((k, v) for (k, v) in env.items()
|
||||||
if k not in (env_fmt.PARAMETER_DEFAULTS,
|
if k not in (env_fmt.PARAMETER_DEFAULTS,
|
||||||
env_fmt.ENCRYPTED_PARAM_NAMES,
|
env_fmt.ENCRYPTED_PARAM_NAMES,
|
||||||
env_fmt.EVENT_SINKS,
|
env_fmt.EVENT_SINKS,
|
||||||
|
@ -16,14 +16,11 @@ import collections
|
|||||||
import itertools
|
import itertools
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class Function(metaclass=abc.ABCMeta):
|
||||||
class Function(object):
|
|
||||||
"""Abstract base class for template functions."""
|
"""Abstract base class for template functions."""
|
||||||
|
|
||||||
def __init__(self, stack, fn_name, args):
|
def __init__(self, stack, fn_name, args):
|
||||||
@ -98,13 +95,13 @@ class Function(object):
|
|||||||
return all_dep_attrs(self.args)
|
return all_dep_attrs(self.args)
|
||||||
|
|
||||||
def res_dep_attrs(resource_name):
|
def res_dep_attrs(resource_name):
|
||||||
return six.moves.zip(itertools.repeat(resource_name),
|
return zip(itertools.repeat(resource_name),
|
||||||
self.dep_attrs(resource_name))
|
self.dep_attrs(resource_name))
|
||||||
|
|
||||||
resource_names = self.stack.enabled_rsrc_names()
|
resource_names = self.stack.enabled_rsrc_names()
|
||||||
|
|
||||||
return itertools.chain.from_iterable(six.moves.map(res_dep_attrs,
|
return itertools.chain.from_iterable(map(res_dep_attrs,
|
||||||
resource_names))
|
resource_names))
|
||||||
|
|
||||||
def __reduce__(self):
|
def __reduce__(self):
|
||||||
"""Return a representation of the function suitable for pickling.
|
"""Return a representation of the function suitable for pickling.
|
||||||
@ -160,8 +157,7 @@ class Function(object):
|
|||||||
__hash__ = None
|
__hash__ = None
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class Macro(Function, metaclass=abc.ABCMeta):
|
||||||
class Macro(Function):
|
|
||||||
"""Abstract base class for template macros.
|
"""Abstract base class for template macros.
|
||||||
|
|
||||||
A macro differs from a function in that it controls how the template is
|
A macro differs from a function in that it controls how the template is
|
||||||
@ -260,7 +256,7 @@ def resolve(snippet):
|
|||||||
|
|
||||||
if isinstance(snippet, collections.Mapping):
|
if isinstance(snippet, collections.Mapping):
|
||||||
return dict((k, resolve(v)) for k, v in snippet.items())
|
return dict((k, resolve(v)) for k, v in snippet.items())
|
||||||
elif (not isinstance(snippet, six.string_types) and
|
elif (not isinstance(snippet, str) and
|
||||||
isinstance(snippet, collections.Iterable)):
|
isinstance(snippet, collections.Iterable)):
|
||||||
return [resolve(v) for v in snippet]
|
return [resolve(v) for v in snippet]
|
||||||
|
|
||||||
@ -270,7 +266,7 @@ def resolve(snippet):
|
|||||||
def validate(snippet, path=None):
|
def validate(snippet, path=None):
|
||||||
if path is None:
|
if path is None:
|
||||||
path = []
|
path = []
|
||||||
elif isinstance(path, six.string_types):
|
elif isinstance(path, str):
|
||||||
path = [path]
|
path = [path]
|
||||||
|
|
||||||
if isinstance(snippet, Function):
|
if isinstance(snippet, Function):
|
||||||
@ -281,11 +277,11 @@ def validate(snippet, path=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise exception.StackValidationFailed(
|
raise exception.StackValidationFailed(
|
||||||
path=path + [snippet.fn_name],
|
path=path + [snippet.fn_name],
|
||||||
message=six.text_type(e))
|
message=str(e))
|
||||||
elif isinstance(snippet, collections.Mapping):
|
elif isinstance(snippet, collections.Mapping):
|
||||||
for k, v in six.iteritems(snippet):
|
for k, v in snippet.items():
|
||||||
validate(v, path + [k])
|
validate(v, path + [k])
|
||||||
elif (not isinstance(snippet, six.string_types) and
|
elif (not isinstance(snippet, str) and
|
||||||
isinstance(snippet, collections.Iterable)):
|
isinstance(snippet, collections.Iterable)):
|
||||||
basepath = list(path)
|
basepath = list(path)
|
||||||
parent = basepath.pop() if basepath else ''
|
parent = basepath.pop() if basepath else ''
|
||||||
@ -305,13 +301,13 @@ def dependencies(snippet, path=''):
|
|||||||
|
|
||||||
elif isinstance(snippet, collections.Mapping):
|
elif isinstance(snippet, collections.Mapping):
|
||||||
def mkpath(key):
|
def mkpath(key):
|
||||||
return '.'.join([path, six.text_type(key)])
|
return '.'.join([path, str(key)])
|
||||||
|
|
||||||
deps = (dependencies(value,
|
deps = (dependencies(value,
|
||||||
mkpath(key)) for key, value in snippet.items())
|
mkpath(key)) for key, value in snippet.items())
|
||||||
return itertools.chain.from_iterable(deps)
|
return itertools.chain.from_iterable(deps)
|
||||||
|
|
||||||
elif (not isinstance(snippet, six.string_types) and
|
elif (not isinstance(snippet, str) and
|
||||||
isinstance(snippet, collections.Iterable)):
|
isinstance(snippet, collections.Iterable)):
|
||||||
def mkpath(idx):
|
def mkpath(idx):
|
||||||
return ''.join([path, '[%d]' % idx])
|
return ''.join([path, '[%d]' % idx])
|
||||||
@ -340,7 +336,7 @@ def dep_attrs(snippet, resource_name):
|
|||||||
elif isinstance(snippet, collections.Mapping):
|
elif isinstance(snippet, collections.Mapping):
|
||||||
attrs = (dep_attrs(val, resource_name) for val in snippet.values())
|
attrs = (dep_attrs(val, resource_name) for val in snippet.values())
|
||||||
return itertools.chain.from_iterable(attrs)
|
return itertools.chain.from_iterable(attrs)
|
||||||
elif (not isinstance(snippet, six.string_types) and
|
elif (not isinstance(snippet, str) and
|
||||||
isinstance(snippet, collections.Iterable)):
|
isinstance(snippet, collections.Iterable)):
|
||||||
attrs = (dep_attrs(value, resource_name) for value in snippet)
|
attrs = (dep_attrs(value, resource_name) for value in snippet)
|
||||||
return itertools.chain.from_iterable(attrs)
|
return itertools.chain.from_iterable(attrs)
|
||||||
@ -363,7 +359,7 @@ def all_dep_attrs(snippet):
|
|||||||
elif isinstance(snippet, collections.Mapping):
|
elif isinstance(snippet, collections.Mapping):
|
||||||
res_attrs = (all_dep_attrs(value) for value in snippet.values())
|
res_attrs = (all_dep_attrs(value) for value in snippet.values())
|
||||||
return itertools.chain.from_iterable(res_attrs)
|
return itertools.chain.from_iterable(res_attrs)
|
||||||
elif (not isinstance(snippet, six.string_types) and
|
elif (not isinstance(snippet, str) and
|
||||||
isinstance(snippet, collections.Iterable)):
|
isinstance(snippet, collections.Iterable)):
|
||||||
res_attrs = (all_dep_attrs(value) for value in snippet)
|
res_attrs = (all_dep_attrs(value) for value in snippet)
|
||||||
return itertools.chain.from_iterable(res_attrs)
|
return itertools.chain.from_iterable(res_attrs)
|
||||||
|
@ -12,14 +12,14 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import functools
|
||||||
import hashlib
|
import hashlib
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
from urllib import parse as urlparse
|
||||||
from six.moves.urllib import parse as urlparse
|
|
||||||
import yaql
|
import yaql
|
||||||
from yaql.language import exceptions
|
from yaql.language import exceptions
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class GetParam(function.Function):
|
|||||||
raise ValueError(_('Function "%s" must have arguments') %
|
raise ValueError(_('Function "%s" must have arguments') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
if isinstance(args, six.string_types):
|
if isinstance(args, str):
|
||||||
param_name = args
|
param_name = args
|
||||||
path_components = []
|
path_components = []
|
||||||
elif isinstance(args, collections.Sequence):
|
elif isinstance(args, collections.Sequence):
|
||||||
@ -86,7 +86,7 @@ class GetParam(function.Function):
|
|||||||
raise TypeError(_('Argument to "%s" must be string or list') %
|
raise TypeError(_('Argument to "%s" must be string or list') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
if not isinstance(param_name, six.string_types):
|
if not isinstance(param_name, str):
|
||||||
raise TypeError(_('Parameter name in "%s" must be string') %
|
raise TypeError(_('Parameter name in "%s" must be string') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
@ -100,12 +100,12 @@ class GetParam(function.Function):
|
|||||||
collections.Sequence)):
|
collections.Sequence)):
|
||||||
raise TypeError(_('"%s" can\'t traverse path') % self.fn_name)
|
raise TypeError(_('"%s" can\'t traverse path') % self.fn_name)
|
||||||
|
|
||||||
if not isinstance(key, (six.string_types, int)):
|
if not isinstance(key, (str, int)):
|
||||||
raise TypeError(_('Path components in "%s" '
|
raise TypeError(_('Path components in "%s" '
|
||||||
'must be strings') % self.fn_name)
|
'must be strings') % self.fn_name)
|
||||||
|
|
||||||
if isinstance(collection, collections.Sequence
|
if isinstance(collection, collections.Sequence
|
||||||
) and isinstance(key, six.string_types):
|
) and isinstance(key, str):
|
||||||
try:
|
try:
|
||||||
key = int(key)
|
key = int(key)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -116,7 +116,7 @@ class GetParam(function.Function):
|
|||||||
return collection[key]
|
return collection[key]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return six.moves.reduce(get_path_component, path_components,
|
return functools.reduce(get_path_component, path_components,
|
||||||
parameter)
|
parameter)
|
||||||
except (KeyError, IndexError, TypeError):
|
except (KeyError, IndexError, TypeError):
|
||||||
return ''
|
return ''
|
||||||
@ -168,7 +168,7 @@ class GetAttThenSelect(function.Function):
|
|||||||
|
|
||||||
def _parse_args(self):
|
def _parse_args(self):
|
||||||
if (not isinstance(self.args, collections.Sequence) or
|
if (not isinstance(self.args, collections.Sequence) or
|
||||||
isinstance(self.args, six.string_types)):
|
isinstance(self.args, str)):
|
||||||
raise TypeError(_('Argument to "%s" must be a list') %
|
raise TypeError(_('Argument to "%s" must be a list') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ class GetAttThenSelect(function.Function):
|
|||||||
attrs = [self._attr_path()]
|
attrs = [self._attr_path()]
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
LOG.debug("Ignoring exception calculating required attributes"
|
LOG.debug("Ignoring exception calculating required attributes"
|
||||||
": %s %s", type(exc).__name__, six.text_type(exc))
|
": %s %s", type(exc).__name__, str(exc))
|
||||||
attrs = []
|
attrs = []
|
||||||
else:
|
else:
|
||||||
attrs = []
|
attrs = []
|
||||||
@ -400,13 +400,13 @@ class Replace(function.Function):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
if not isinstance(value,
|
if not isinstance(value,
|
||||||
(six.string_types, six.integer_types,
|
(str, int,
|
||||||
float, bool)):
|
float, bool)):
|
||||||
raise TypeError(_('"%(name)s" params must be strings or numbers, '
|
raise TypeError(_('"%(name)s" params must be strings or numbers, '
|
||||||
'param %(param)s is not valid') %
|
'param %(param)s is not valid') %
|
||||||
{'name': self.fn_name, 'param': param})
|
{'name': self.fn_name, 'param': param})
|
||||||
|
|
||||||
return six.text_type(value)
|
return str(value)
|
||||||
|
|
||||||
def result(self):
|
def result(self):
|
||||||
template = function.resolve(self._string)
|
template = function.resolve(self._string)
|
||||||
@ -415,7 +415,7 @@ class Replace(function.Function):
|
|||||||
if self._strict:
|
if self._strict:
|
||||||
unreplaced_keys = set(mapping)
|
unreplaced_keys = set(mapping)
|
||||||
|
|
||||||
if not isinstance(template, six.string_types):
|
if not isinstance(template, str):
|
||||||
raise TypeError(_('"%s" template must be a string') % self.fn_name)
|
raise TypeError(_('"%s" template must be a string') % self.fn_name)
|
||||||
|
|
||||||
if not isinstance(mapping, collections.Mapping):
|
if not isinstance(mapping, collections.Mapping):
|
||||||
@ -426,7 +426,7 @@ class Replace(function.Function):
|
|||||||
return strings
|
return strings
|
||||||
|
|
||||||
placeholder = keys[0]
|
placeholder = keys[0]
|
||||||
if not isinstance(placeholder, six.string_types):
|
if not isinstance(placeholder, str):
|
||||||
raise TypeError(_('"%s" param placeholders must be strings') %
|
raise TypeError(_('"%s" param placeholders must be strings') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
@ -490,7 +490,7 @@ class ReplaceJson(Replace):
|
|||||||
else:
|
else:
|
||||||
_raise_empty_param_value_error()
|
_raise_empty_param_value_error()
|
||||||
|
|
||||||
if not isinstance(value, (six.string_types, six.integer_types,
|
if not isinstance(value, (str, int,
|
||||||
float, bool)):
|
float, bool)):
|
||||||
if isinstance(value, (collections.Mapping, collections.Sequence)):
|
if isinstance(value, (collections.Mapping, collections.Sequence)):
|
||||||
if not self._allow_empty_value and len(value) == 0:
|
if not self._allow_empty_value and len(value) == 0:
|
||||||
@ -507,7 +507,7 @@ class ReplaceJson(Replace):
|
|||||||
raise TypeError(_('"%s" params must be strings, numbers, '
|
raise TypeError(_('"%s" params must be strings, numbers, '
|
||||||
'list or map.') % self.fn_name)
|
'list or map.') % self.fn_name)
|
||||||
|
|
||||||
ret_value = six.text_type(value)
|
ret_value = str(value)
|
||||||
if not self._allow_empty_value and not ret_value:
|
if not self._allow_empty_value and not ret_value:
|
||||||
_raise_empty_param_value_error()
|
_raise_empty_param_value_error()
|
||||||
return ret_value
|
return ret_value
|
||||||
@ -553,7 +553,7 @@ class GetFile(function.Function):
|
|||||||
assert self.files is not None, "No stack definition in Function"
|
assert self.files is not None, "No stack definition in Function"
|
||||||
|
|
||||||
args = function.resolve(self.args)
|
args = function.resolve(self.args)
|
||||||
if not (isinstance(args, six.string_types)):
|
if not (isinstance(args, str)):
|
||||||
raise TypeError(_('Argument to "%s" must be a string') %
|
raise TypeError(_('Argument to "%s" must be a string') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
@ -603,19 +603,19 @@ class Join(function.Function):
|
|||||||
strings = function.resolve(self._strings)
|
strings = function.resolve(self._strings)
|
||||||
if strings is None:
|
if strings is None:
|
||||||
strings = []
|
strings = []
|
||||||
if (isinstance(strings, six.string_types) or
|
if (isinstance(strings, str) or
|
||||||
not isinstance(strings, collections.Sequence)):
|
not isinstance(strings, collections.Sequence)):
|
||||||
raise TypeError(_('"%s" must operate on a list') % self.fn_name)
|
raise TypeError(_('"%s" must operate on a list') % self.fn_name)
|
||||||
|
|
||||||
delim = function.resolve(self._delim)
|
delim = function.resolve(self._delim)
|
||||||
if not isinstance(delim, six.string_types):
|
if not isinstance(delim, str):
|
||||||
raise TypeError(_('"%s" delimiter must be a string') %
|
raise TypeError(_('"%s" delimiter must be a string') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
def ensure_string(s):
|
def ensure_string(s):
|
||||||
if s is None:
|
if s is None:
|
||||||
return ''
|
return ''
|
||||||
if not isinstance(s, six.string_types):
|
if not isinstance(s, str):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
_('Items to join must be strings not %s'
|
_('Items to join must be strings not %s'
|
||||||
) % (repr(s)[:200]))
|
) % (repr(s)[:200]))
|
||||||
@ -668,7 +668,7 @@ class JoinMultiple(function.Function):
|
|||||||
strings = []
|
strings = []
|
||||||
for jl in r_joinlists:
|
for jl in r_joinlists:
|
||||||
if jl:
|
if jl:
|
||||||
if (isinstance(jl, six.string_types) or
|
if (isinstance(jl, str) or
|
||||||
not isinstance(jl, collections.Sequence)):
|
not isinstance(jl, collections.Sequence)):
|
||||||
raise TypeError(_('"%s" must operate on '
|
raise TypeError(_('"%s" must operate on '
|
||||||
'a list') % self.fn_name)
|
'a list') % self.fn_name)
|
||||||
@ -676,7 +676,7 @@ class JoinMultiple(function.Function):
|
|||||||
strings += jl
|
strings += jl
|
||||||
|
|
||||||
delim = function.resolve(self._delim)
|
delim = function.resolve(self._delim)
|
||||||
if not isinstance(delim, six.string_types):
|
if not isinstance(delim, str):
|
||||||
raise TypeError(_('"%s" delimiter must be a string') %
|
raise TypeError(_('"%s" delimiter must be a string') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
@ -685,7 +685,7 @@ class JoinMultiple(function.Function):
|
|||||||
) % (repr(s)[:200])
|
) % (repr(s)[:200])
|
||||||
if s is None:
|
if s is None:
|
||||||
return ''
|
return ''
|
||||||
elif isinstance(s, six.string_types):
|
elif isinstance(s, str):
|
||||||
return s
|
return s
|
||||||
elif isinstance(s, (collections.Mapping, collections.Sequence)):
|
elif isinstance(s, (collections.Mapping, collections.Sequence)):
|
||||||
try:
|
try:
|
||||||
@ -801,7 +801,7 @@ class MapReplace(function.Function):
|
|||||||
repl_keys = ensure_map(repl_map.get('keys', {}))
|
repl_keys = ensure_map(repl_map.get('keys', {}))
|
||||||
repl_values = ensure_map(repl_map.get('values', {}))
|
repl_values = ensure_map(repl_map.get('values', {}))
|
||||||
ret_map = {}
|
ret_map = {}
|
||||||
for k, v in six.iteritems(in_map):
|
for k, v in in_map.items():
|
||||||
key = repl_keys.get(k)
|
key = repl_keys.get(k)
|
||||||
if key is None:
|
if key is None:
|
||||||
key = k
|
key = k
|
||||||
@ -930,12 +930,12 @@ class Repeat(function.Function):
|
|||||||
def _valid_arg(self, arg):
|
def _valid_arg(self, arg):
|
||||||
if not (isinstance(arg, (collections.Sequence,
|
if not (isinstance(arg, (collections.Sequence,
|
||||||
function.Function)) and
|
function.Function)) and
|
||||||
not isinstance(arg, six.string_types)):
|
not isinstance(arg, str)):
|
||||||
raise TypeError(_('The values of the "for_each" argument to '
|
raise TypeError(_('The values of the "for_each" argument to '
|
||||||
'"%s" must be lists') % self.fn_name)
|
'"%s" must be lists') % self.fn_name)
|
||||||
|
|
||||||
def _do_replacement(self, keys, values, template):
|
def _do_replacement(self, keys, values, template):
|
||||||
if isinstance(template, six.string_types):
|
if isinstance(template, str):
|
||||||
for (key, value) in zip(keys, values):
|
for (key, value) in zip(keys, values):
|
||||||
template = template.replace(key, value)
|
template = template.replace(key, value)
|
||||||
return template
|
return template
|
||||||
@ -951,7 +951,7 @@ class Repeat(function.Function):
|
|||||||
|
|
||||||
def result(self):
|
def result(self):
|
||||||
for_each = function.resolve(self._for_each)
|
for_each = function.resolve(self._for_each)
|
||||||
keys, lists = six.moves.zip(*for_each.items())
|
keys, lists = zip(*for_each.items())
|
||||||
|
|
||||||
# use empty list for references(None) else validation will fail
|
# use empty list for references(None) else validation will fail
|
||||||
value_lens = []
|
value_lens = []
|
||||||
@ -970,7 +970,7 @@ class Repeat(function.Function):
|
|||||||
'loop.') % self.fn_name)
|
'loop.') % self.fn_name)
|
||||||
|
|
||||||
template = function.resolve(self._template)
|
template = function.resolve(self._template)
|
||||||
iter_func = itertools.product if self._nested_loop else six.moves.zip
|
iter_func = itertools.product if self._nested_loop else zip
|
||||||
|
|
||||||
return [self._do_replacement(keys, replacements, template)
|
return [self._do_replacement(keys, replacements, template)
|
||||||
for replacements in iter_func(*values)]
|
for replacements in iter_func(*values)]
|
||||||
@ -996,7 +996,7 @@ class RepeatWithMap(Repeat):
|
|||||||
if not (isinstance(arg, (collections.Sequence,
|
if not (isinstance(arg, (collections.Sequence,
|
||||||
collections.Mapping,
|
collections.Mapping,
|
||||||
function.Function)) and
|
function.Function)) and
|
||||||
not isinstance(arg, six.string_types)):
|
not isinstance(arg, str)):
|
||||||
raise TypeError(_('The values of the "for_each" argument to '
|
raise TypeError(_('The values of the "for_each" argument to '
|
||||||
'"%s" must be lists or maps') % self.fn_name)
|
'"%s" must be lists or maps') % self.fn_name)
|
||||||
|
|
||||||
@ -1067,7 +1067,7 @@ class Digest(function.Function):
|
|||||||
|
|
||||||
def validate_usage(self, args):
|
def validate_usage(self, args):
|
||||||
if not (isinstance(args, list) and
|
if not (isinstance(args, list) and
|
||||||
all([isinstance(a, six.string_types) for a in args])):
|
all([isinstance(a, str) for a in args])):
|
||||||
msg = _('Argument to function "%s" must be a list of strings')
|
msg = _('Argument to function "%s" must be a list of strings')
|
||||||
raise TypeError(msg % self.fn_name)
|
raise TypeError(msg % self.fn_name)
|
||||||
|
|
||||||
@ -1075,18 +1075,15 @@ class Digest(function.Function):
|
|||||||
msg = _('Function "%s" usage: ["<algorithm>", "<value>"]')
|
msg = _('Function "%s" usage: ["<algorithm>", "<value>"]')
|
||||||
raise ValueError(msg % self.fn_name)
|
raise ValueError(msg % self.fn_name)
|
||||||
|
|
||||||
if six.PY3:
|
algorithms = hashlib.algorithms_available
|
||||||
algorithms = hashlib.algorithms_available
|
|
||||||
else:
|
|
||||||
algorithms = hashlib.algorithms
|
|
||||||
|
|
||||||
if args[0].lower() not in algorithms:
|
if args[0].lower() not in algorithms:
|
||||||
msg = _('Algorithm must be one of %s')
|
msg = _('Algorithm must be one of %s')
|
||||||
raise ValueError(msg % six.text_type(algorithms))
|
raise ValueError(msg % str(algorithms))
|
||||||
|
|
||||||
def digest(self, algorithm, value):
|
def digest(self, algorithm, value):
|
||||||
_hash = hashlib.new(algorithm)
|
_hash = hashlib.new(algorithm)
|
||||||
_hash.update(six.b(value))
|
_hash.update(value.encode('latin-1'))
|
||||||
|
|
||||||
return _hash.hexdigest()
|
return _hash.hexdigest()
|
||||||
|
|
||||||
@ -1121,7 +1118,7 @@ class StrSplit(function.Function):
|
|||||||
'example': example}
|
'example': example}
|
||||||
self.fn_name = fn_name
|
self.fn_name = fn_name
|
||||||
|
|
||||||
if isinstance(args, (six.string_types, collections.Mapping)):
|
if isinstance(args, (str, collections.Mapping)):
|
||||||
raise TypeError(_('Incorrect arguments to "%(fn_name)s" '
|
raise TypeError(_('Incorrect arguments to "%(fn_name)s" '
|
||||||
'should be: %(example)s') % self.fmt_data)
|
'should be: %(example)s') % self.fmt_data)
|
||||||
|
|
||||||
@ -1214,7 +1211,7 @@ class Yaql(function.Function):
|
|||||||
self._parse(self._expression)
|
self._parse(self._expression)
|
||||||
|
|
||||||
def _parse(self, expression):
|
def _parse(self, expression):
|
||||||
if not isinstance(expression, six.string_types):
|
if not isinstance(expression, str):
|
||||||
raise TypeError(_('The "expression" argument to %s must '
|
raise TypeError(_('The "expression" argument to %s must '
|
||||||
'contain a string.') % self.fn_name)
|
'contain a string.') % self.fn_name)
|
||||||
|
|
||||||
@ -1282,7 +1279,7 @@ class If(function.Macro):
|
|||||||
try:
|
try:
|
||||||
if (not self.args or
|
if (not self.args or
|
||||||
not isinstance(self.args, collections.Sequence) or
|
not isinstance(self.args, collections.Sequence) or
|
||||||
isinstance(self.args, six.string_types)):
|
isinstance(self.args, str)):
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
condition, value_if_true, value_if_false = self.args
|
condition, value_if_true, value_if_false = self.args
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -1311,7 +1308,7 @@ class ConditionBoolean(function.Function):
|
|||||||
|
|
||||||
def _check_args(self):
|
def _check_args(self):
|
||||||
if not (isinstance(self.args, collections.Sequence) and
|
if not (isinstance(self.args, collections.Sequence) and
|
||||||
not isinstance(self.args, six.string_types)):
|
not isinstance(self.args, str)):
|
||||||
msg = _('Arguments to "%s" must be a list of conditions')
|
msg = _('Arguments to "%s" must be a list of conditions')
|
||||||
raise ValueError(msg % self.fn_name)
|
raise ValueError(msg % self.fn_name)
|
||||||
if not self.args or len(self.args) < 2:
|
if not self.args or len(self.args) < 2:
|
||||||
@ -1406,7 +1403,7 @@ class Filter(function.Function):
|
|||||||
|
|
||||||
def _parse_args(self):
|
def _parse_args(self):
|
||||||
if (not isinstance(self.args, collections.Sequence) or
|
if (not isinstance(self.args, collections.Sequence) or
|
||||||
isinstance(self.args, six.string_types)):
|
isinstance(self.args, str)):
|
||||||
raise TypeError(_('Argument to "%s" must be a list') %
|
raise TypeError(_('Argument to "%s" must be a list') %
|
||||||
self.fn_name)
|
self.fn_name)
|
||||||
|
|
||||||
@ -1476,7 +1473,7 @@ class MakeURL(function.Function):
|
|||||||
elif arg == self.PORT:
|
elif arg == self.PORT:
|
||||||
port = args[arg]
|
port = args[arg]
|
||||||
if not isinstance(port, function.Function):
|
if not isinstance(port, function.Function):
|
||||||
if not isinstance(port, six.integer_types):
|
if not isinstance(port, int):
|
||||||
try:
|
try:
|
||||||
port = int(port)
|
port = int(port)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -1493,7 +1490,7 @@ class MakeURL(function.Function):
|
|||||||
'must be in range 1-65535') % port)
|
'must be in range 1-65535') % port)
|
||||||
else:
|
else:
|
||||||
if not isinstance(args[arg], (function.Function,
|
if not isinstance(args[arg], (function.Function,
|
||||||
six.string_types)):
|
str)):
|
||||||
raise TypeError(_('The "%(arg)s" argument to '
|
raise TypeError(_('The "%(arg)s" argument to '
|
||||||
'"%(fn_name)s" must be a string') %
|
'"%(fn_name)s" must be a string') %
|
||||||
{'arg': arg,
|
{'arg': arg,
|
||||||
@ -1544,7 +1541,7 @@ class MakeURL(function.Function):
|
|||||||
port = args.get(self.PORT, '')
|
port = args.get(self.PORT, '')
|
||||||
if port:
|
if port:
|
||||||
yield ':'
|
yield ':'
|
||||||
yield six.text_type(port)
|
yield str(port)
|
||||||
|
|
||||||
path = urlparse.quote(args.get(self.PATH, ''))
|
path = urlparse.quote(args.get(self.PATH, ''))
|
||||||
|
|
||||||
@ -1584,7 +1581,7 @@ class ListConcat(function.Function):
|
|||||||
def result(self):
|
def result(self):
|
||||||
args = function.resolve(self.args)
|
args = function.resolve(self.args)
|
||||||
|
|
||||||
if (isinstance(args, six.string_types) or
|
if (isinstance(args, str) or
|
||||||
not isinstance(args, collections.Sequence)):
|
not isinstance(args, collections.Sequence)):
|
||||||
raise TypeError(_('Incorrect arguments to "%(fn_name)s" '
|
raise TypeError(_('Incorrect arguments to "%(fn_name)s" '
|
||||||
'should be: %(example)s') % self.fmt_data)
|
'should be: %(example)s') % self.fmt_data)
|
||||||
@ -1593,7 +1590,7 @@ class ListConcat(function.Function):
|
|||||||
if m is None:
|
if m is None:
|
||||||
return []
|
return []
|
||||||
elif (isinstance(m, collections.Sequence) and
|
elif (isinstance(m, collections.Sequence) and
|
||||||
not isinstance(m, six.string_types)):
|
not isinstance(m, str)):
|
||||||
return m
|
return m
|
||||||
else:
|
else:
|
||||||
msg = _('Incorrect arguments: Items to concat must be lists. '
|
msg = _('Incorrect arguments: Items to concat must be lists. '
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
from heat.engine.cfn import functions as cfn_funcs
|
from heat.engine.cfn import functions as cfn_funcs
|
||||||
@ -159,7 +157,7 @@ class HOTemplate20130523(template_common.CommonTemplate):
|
|||||||
if not attrs:
|
if not attrs:
|
||||||
raise exception.StackValidationFailed(message=message)
|
raise exception.StackValidationFailed(message=message)
|
||||||
try:
|
try:
|
||||||
for attr, attr_value in six.iteritems(attrs):
|
for attr, attr_value in attrs.items():
|
||||||
if attr not in allowed_keys:
|
if attr not in allowed_keys:
|
||||||
raise KeyError(err_msg % attr)
|
raise KeyError(err_msg % attr)
|
||||||
if sub_section not in attrs:
|
if sub_section not in attrs:
|
||||||
@ -183,7 +181,7 @@ class HOTemplate20130523(template_common.CommonTemplate):
|
|||||||
for name, attrs in sorted(data.items()):
|
for name, attrs in sorted(data.items()):
|
||||||
cfn_object = {}
|
cfn_object = {}
|
||||||
|
|
||||||
for attr, attr_value in six.iteritems(attrs):
|
for attr, attr_value in attrs.items():
|
||||||
cfn_attr = mapping[attr]
|
cfn_attr = mapping[attr]
|
||||||
if cfn_attr is not None:
|
if cfn_attr is not None:
|
||||||
cfn_object[cfn_attr] = attr_value
|
cfn_object[cfn_attr] = attr_value
|
||||||
@ -201,18 +199,18 @@ class HOTemplate20130523(template_common.CommonTemplate):
|
|||||||
|
|
||||||
def get_section_name(self, section):
|
def get_section_name(self, section):
|
||||||
cfn_to_hot_attrs = dict(
|
cfn_to_hot_attrs = dict(
|
||||||
zip(six.itervalues(self._HOT_TO_CFN_ATTRS),
|
zip(self._HOT_TO_CFN_ATTRS.values(),
|
||||||
six.iterkeys(self._HOT_TO_CFN_ATTRS)))
|
self._HOT_TO_CFN_ATTRS.keys()))
|
||||||
return cfn_to_hot_attrs.get(section, section)
|
return cfn_to_hot_attrs.get(section, section)
|
||||||
|
|
||||||
def param_schemata(self, param_defaults=None):
|
def param_schemata(self, param_defaults=None):
|
||||||
parameter_section = self.t.get(self.PARAMETERS) or {}
|
parameter_section = self.t.get(self.PARAMETERS) or {}
|
||||||
pdefaults = param_defaults or {}
|
pdefaults = param_defaults or {}
|
||||||
for name, schema in six.iteritems(parameter_section):
|
for name, schema in parameter_section.items():
|
||||||
if name in pdefaults:
|
if name in pdefaults:
|
||||||
parameter_section[name]['default'] = pdefaults[name]
|
parameter_section[name]['default'] = pdefaults[name]
|
||||||
|
|
||||||
params = six.iteritems(parameter_section)
|
params = parameter_section.items()
|
||||||
return dict((name, self.param_schema_class.from_dict(name, schema))
|
return dict((name, self.param_schema_class.from_dict(name, schema))
|
||||||
for name, schema in params)
|
for name, schema in params)
|
||||||
|
|
||||||
@ -228,7 +226,7 @@ class HOTemplate20130523(template_common.CommonTemplate):
|
|||||||
valid_keys = frozenset(self._RESOURCE_KEYS)
|
valid_keys = frozenset(self._RESOURCE_KEYS)
|
||||||
|
|
||||||
def defns():
|
def defns():
|
||||||
for name, snippet in six.iteritems(resources):
|
for name, snippet in resources.items():
|
||||||
try:
|
try:
|
||||||
invalid_keys = set(snippet) - valid_keys
|
invalid_keys = set(snippet) - valid_keys
|
||||||
if invalid_keys:
|
if invalid_keys:
|
||||||
@ -239,7 +237,7 @@ class HOTemplate20130523(template_common.CommonTemplate):
|
|||||||
defn_data = dict(self._rsrc_defn_args(stack, name,
|
defn_data = dict(self._rsrc_defn_args(stack, name,
|
||||||
snippet))
|
snippet))
|
||||||
except (TypeError, ValueError, KeyError) as ex:
|
except (TypeError, ValueError, KeyError) as ex:
|
||||||
msg = six.text_type(ex)
|
msg = str(ex)
|
||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
|
|
||||||
defn = rsrc_defn.ResourceDefinition(name, **defn_data)
|
defn = rsrc_defn.ResourceDefinition(name, **defn_data)
|
||||||
@ -250,7 +248,7 @@ class HOTemplate20130523(template_common.CommonTemplate):
|
|||||||
enabled = conditions.is_enabled(cond_name)
|
enabled = conditions.is_enabled(cond_name)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
path = [self.RESOURCES, name, self.RES_CONDITION]
|
path = [self.RESOURCES, name, self.RES_CONDITION]
|
||||||
message = six.text_type(exc)
|
message = str(exc)
|
||||||
raise exception.StackValidationFailed(path=path,
|
raise exception.StackValidationFailed(path=path,
|
||||||
message=message)
|
message=message)
|
||||||
if not enabled:
|
if not enabled:
|
||||||
@ -490,7 +488,7 @@ class HOTemplate20161014(HOTemplate20160408):
|
|||||||
tmpl, template_id, files, env)
|
tmpl, template_id, files, env)
|
||||||
|
|
||||||
self._parser_condition_functions = {}
|
self._parser_condition_functions = {}
|
||||||
for n, f in six.iteritems(self.functions):
|
for n, f in self.functions.items():
|
||||||
if not f == hot_funcs.Removed:
|
if not f == hot_funcs.Removed:
|
||||||
self._parser_condition_functions[n] = function.Invalid
|
self._parser_condition_functions[n] = function.Invalid
|
||||||
else:
|
else:
|
||||||
@ -512,14 +510,14 @@ class HOTemplate20161014(HOTemplate20160408):
|
|||||||
|
|
||||||
yield ('external_id',
|
yield ('external_id',
|
||||||
self._parse_resource_field(self.RES_EXTERNAL_ID,
|
self._parse_resource_field(self.RES_EXTERNAL_ID,
|
||||||
(six.string_types,
|
(str,
|
||||||
function.Function),
|
function.Function),
|
||||||
'string',
|
'string',
|
||||||
name, data, parse))
|
name, data, parse))
|
||||||
|
|
||||||
yield ('condition',
|
yield ('condition',
|
||||||
self._parse_resource_field(self.RES_CONDITION,
|
self._parse_resource_field(self.RES_CONDITION,
|
||||||
(six.string_types, bool,
|
(str, bool,
|
||||||
function.Function),
|
function.Function),
|
||||||
'string_or_boolean',
|
'string_or_boolean',
|
||||||
name, data, parse_cond))
|
name, data, parse_cond))
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
class NodeData(object):
|
class NodeData(object):
|
||||||
"""Data about a node in the graph, to be passed along to other nodes."""
|
"""Data about a node in the graph, to be passed along to other nodes."""
|
||||||
@ -53,8 +51,8 @@ class NodeData(object):
|
|||||||
"""Return a dict of all available top-level attribute values."""
|
"""Return a dict of all available top-level attribute values."""
|
||||||
attrs = {k: v
|
attrs = {k: v
|
||||||
for k, v in self._attributes.items()
|
for k, v in self._attributes.items()
|
||||||
if isinstance(k, six.string_types)}
|
if isinstance(k, str)}
|
||||||
for v in six.itervalues(attrs):
|
for v in attrs.values():
|
||||||
if isinstance(v, Exception):
|
if isinstance(v, Exception):
|
||||||
raise v
|
raise v
|
||||||
return attrs
|
return attrs
|
||||||
@ -69,7 +67,7 @@ class NodeData(object):
|
|||||||
def attribute_names(self):
|
def attribute_names(self):
|
||||||
"""Iterate over valid top-level attribute names."""
|
"""Iterate over valid top-level attribute names."""
|
||||||
for key in self._attributes:
|
for key in self._attributes:
|
||||||
if isinstance(key, six.string_types):
|
if isinstance(key, str):
|
||||||
yield key
|
yield key
|
||||||
else:
|
else:
|
||||||
yield key[0]
|
yield key[0]
|
||||||
@ -80,7 +78,7 @@ class NodeData(object):
|
|||||||
This is the format that is serialised and stored in the database's
|
This is the format that is serialised and stored in the database's
|
||||||
SyncPoints.
|
SyncPoints.
|
||||||
"""
|
"""
|
||||||
for v in six.itervalues(self._attributes):
|
for v in self._attributes.values():
|
||||||
if isinstance(v, Exception):
|
if isinstance(v, Exception):
|
||||||
raise v
|
raise v
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.engine import function
|
from heat.engine import function
|
||||||
@ -47,8 +46,7 @@ class OutputDefinition(object):
|
|||||||
if self._deps is None:
|
if self._deps is None:
|
||||||
try:
|
try:
|
||||||
required_resources = function.dependencies(self._value)
|
required_resources = function.dependencies(self._value)
|
||||||
self._deps = set(six.moves.map(lambda rp: rp.name,
|
self._deps = set(map(lambda rp: rp.name, required_resources))
|
||||||
required_resources))
|
|
||||||
except (exception.InvalidTemplateAttribute,
|
except (exception.InvalidTemplateAttribute,
|
||||||
exception.InvalidTemplateReference):
|
exception.InvalidTemplateReference):
|
||||||
# This output ain't gonna work anyway
|
# This output ain't gonna work anyway
|
||||||
@ -83,7 +81,7 @@ class OutputDefinition(object):
|
|||||||
if self._description is None:
|
if self._description is None:
|
||||||
return 'No description given'
|
return 'No description given'
|
||||||
|
|
||||||
return six.text_type(self._description)
|
return str(self._description)
|
||||||
|
|
||||||
def render_hot(self):
|
def render_hot(self):
|
||||||
def items():
|
def items():
|
||||||
|
@ -18,7 +18,6 @@ import itertools
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
@ -87,8 +86,7 @@ class Schema(constr.Schema):
|
|||||||
message=_('Default must be a comma-delimited list '
|
message=_('Default must be a comma-delimited list '
|
||||||
'string: %s') % err)
|
'string: %s') % err)
|
||||||
elif self.type == self.LIST and isinstance(self.default, list):
|
elif self.type == self.LIST and isinstance(self.default, list):
|
||||||
default_value = [(six.text_type(x))
|
default_value = [(str(x)) for x in self.default]
|
||||||
for x in self.default]
|
|
||||||
try:
|
try:
|
||||||
self.validate_constraints(default_value, context,
|
self.validate_constraints(default_value, context,
|
||||||
[constr.CustomConstraint])
|
[constr.CustomConstraint])
|
||||||
@ -184,7 +182,6 @@ class Schema(constr.Schema):
|
|||||||
return super(Schema, self).__getitem__(key)
|
return super(Schema, self).__getitem__(key)
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
|
||||||
class Parameter(object):
|
class Parameter(object):
|
||||||
"""A template parameter."""
|
"""A template parameter."""
|
||||||
|
|
||||||
@ -247,10 +244,10 @@ class Parameter(object):
|
|||||||
else:
|
else:
|
||||||
raise exception.UserParameterMissing(key=self.name)
|
raise exception.UserParameterMissing(key=self.name)
|
||||||
except exception.StackValidationFailed as ex:
|
except exception.StackValidationFailed as ex:
|
||||||
msg = err_msg % dict(name=self.name, exp=six.text_type(ex))
|
msg = err_msg % dict(name=self.name, exp=str(ex))
|
||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
except exception.InvalidSchemaError as ex:
|
except exception.InvalidSchemaError as ex:
|
||||||
msg = err_msg % dict(name=self.name, exp=six.text_type(ex))
|
msg = err_msg % dict(name=self.name, exp=str(ex))
|
||||||
raise exception.InvalidSchemaError(message=msg)
|
raise exception.InvalidSchemaError(message=msg)
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
@ -302,13 +299,13 @@ class Parameter(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _value_as_text(cls, value):
|
def _value_as_text(cls, value):
|
||||||
return six.text_type(value)
|
return str(value)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return a string representation of the parameter."""
|
"""Return a string representation of the parameter."""
|
||||||
value = self.value()
|
value = self.value()
|
||||||
if self.hidden():
|
if self.hidden():
|
||||||
return six.text_type('******')
|
return str('******')
|
||||||
else:
|
else:
|
||||||
return self._value_as_text(value)
|
return self._value_as_text(value)
|
||||||
|
|
||||||
@ -330,7 +327,7 @@ class NumberParam(Parameter):
|
|||||||
try:
|
try:
|
||||||
Schema.str_to_num(val)
|
Schema.str_to_num(val)
|
||||||
except (ValueError, TypeError) as ex:
|
except (ValueError, TypeError) as ex:
|
||||||
raise exception.StackValidationFailed(message=six.text_type(ex))
|
raise exception.StackValidationFailed(message=str(ex))
|
||||||
self.schema.validate_value(val, context)
|
self.schema.validate_value(val, context)
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
@ -346,7 +343,7 @@ class BooleanParam(Parameter):
|
|||||||
try:
|
try:
|
||||||
strutils.bool_from_string(val, strict=True)
|
strutils.bool_from_string(val, strict=True)
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
raise exception.StackValidationFailed(message=six.text_type(ex))
|
raise exception.StackValidationFailed(message=str(ex))
|
||||||
self.schema.validate_value(val, context)
|
self.schema.validate_value(val, context)
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
@ -402,12 +399,12 @@ class CommaDelimitedListParam(ParsedParameter, collections.Sequence):
|
|||||||
def parse(self, value):
|
def parse(self, value):
|
||||||
# only parse when value is not already a list
|
# only parse when value is not already a list
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
return [(six.text_type(x)) for x in value]
|
return [(str(x)) for x in value]
|
||||||
try:
|
try:
|
||||||
return param_utils.delim_string_to_list(value)
|
return param_utils.delim_string_to_list(value)
|
||||||
except (KeyError, AttributeError) as err:
|
except (KeyError, AttributeError) as err:
|
||||||
message = _('Value must be a comma-delimited list string: %s')
|
message = _('Value must be a comma-delimited list string: %s')
|
||||||
raise ValueError(message % six.text_type(err))
|
raise ValueError(message % str(err))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
@ -432,7 +429,7 @@ class CommaDelimitedListParam(ParsedParameter, collections.Sequence):
|
|||||||
try:
|
try:
|
||||||
parsed = self.parse(val)
|
parsed = self.parse(val)
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
raise exception.StackValidationFailed(message=six.text_type(ex))
|
raise exception.StackValidationFailed(message=str(ex))
|
||||||
self.schema.validate_value(parsed, context)
|
self.schema.validate_value(parsed, context)
|
||||||
|
|
||||||
|
|
||||||
@ -448,7 +445,7 @@ class JsonParam(ParsedParameter):
|
|||||||
def parse(self, value):
|
def parse(self, value):
|
||||||
try:
|
try:
|
||||||
val = value
|
val = value
|
||||||
if not isinstance(val, six.string_types):
|
if not isinstance(val, str):
|
||||||
# turn off oslo_serialization's clever to_primitive()
|
# turn off oslo_serialization's clever to_primitive()
|
||||||
val = jsonutils.dumps(val, default=None)
|
val = jsonutils.dumps(val, default=None)
|
||||||
if val:
|
if val:
|
||||||
@ -481,12 +478,11 @@ class JsonParam(ParsedParameter):
|
|||||||
try:
|
try:
|
||||||
parsed = self.parse(val)
|
parsed = self.parse(val)
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
raise exception.StackValidationFailed(message=six.text_type(ex))
|
raise exception.StackValidationFailed(message=str(ex))
|
||||||
self.schema.validate_value(parsed, context)
|
self.schema.validate_value(parsed, context)
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
class Parameters(collections.Mapping, metaclass=abc.ABCMeta):
|
||||||
class Parameters(collections.Mapping):
|
|
||||||
"""Parameters of a stack.
|
"""Parameters of a stack.
|
||||||
|
|
||||||
The parameters of a stack, with type checking, defaults, etc. specified by
|
The parameters of a stack, with type checking, defaults, etc. specified by
|
||||||
@ -513,7 +509,7 @@ class Parameters(collections.Mapping):
|
|||||||
|
|
||||||
schemata = self.tmpl.param_schemata()
|
schemata = self.tmpl.param_schemata()
|
||||||
user_parameters = (user_parameter(si) for si in
|
user_parameters = (user_parameter(si) for si in
|
||||||
six.iteritems(schemata))
|
schemata.items())
|
||||||
pseudo_parameters = self._pseudo_parameters(stack_identifier)
|
pseudo_parameters = self._pseudo_parameters(stack_identifier)
|
||||||
|
|
||||||
self.params = dict((p.name,
|
self.params = dict((p.name,
|
||||||
@ -534,7 +530,7 @@ class Parameters(collections.Mapping):
|
|||||||
"""
|
"""
|
||||||
self._validate_user_parameters()
|
self._validate_user_parameters()
|
||||||
|
|
||||||
for param in six.itervalues(self.params):
|
for param in self.params.values():
|
||||||
param.validate(validate_value, context)
|
param.validate(validate_value, context)
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
@ -560,7 +556,7 @@ class Parameters(collections.Mapping):
|
|||||||
function) and return the resulting dictionary.
|
function) and return the resulting dictionary.
|
||||||
"""
|
"""
|
||||||
return dict((n, func(p))
|
return dict((n, func(p))
|
||||||
for n, p in six.iteritems(self.params) if filter_func(p))
|
for n, p in self.params.items() if filter_func(p))
|
||||||
|
|
||||||
def set_stack_id(self, stack_identifier):
|
def set_stack_id(self, stack_identifier):
|
||||||
"""Set the StackId pseudo parameter value."""
|
"""Set the StackId pseudo parameter value."""
|
||||||
|
@ -17,7 +17,6 @@ import sys
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import plugin_loader
|
from heat.common import plugin_loader
|
||||||
|
|
||||||
@ -49,15 +48,14 @@ class PluginManager(object):
|
|||||||
'heat.engine')
|
'heat.engine')
|
||||||
|
|
||||||
def modules():
|
def modules():
|
||||||
pkg_modules = six.moves.map(plugin_loader.load_modules,
|
pkg_modules = map(plugin_loader.load_modules, packages())
|
||||||
packages())
|
|
||||||
return itertools.chain.from_iterable(pkg_modules)
|
return itertools.chain.from_iterable(pkg_modules)
|
||||||
|
|
||||||
self.modules = list(modules())
|
self.modules = list(modules())
|
||||||
|
|
||||||
def map_to_modules(self, function):
|
def map_to_modules(self, function):
|
||||||
"""Iterate over the results of calling a function on every module."""
|
"""Iterate over the results of calling a function on every module."""
|
||||||
return six.moves.map(function, self.modules)
|
return map(function, self.modules)
|
||||||
|
|
||||||
|
|
||||||
class PluginMapping(object):
|
class PluginMapping(object):
|
||||||
@ -72,7 +70,7 @@ class PluginMapping(object):
|
|||||||
mappings provided by that module. Any other arguments passed will be
|
mappings provided by that module. Any other arguments passed will be
|
||||||
passed to the mapping functions.
|
passed to the mapping functions.
|
||||||
"""
|
"""
|
||||||
if isinstance(names, six.string_types):
|
if isinstance(names, str):
|
||||||
names = [names]
|
names = [names]
|
||||||
|
|
||||||
self.names = ['%s_mapping' % name for name in names]
|
self.names = ['%s_mapping' % name for name in names]
|
||||||
@ -109,5 +107,5 @@ class PluginMapping(object):
|
|||||||
Mappings are returned as a list of (key, value) tuples.
|
Mappings are returned as a list of (key, value) tuples.
|
||||||
"""
|
"""
|
||||||
mod_dicts = plugin_manager.map_to_modules(self.load_from_module)
|
mod_dicts = plugin_manager.map_to_modules(self.load_from_module)
|
||||||
return itertools.chain.from_iterable(six.iteritems(d) for d
|
return itertools.chain.from_iterable(d.items() for d
|
||||||
in mod_dicts)
|
in mod_dicts)
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
import collections
|
import collections
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
@ -274,9 +273,9 @@ class Property(object):
|
|||||||
def _get_string(self, value):
|
def _get_string(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
value = self.has_default() and self.default() or ''
|
value = self.has_default() and self.default() or ''
|
||||||
if not isinstance(value, six.string_types):
|
if not isinstance(value, str):
|
||||||
if isinstance(value, (bool, int)):
|
if isinstance(value, (bool, int)):
|
||||||
value = six.text_type(value)
|
value = str(value)
|
||||||
else:
|
else:
|
||||||
raise ValueError(_('Value must be a string; got %r') % value)
|
raise ValueError(_('Value must be a string; got %r') % value)
|
||||||
return value
|
return value
|
||||||
@ -306,24 +305,23 @@ class Property(object):
|
|||||||
# via a provider resource, in particular lists-of-dicts which
|
# via a provider resource, in particular lists-of-dicts which
|
||||||
# cannot be handled correctly via comma_delimited_list
|
# cannot be handled correctly via comma_delimited_list
|
||||||
if self.schema.allow_conversion:
|
if self.schema.allow_conversion:
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
return value
|
return value
|
||||||
elif isinstance(value, collections.Sequence):
|
elif isinstance(value, collections.Sequence):
|
||||||
return jsonutils.dumps(value)
|
return jsonutils.dumps(value)
|
||||||
raise TypeError(_('"%s" is not a map') % value)
|
raise TypeError(_('"%s" is not a map') % value)
|
||||||
|
|
||||||
return dict(self._get_children(six.iteritems(value),
|
return dict(self._get_children(value.items(),
|
||||||
validate=validate,
|
validate=validate,
|
||||||
translation=translation))
|
translation=translation))
|
||||||
|
|
||||||
def _get_list(self, value, validate=False, translation=None):
|
def _get_list(self, value, validate=False, translation=None):
|
||||||
if value is None:
|
if value is None:
|
||||||
value = self.has_default() and self.default() or []
|
value = self.has_default() and self.default() or []
|
||||||
if self.schema.allow_conversion and isinstance(value,
|
if self.schema.allow_conversion and isinstance(value, str):
|
||||||
six.string_types):
|
|
||||||
value = param_utils.delim_string_to_list(value)
|
value = param_utils.delim_string_to_list(value)
|
||||||
if (not isinstance(value, collections.Sequence) or
|
if (not isinstance(value, collections.Sequence) or
|
||||||
isinstance(value, six.string_types)):
|
isinstance(value, str)):
|
||||||
raise TypeError(_('"%s" is not a list') % repr(value))
|
raise TypeError(_('"%s" is not a list') % repr(value))
|
||||||
|
|
||||||
return [v[1] for v in self._get_children(enumerate(value),
|
return [v[1] for v in self._get_children(enumerate(value),
|
||||||
@ -341,7 +339,7 @@ class Property(object):
|
|||||||
value = self.has_default() and self.default() or False
|
value = self.has_default() and self.default() or False
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
return value
|
return value
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
normalised = value.lower()
|
normalised = value.lower()
|
||||||
if normalised not in ['true', 'false']:
|
if normalised not in ['true', 'false']:
|
||||||
raise ValueError(_('"%s" is not a valid boolean') % normalised)
|
raise ValueError(_('"%s" is not a valid boolean') % normalised)
|
||||||
@ -432,7 +430,7 @@ class Properties(collections.Mapping):
|
|||||||
else:
|
else:
|
||||||
path = [key]
|
path = [key]
|
||||||
raise exception.StackValidationFailed(
|
raise exception.StackValidationFailed(
|
||||||
path=path, message=six.text_type(e))
|
path=path, message=str(e))
|
||||||
|
|
||||||
# are there unimplemented Properties
|
# are there unimplemented Properties
|
||||||
if not prop.implemented() and key in self.data:
|
if not prop.implemented() and key in self.data:
|
||||||
@ -488,7 +486,7 @@ class Properties(collections.Mapping):
|
|||||||
# the resolver function could raise any number of exceptions,
|
# the resolver function could raise any number of exceptions,
|
||||||
# so handle this generically
|
# so handle this generically
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(six.text_type(e))
|
raise ValueError(str(e))
|
||||||
|
|
||||||
def _get_property_value(self, key, validate=False):
|
def _get_property_value(self, key, validate=False):
|
||||||
if key not in self:
|
if key not in self:
|
||||||
@ -658,7 +656,7 @@ class Properties(collections.Mapping):
|
|||||||
return {}, {}
|
return {}, {}
|
||||||
|
|
||||||
param_prop_defs = [param_prop_def_items(n, s, template_type)
|
param_prop_defs = [param_prop_def_items(n, s, template_type)
|
||||||
for n, s in six.iteritems(schemata(schema))
|
for n, s in schemata(schema).items()
|
||||||
if s.implemented]
|
if s.implemented]
|
||||||
param_items, prop_items = zip(*param_prop_defs)
|
param_items, prop_items = zip(*param_prop_defs)
|
||||||
return dict(param_items), dict(prop_items)
|
return dict(param_items), dict(prop_items)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user