From d46adc1d53ab3df45a7e6bf484000495be11a408 Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Sun, 23 Feb 2014 20:03:02 +0800 Subject: [PATCH] Avoid referencing Message.__str__ in exceptions Change exception.py to accommodate future enablement of lazy translation. Specifically, encode unicode messages to byte strings as gettextutil.Message doesn't support __str__. Change-Id: I16ab67c32d2050d83c1b51b84b24c0a60675aff7 --- heat/common/exception.py | 5 ++++- heat/engine/constraints.py | 2 +- heat/engine/resources/wait_condition.py | 5 +++-- heat/engine/scheduler.py | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/heat/common/exception.py b/heat/common/exception.py index bceed3dfd9..e0c6c0eba3 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -120,11 +120,14 @@ class HeatException(Exception): raise exc_info[0], exc_info[1], exc_info[2] def __str__(self): - return str(self.message) + return unicode(self.message).encode('UTF-8') def __unicode__(self): return unicode(self.message) + def __deepcopy__(self, memo): + return self.__class__(**self.kwargs) + class MissingCredentialError(HeatException): msg_fmt = _("Missing required credential: %(required)s") diff --git a/heat/engine/constraints.py b/heat/engine/constraints.py index 32fbc7f1f0..b29e82a4a7 100644 --- a/heat/engine/constraints.py +++ b/heat/engine/constraints.py @@ -22,7 +22,7 @@ from heat.engine import resources from heat.common import exception -class InvalidSchemaError(Exception): +class InvalidSchemaError(exception.Error): pass diff --git a/heat/engine/resources/wait_condition.py b/heat/engine/resources/wait_condition.py index 5312c86f99..f36910eabc 100644 --- a/heat/engine/resources/wait_condition.py +++ b/heat/engine/resources/wait_condition.py @@ -13,6 +13,7 @@ import json +from heat.common import exception from heat.common import identifier from heat.engine import constraints from heat.engine import properties @@ -126,13 +127,13 @@ class UpdateWaitConditionHandle(WaitConditionHandle): raise resource.UpdateReplace(self.name) -class WaitConditionFailure(Exception): +class WaitConditionFailure(exception.Error): def __init__(self, wait_condition, handle): reasons = handle.get_status_reason(STATUS_FAILURE) super(WaitConditionFailure, self).__init__(reasons) -class WaitConditionTimeout(Exception): +class WaitConditionTimeout(exception.Error): def __init__(self, wait_condition, handle): reasons = handle.get_status_reason(STATUS_SUCCESS) vals = {'len': len(reasons), diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index 52c16d8ebd..686c405393 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -91,10 +91,11 @@ class ExceptionGroup(Exception): self.exceptions = list(exceptions) def __str__(self): - return str(map(str, self.exceptions)) + return unicode([unicode(ex).encode('utf-8') + for ex in self.exceptions]).encode('utf-8') def __unicode__(self): - return unicode(map(str, self.exceptions)) + return unicode(map(unicode, self.exceptions)) class TaskRunner(object):