Hi,

I am using pylons with formencode and international setting set to
'cs':

formencode.api.set_stdtranslation(domain="FormEncode",
languages=['cs'])

However, I don't know if it's a problem between the keyboard and
chair, I have encountered a few UnicodeErrors. For example I have an
login form where I am simply controlling the length of login:

# a draft
class UserController(BaseController):
    def login(self):
        if not len(request.params):
            return render('/user-login.mako')

            try:
                form_result =
form.LoginSchema().to_python(request.params)

            except formencode.Invalid, e:
                defaults = request.params
                errors = e.error_dict
                return formencode.htmlfill.render(render('/user-
login.mako'), defaults, errors, encoding='utf-8')

        else:
            return 'yupi'

when I call it with not set variables, it should display a
nationalized response "type a value", but instead I get an
UnicodeError exception in formencode/htmlfill.py:110:

>>  return cgi.escape(str(v), 1)
exceptions.UnicodeEncodeError: 'ascii' codec can't encode character
u'\xed' in position 4: ordinal not in range(128)

I am doing something wrong?

I found 2 "hacks" to resolve it:
1) patch htmlfill.py, replace line 110 with this:
return cgi.escape(unicode(v), 1)

or (for those who are forced to use standard or old packages)
2) create a function and preprocess e.error_dict:

def fix_bug(exceptions):
     ret = exceptions

     for k in ret.keys():
         ret[k].args = unicode(exceptions[k].args).encode('utf-8')
         ret[k].msg = unicode(exceptions[k].msg).encode('utf-8')
         ret[k].value = unicode(exceptions[k].value).encode('utf-8')

     return ret


errors = fix_bug(e.error_dict)

Any thoughts?

Karol
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to