diff --git a/heat/common/exception.py b/heat/common/exception.py index 36402b5e0e..5bb97d56a2 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -93,6 +93,7 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, return inner +@six.python_2_unicode_compatible class HeatException(Exception): """Base Heat Exception @@ -121,9 +122,6 @@ class HeatException(Exception): raise_(exc_info[0], exc_info[1], exc_info[2]) def __str__(self): - return six.text_type(self.message).encode('UTF-8') - - def __unicode__(self): return six.text_type(self.message) def __deepcopy__(self, memo): diff --git a/heat/engine/dependencies.py b/heat/engine/dependencies.py index f7fb7cafe9..3efb37df0f 100644 --- a/heat/engine/dependencies.py +++ b/heat/engine/dependencies.py @@ -25,6 +25,7 @@ class CircularDependencyException(exception.HeatException): msg_fmt = _("Circular Dependency Found: %(cycle)s") +@six.python_2_unicode_compatible class Node(object): '''A node in a dependency graph.''' @@ -94,18 +95,14 @@ class Node(object): def __str__(self): '''Return a human-readable string representation of the node.''' text = '{%s}' % ', '.join(str(n) for n in self) - return encodeutils.safe_encode(text) - - def __unicode__(self): - '''Return a human-readable string representation of the node.''' - text = '{%s}' % ', '.join(six.text_type(n) for n in self) - return encodeutils.safe_decode(text) + return six.text_type(text) def __repr__(self): '''Return a string representation of the node.''' return repr(self.require) +@six.python_2_unicode_compatible class Graph(collections.defaultdict): '''A mutable mapping of objects to nodes in a dependency graph.''' @@ -153,14 +150,7 @@ class Graph(collections.defaultdict): '''Convert the graph to a human-readable string.''' pairs = ('%s: %s' % (str(k), str(v)) for k, v in six.iteritems(self)) text = '{%s}' % ', '.join(pairs) - return encodeutils.safe_encode(text) - - def __unicode__(self): - '''Convert the graph to a human-readable string.''' - pairs = ('%s: %s' % (six.text_type(k), six.text_type(v)) - for k, v in six.iteritems(self)) - text = '{%s}' % ', '.join(pairs) - return encodeutils.safe_decode(text) + return six.text_type(text) @staticmethod def toposort(graph): @@ -181,6 +171,7 @@ class Graph(collections.defaultdict): raise CircularDependencyException(cycle=six.text_type(graph)) +@six.python_2_unicode_compatible class Dependencies(object): '''Helper class for calculating a dependency graph.''' @@ -280,12 +271,6 @@ class Dependencies(object): return type(self)(tuple(map(transform_key, e)) for e in edges) def __str__(self): - ''' - Return a human-readable string representation of the dependency graph - ''' - return str(self._graph) - - def __unicode__(self): ''' Return a human-readable string representation of the dependency graph ''' diff --git a/heat/engine/environment.py b/heat/engine/environment.py index 5cf6f894b3..345b8f67f3 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -21,7 +21,6 @@ import warnings from oslo_config import cfg from oslo_log import log -from oslo_utils import encodeutils import six from heat.common import environment_format as env_fmt @@ -266,7 +265,7 @@ class ResourceRegistry(object): if isinstance(info, ClassResourceInfo): if info.value.support_status.status != support.SUPPORTED: if info.value.support_status.message is not None: - warnings.warn(encodeutils.safe_encode( + warnings.warn(six.text_type( info.value.support_status.message)) info.user_resource = (self.global_registry is not None) diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index 5ed37bfa31..4f91bea4da 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -171,6 +171,7 @@ class Schema(constr.Schema): return super(Schema, self).__getitem__(key) +@six.python_2_unicode_compatible class Parameter(object): '''A template parameter.''' @@ -283,9 +284,9 @@ class Parameter(object): '''Return a string representation of the parameter.''' value = self.value() if self.hidden(): - return '******' + return six.text_type('******') else: - return encodeutils.safe_encode(six.text_type(value)) + return six.text_type(value) class NumberParam(Parameter): diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 09b7332d1a..92dda53ac4 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -18,7 +18,6 @@ import weakref from oslo_config import cfg from oslo_log import log as logging -from oslo_utils import encodeutils from oslo_utils import excutils import six @@ -93,6 +92,7 @@ class UpdateInProgress(Exception): super(Exception, self).__init__(six.text_type(msg)) +@six.python_2_unicode_compatible class Resource(object): ACTIONS = ( INIT, CREATE, DELETE, UPDATE, ROLLBACK, @@ -461,18 +461,6 @@ class Resource(object): return dict((k, after_props.get(k)) for k in changed_properties_set) def __str__(self): - if self.stack.id: - if self.resource_id: - text = '%s "%s" [%s] %s' % (self.__class__.__name__, self.name, - self.resource_id, str(self.stack)) - else: - text = '%s "%s" %s' % (self.__class__.__name__, self.name, - str(self.stack)) - else: - text = '%s "%s"' % (self.__class__.__name__, self.name) - return encodeutils.safe_encode(text) - - def __unicode__(self): if self.stack.id: if self.resource_id: text = '%s "%s" [%s] %s' % (self.__class__.__name__, self.name, @@ -483,7 +471,7 @@ class Resource(object): six.text_type(self.stack)) else: text = '%s "%s"' % (self.__class__.__name__, self.name) - return encodeutils.safe_decode(text) + return six.text_type(text) def dep_attrs(self, resource_name): return self.t.dep_attrs(resource_name) diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index f9bb0f657b..225b04d12c 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -120,6 +120,7 @@ class TimedCancel(Timeout): return False +@six.python_2_unicode_compatible class ExceptionGroup(Exception): ''' Container for multiple exceptions. @@ -137,13 +138,10 @@ class ExceptionGroup(Exception): self.exceptions = list(exceptions) def __str__(self): - return six.text_type([six.text_type(ex).encode('utf-8') - for ex in self.exceptions]).encode('utf-8') - - def __unicode__(self): - return six.text_type(map(six.text_type, self.exceptions)) + return six.text_type([six.text_type(ex) for ex in self.exceptions]) +@six.python_2_unicode_compatible class TaskRunner(object): """ Wrapper for a resumable task (co-routine). @@ -170,12 +168,7 @@ class TaskRunner(object): def __str__(self): """Return a human-readable string representation of the task.""" text = 'Task %s' % self.name - return encodeutils.safe_encode(text) - - def __unicode__(self): - """Return a human-readable string representation of the task.""" - text = 'Task %s' % self.name - return encodeutils.safe_decode(text) + return six.text_type(text) def _sleep(self, wait_time): """Sleep for the specified number of seconds.""" diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 9cbca3b185..1838405b44 100755 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -65,6 +65,7 @@ class ForcedCancel(BaseException): return "Operation cancelled" +@six.python_2_unicode_compatible class Stack(collections.Mapping): ACTIONS = ( @@ -556,12 +557,7 @@ class Stack(collections.Mapping): def __str__(self): '''Return a human-readable string representation of the stack.''' text = 'Stack "%s" [%s]' % (self.name, self.id) - return encodeutils.safe_encode(text) - - def __unicode__(self): - '''Return a human-readable string representation of the stack.''' - text = 'Stack "%s" [%s]' % (self.name, self.id) - return encodeutils.safe_encode(text) + return six.text_type(text) def resource_by_refid(self, refid): ''' diff --git a/heat/tests/test_scheduler.py b/heat/tests/test_scheduler.py index c291c19edf..fe92957d04 100644 --- a/heat/tests/test_scheduler.py +++ b/heat/tests/test_scheduler.py @@ -187,7 +187,7 @@ class ExceptionGroupTest(common.HeatTestCase): ex2 = Exception("ex 2") exception_group = scheduler.ExceptionGroup([ex1, ex2]) - self.assertEqual("['ex 1', 'ex 2']", str(exception_group)) + self.assertEqual("[u'ex 1', u'ex 2']", str(exception_group)) class DependencyTaskGroupTest(common.HeatTestCase):