formencode.api.Invalid class lack __unicode__ method

"Marcin StÄ™pnicki" <[email protected]> Wed, 29 Oct 2008 12:12:48 +0100
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
I've noticed that error messages which are unicode objects give the
following error when used in htmlfill:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u0119' in
position 5: ordinal not in range(128)

In rewritingparser.html_quote there is a fragment which checks if
given object has __unicode__ attribute:

(...)
   else:
        if hasattr(v, '__unicode__'):
            v = unicode(v)

but objects of  'formencode.api.Invalid' class don't have it, so the following:
(...)
   else:
            v = str(v)

fails with UnicodeDecodeError.

Adding:

    def __unicode__(self):
        val = self.msg
        return val

to formencode.api.Invalid fixes the problem for me.

Regards,
Marcin

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/