mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-24 14:28:32 +03:00
tlv: Fix from_dict() symmetry
the to_dict() method generates a {class_name: value} dictionary,
for both the nested and non-nested case. However, before this patch,
the from_dict() method expects a plain list of child IE dicts
in the nested case. This is illogical.
Let's make sure from_dict always expectes a {class_name: value} dict
for both nested and non-nested situations.
Change-Id: I07e4feb3800b420d8be7aae8911f828f1da9dab8
This commit is contained in:
@@ -157,13 +157,13 @@ class IE(Transcodable, metaclass=TlvMeta):
|
|||||||
def from_dict(self, decoded: dict):
|
def from_dict(self, decoded: dict):
|
||||||
"""Set the IE internal decoded representation to data from the argument.
|
"""Set the IE internal decoded representation to data from the argument.
|
||||||
If this is a nested IE, the child IE instance list is re-created."""
|
If this is a nested IE, the child IE instance list is re-created."""
|
||||||
|
expected_key_name = camel_to_snake(type(self).__name__)
|
||||||
|
if not expected_key_name in decoded:
|
||||||
|
raise ValueError("Dict %s doesn't contain expected key %s" % (decoded, expected_key_name))
|
||||||
if self.nested_collection:
|
if self.nested_collection:
|
||||||
self.children = self.nested_collection.from_dict(decoded)
|
self.children = self.nested_collection.from_dict(decoded[expected_key_name])
|
||||||
else:
|
else:
|
||||||
self.children = []
|
self.children = []
|
||||||
expected_key_name = camel_to_snake(type(self).__name__)
|
|
||||||
if not expected_key_name in decoded:
|
|
||||||
raise ValueError("Dict %s doesn't contain expected key %s" % (decoded, expected_key_name))
|
|
||||||
self.decoded = decoded[expected_key_name]
|
self.decoded = decoded[expected_key_name]
|
||||||
|
|
||||||
def is_constructed(self):
|
def is_constructed(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user