laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/35238?usp=email )


Change subject: flatten_dict_lists(): Don't flatten lists with duplicate keys
......................................................................

flatten_dict_lists(): Don't flatten lists with duplicate keys

If we have a list of dicts, and we flatten that into a dict: Only
do that if there are no dicts with duplocate key values in the list,
as otherwise we will loose information during the transformation.

Change-Id: I7f6d03bf323a153f3172853a3ef171cbec8aece7
Closes: OS#6288
---
M pySim/tlv.py
1 file changed, 19 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/38/35238/1

diff --git a/pySim/tlv.py b/pySim/tlv.py
index 7f20559..1ecc806 100644
--- a/pySim/tlv.py
+++ b/pySim/tlv.py
@@ -435,8 +435,12 @@
                 return False
         return True

+    def are_elements_unique(lod):
+        set_of_keys = set([list(x.keys())[0] for x in lod])
+        return len(lod) == len(set_of_keys)
+
     if isinstance(inp, list):
-        if are_all_elements_dict(inp):
+        if are_all_elements_dict(inp) and are_elements_unique(inp):
             # flatten into one shared dict
             newdict = {}
             for e in inp:

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/35238?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I7f6d03bf323a153f3172853a3ef171cbec8aece7
Gerrit-Change-Number: 35238
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-MessageType: newchange

Reply via email to