Roger Demetrescu schrieb:
>> ================
>> 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...
>
> Forget to mention that the line:
> elif hasattr(v, 'encode'):
> could be changed to:
> elif isinstance(v, basestring):
I think we should also handle the case that we have a list of dicts or
FileStorages or other non-basestrings, so
res[k] = [vv.encode('utf-8') for vv in v]
should become
res[k] = map(encode_utf8, v)
-- Christoph
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---