I upgraded my TurboGears copy to latest SVN (r948) and run into a problem with
formencode.
I use localized error messages in form and it used to work. E.g.:
title = widgets.TextField('title', label=_(u'Title'), default='',
validator=validators.UnicodeString(not_empty=True, max=120,
messages={'empty':_(u'Укажите название книги')}))
Now I got all too familiar UnicodeEncodeError:
File "<string>", line 3, in do_addbook
File "d:\projects\3rd-party\turbogears\turbogears\controllers.py", line 125,
in validate
kw.update(form.validate(value))
File "d:\projects\3rd-party\turbogears\turbogears\widgets\base.py", line 275,
in validate
return self.validator.to_python(value, state)
File
"c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\api.py",
line 304, in to_python
value = tp(value, state)
File
"c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\schema.py",
line 172, in _to_python
raise Invalid(
File
"c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\schema.py",
line 296, in format_compound_error
return ('%s\n' % (' '*indent)).join(
File
"c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\schema.py",
line 292, in format_compound_error
return str(v)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-6:
ordinal not in range(128)
I hacked formencode.api.Invalid class to fix that but I'm far from sure this is
the way to go:
def __str__(self):
val = self.msg
#if self.value:
# val += " (value: %s)" % repr(self.value)
try:
val = str(val)
except UnicodeEncodeError:
val = val.encode('utf8')
return val
So, how should I proceed?
Am I doing something wrong/old-fashioned way? Should I stop using non-ascii
error messages with formencode? Submit a patch to formencode? Submit a ticket
to TG?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---