Handle unicode strings in merge-dict
Change-Id: I07958aa5f06ab74f2a5ff8f568897863426ba04f
This commit is contained in:
@@ -107,25 +107,26 @@ def merge_lists(list1, list2):
|
|||||||
|
|
||||||
def merge_dicts(dict1, dict2, max_levels=0):
|
def merge_dicts(dict1, dict2, max_levels=0):
|
||||||
result = {}
|
result = {}
|
||||||
for key, value in dict1.items():
|
for key, value1 in dict1.items():
|
||||||
result[key] = value
|
result[key] = value1
|
||||||
if key in dict2:
|
if key in dict2:
|
||||||
other_value = dict2[key]
|
value2 = dict2[key]
|
||||||
if type(other_value) != type(value):
|
if type(value2) != type(value1):
|
||||||
|
if (isinstance(value1, types.StringTypes) and
|
||||||
|
isinstance(value2, types.StringTypes)):
|
||||||
|
continue
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
if max_levels != 1 and isinstance(
|
if max_levels != 1 and isinstance(value2, types.DictionaryType):
|
||||||
other_value, types.DictionaryType):
|
|
||||||
result[key] = merge_dicts(
|
result[key] = merge_dicts(
|
||||||
value, other_value,
|
value1, value2,
|
||||||
0 if max_levels == 0 else max_levels - 1)
|
0 if max_levels == 0 else max_levels - 1)
|
||||||
elif max_levels != 1 and isinstance(
|
elif max_levels != 1 and isinstance(value2, types.ListType):
|
||||||
other_value, types.ListType):
|
result[key] = merge_lists(value1, value2)
|
||||||
result[key] = merge_lists(value, other_value)
|
|
||||||
else:
|
else:
|
||||||
result[key] = other_value
|
result[key] = value2
|
||||||
for key, value in dict2.items():
|
for key, value1 in dict2.items():
|
||||||
if key not in result:
|
if key not in result:
|
||||||
result[key] = value
|
result[key] = value1
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user