X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Futils%2Fnested_dict.py;h=692ef5f15e42a828853167a212adc8b8748b67d9;hb=refs%2Fchanges%2F62%2F74762%2F2;hp=24f7e5e5c4e45a7e9cdc728b04f21b989756ad81;hpb=ca9085f0f77d442d3741a8c754e65cc45b6a318d;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/utils/nested_dict.py b/ice_validator/tests/utils/nested_dict.py index 24f7e5e..692ef5f 100644 --- a/ice_validator/tests/utils/nested_dict.py +++ b/ice_validator/tests/utils/nested_dict.py @@ -38,28 +38,30 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -'''nested_dict.get -''' +"""nested_dict.get +""" -VERSION = '1.0.0' +VERSION = "1.1.1" -def get(dic, *keys): - '''Return the value of the last key given a (nested) dict - and list of keys. If any key is missing, or if the value - of any key except the last is not a dict, then None is returned. - ''' +def get(dic, *keys, **kwargs): + """Return the value of the last key given a (nested) dict and + list of keys. If any key is missing, or if the value of any key + except the last is not a dict, then the default value is returned. + The default value may be passed in using the keyword 'default=', + otherwise the default value is None. + """ d = dic + default = kwargs.get("default", None) for key in keys: - if hasattr(d, 'get'): - d = d.get(key) + if hasattr(d, "get"): + d = d.get(key, default) else: - return None + return default return d def is_dict_has_key(obj, key): - '''return True/False `obj` is a dict and has `key` - ''' + """return True/False `obj` is a dict and has `key` + """ return isinstance(obj, dict) and key in obj -