Re: String validator not caching encoding exceptions
Ian Bicking <[email protected]> Wed, 15 Oct 2008 10:38:24 -0400
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Leandro Lucarella wrote: > Hi! > > I think this is a bug: > >>>> from formencode import validators >>>> v = validators.String(encoding='ascii') >>>> v.to_python(u'já!') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/lib/python2.5/site-packages/formencode/api.py", line 381, in to_python > value = tp(value, state) > File "/usr/lib/python2.5/site-packages/formencode/validators.py", line 1056, in _to_python > value = value.encode(self.encoding) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 1: ordinal not in range(128) > > I guess this should raise an Invalid exception instead, right? > > Should I send a patch? Sure, Invalid seems much more reasonable. Probably it should also be possible to do unicode_error='replace' to avoid any errors. -- Ian Bicking : [email protected] : http://blog.ianbicking.org ------------------------------------------------------------------------- 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=/ _______________________________________________ FormEncode-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/formencode-discuss