String validator not caching encoding exceptions

Leandro Lucarella <[email protected]> Tue, 14 Oct 2008 22:23:54 -0300
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
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?

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
According to several sources
Dr. Harvey Kellogg tried to make a cure for masturbation
When he made cornflakes


-------------------------------------------------------------------------
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