From 026a027603cf4c4ecb021cc3c9a8d40d56f40347 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 15 Mar 2018 12:55:32 -0400 Subject: [PATCH] Fix normalizing unicode in dicts with lists If there's a list in a list, normalize that as well. --- confluent_client/confluent/tlvdata.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/confluent_client/confluent/tlvdata.py b/confluent_client/confluent/tlvdata.py index 93332a48..b8e4859b 100644 --- a/confluent_client/confluent/tlvdata.py +++ b/confluent_client/confluent/tlvdata.py @@ -38,15 +38,21 @@ def unicode_dictvalues(dictdata): elif isinstance(dictdata[key], datetime): dictdata[key] = dictdata[key].strftime('%Y-%m-%dT%H:%M:%S') elif isinstance(dictdata[key], list): - for i in xrange(len(dictdata[key])): - if isinstance(dictdata[key][i], str): - dictdata[key][i] = decodestr(dictdata[key][i]) - elif isinstance(dictdata[key][i], dict): - unicode_dictvalues(dictdata[key][i]) + _unicode_list(dictdata[key]) elif isinstance(dictdata[key], dict): unicode_dictvalues(dictdata[key]) +def _unicode_list(currlist): + for i in xrange(len(currlist)): + if isinstance(currlist[i], str): + currlist[i] = decodestr(currlist[i]) + elif isinstance(currlist[i], dict): + unicode_dictvalues(currlist[i]) + elif isinstance(currlist[i], list): + _unicode_list(currlist[i]) + + def send(handle, data): if isinstance(data, str): # plain text, e.g. console data