# HG changeset patch # User Julien Jehannet > # Date 1267562916 -3600 # Node ID 6dc34d4cf89266d34e7712da80776a8c14cc2f0b # Parent da0ad1b10779b8483afc504dd8e719099f21c678 [F] views: fix 2 unicode errors 1. You can now use valid unicode strings in ValidationError exception. Previously, if 'err' contains unicode, UnicodeDecodeError was raised by format_errors() >>> templstr = '
  • %s
  • \n' >>> e = ValidationError(None, {None: u'oué, une exception en unicode!'}) >>> templstr % e '
  • None (None): ou\xc3\xa9, une exception en unicode!
  • \n' >>> templstr = u'
  • %s
  • \n' >>> templstr % e u'
  • None (None): ou\xe9, une exception en unicode!
  • \n' 2. The message of an Exception can contains unicode. But it now properly managed by “informal” string representation. We can easily fix the problem by using the Exception.message attribute that still contains the original message. >>> a = AssertionError(u'séfdsdf') >>> a.message u's\xe9fdsdf' >>> str(a) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128) >>> a = ValueError(u'fsdfsdéfsdfs') >>> str(a) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 6: ordinal not in range(128) >>> a ValueError(u'fsdfsd\xe9fsdfs',) >>> unicode(a) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 6: ordinal not in range(128) >>> a.message u'fsdfsd\xe9fsdfs' diff -r da0ad1b10779 -r 6dc34d4cf892 web/views/formrenderers.py --- a/web/views/formrenderers.py Mon Feb 22 17:23:46 2010 +0100 +++ b/web/views/formrenderers.py Tue Mar 02 21:48:36 2010 +0100 @@ -132,9 +132,9 @@ errors = form.remaining_errors() if errors: if len(errors) > 1: - templstr = '
  • %s
  • \n' + templstr = u'
  • %s
  • \n' else: - templstr = ' %s\n' + templstr = u' %s\n' for field, err in errors: if field is None: errormsg += templstr % err