validation and unicode again...
Matej Barič <[email protected]>
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Hi,
this is clamed to be fixed in 0.6 but it doesn't work for me...
I have this:
class MyValidator(FormValidator):
...
messages = { 'invalid': u'čšžStrange utf-8 characters }
...
and get the ascii-error that always appears. What I did to code was:
def format_compound_error(v, indent=0):
if isinstance(v, Exception):
try:
return str(v)
except UnicodeDecodeError:
# There doesn't seem to be a better way to get a str()
# version if possible, and unicode() if necessary, because
# testing for the presence of a __unicode__ method isn't
# enough
return unicode(v)
+ except UnicodeEncodeError:
+ return unicode(v)
elif isinstance(v, dict):
l = v.items()
l.sort()
return ('%s\n' % (' '*indent)).join(
["%s: %s" % (k, format_compound_error(value, indent=len
(k)+2))
for k, value in l
if value is not None])
elif isinstance(v, list):
return ('%s\n' % (' '*indent)).join(
['%s' % (format_compound_error(value, indent=indent))
for value in v
if value is not None])
elif isinstance(v, str):
return v
+ elif isinstance(v, unicode):
+ return unicode(v)
else:
assert 0, "I didn't expect something like %s" % repr(v)
Now things work perfectly so far. I haven't posted to bug tracker
because I don't even know if what I did was right so I would be glad
to receive some feedback.
Thanks,
Matej
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FormEncode-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-discuss