On Dec 11, 2007 2:50 PM, Roger Demetrescu <[EMAIL PROTECTED]> wrote:
> Florent had the idea of checking if the object has an encode
> attribute. Something like:
>
> ================
>         def encode_utf8(params):
>             '''
>             will recursively encode to utf-8 all values in a dictionnary
>             '''
>             res = dict()
>             for k, v in params.items():
>                 if isinstance(v, dict):
>                     res[k] = encode_utf8(v)
>                 elif isinstance(v, list):
>                     res[k] = [vv.encode('utf-8') for vv in v]
>                 elif hasattr(v, 'encode'):
>                     res[k] = v.encode('utf-8')
>                 else:
>                     res[k] = v
>
>             return res
> ================
>
> Didn't test the code... but this should do the trick...
>
> []s
> Roger
>

Forget to mention that the line:

                elif hasattr(v, 'encode'):


could be changed to:

                elif isinstance(v, basestring):


Don't think yet which solution we should adopt...   ;-)

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to