Skip to content

Commit

Permalink
avoid issues with unicode error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Jul 18, 2012
1 parent bc509ca commit b5a314d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/test_validation.py
Expand Up @@ -78,6 +78,16 @@ def test_catch_errors(self):
except twc.ValidationError:
pass

def test_unicode_catch_errors(self):
try:
formencode.api.set_stdtranslation(languages=['tr'])
twc.validation.catch_errors(lambda s, x: formencode.validators.Int.to_python(x))(None, 'x')
assert(False)
except twc.ValidationError:
pass
finally:
formencode.api.set_stdtranslation(languages=['en'])

def test_unflatten(self):
assert(twc.validation.unflatten_params({'a':1, 'b:c':2}) ==
{'a':1, 'b':{'c':2}})
Expand Down
5 changes: 3 additions & 2 deletions tw2/core/validation.py
Expand Up @@ -94,9 +94,10 @@ def wrapper(self, *args, **kw):
d = fn(self, *args, **kw)
return d
except catch, e:
e_msg = unicode(e)
if self:
self.error_msg = str(e)
raise ValidationError(str(e), widget=self)
self.error_msg = e_msg
raise ValidationError(e_msg, widget=self)
return wrapper


Expand Down

0 comments on commit b5a314d

Please sign in to comment.