[web2py] Transparently convert request.vars into unicode strings
Hello! What is the best way to transparently convert all variables in request.post_vars to Python unicode strings? When I submit string with non-ascii characters using AJAX from browser to web2py application I receive usual Python 2.6 string (str) in request.post_vars.foo with submitted string encoded in UTF-8. I thing encoding of request.post_vars.foo string depends on encoding specified in client browser, so I can't always do unicode(request.post_vars.foo, 'utf-8'). Also submitted string can be non-valid unicode string, so this should be checked either. Thanks in advance, Vladimir Rutsky
Re: [web2py] Transparently convert request.vars into unicode strings
On Sun, Feb 5, 2012 at 11:26 AM, Vladimir Rutsky rutsky.vladi...@gmail.comwrote: unicode(request.post_vars.foo, 'utf-8') Use dictionary comprehension, in models 0.py do: from gluon.storage import Storage request.post_vars = Storage({key: unicode(value, 'utf-8') for key, value in request.post_vars.items()}) -- Bruno Rocha [http://rochacbruno.com.br]