Merge "Enable unicode error message"

This commit is contained in:
Jenkins 2013-05-14 01:28:55 +00:00 committed by Gerrit Code Review
commit cb0ddabff3
2 changed files with 13 additions and 8 deletions

View File

@ -56,14 +56,10 @@ class Error(StandardError):
:raises: KeyError given insufficient kwargs
"""
return message or self.__doc__ % kwargs
def __str__(self):
"""Cleans up line breaks and indentation from doc strings."""
string = super(Error, self).__str__()
string = re.sub('[ \n]+', ' ', string)
string = string.strip()
return string
if not message:
message = re.sub('[ \n]+', ' ', self.__doc__ % kwargs)
message = message.strip()
return message
class ValidationError(Error):

View File

@ -136,3 +136,12 @@ class SecurityErrorTestCase(ExceptionTestCase):
e = exception.ForbiddenAction(action=risky_info)
self.assertValidJsonRendering(e)
self.assertIn(risky_info, str(e))
def test_unicode_message(self):
message = u'Comment \xe7a va'
e = exception.Error(message)
self.assertEqual(e.message, message)
try:
unicode(e)
except UnicodeEncodeError:
self.fail("unicode error message not supported")