X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fbase_topic.py;h=1bc906c2b4d63594f84a2a129dac715125e35e7e;hp=c22833b87ae31a3270fc78f271b025a1a3d9d621;hb=332e080919376d26f7bb98478d9ebe14b73f4d03;hpb=32bab47c7fde8ae22795306723f3441ec544fa2b diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index c22833b..1bc906c 100644 --- a/osm_nbi/base_topic.py +++ b/osm_nbi/base_topic.py @@ -30,6 +30,21 @@ class EngineException(Exception): super(Exception, self).__init__(message) +def deep_get(target_dict, key_list): + """ + Get a value from target_dict entering in the nested keys. If keys does not exist, it returns None + Example target_dict={a: {b: 5}}; key_list=[a,b] returns 5; both key_list=[a,b,c] and key_list=[f,h] return None + :param target_dict: dictionary to be read + :param key_list: list of keys to read from target_dict + :return: The wanted value if exist, None otherwise + """ + for key in key_list: + if not isinstance(target_dict, dict) or key not in target_dict: + return None + target_dict = target_dict[key] + return target_dict + + def get_iterable(input_var): """ Returns an iterable, in case input_var is None it just returns an empty tuple @@ -389,7 +404,7 @@ class BaseTopic: rollback.append({"topic": self.topic, "_id": _id}) if op_id: content["op_id"] = op_id - self._send_msg("create", content) + self._send_msg("created", content) return _id, op_id except ValidationError as e: raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY) @@ -510,7 +525,7 @@ class BaseTopic: if op_id: indata["op_id"] = op_id indata["_id"] = _id - self._send_msg("edit", indata) + self._send_msg("edited", indata) return op_id except ValidationError as e: raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)