X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Futils%2Fnested_dict.py;h=692ef5f15e42a828853167a212adc8b8748b67d9;hb=1f4df7c7ad27b23773ad9cdbe4db1632ce388cf1;hp=9bc3e999d888849a9a5eb60767ddc5faff166990;hpb=1af0d577ab6d8c431ae1322657c50efd5e0a1a93;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/utils/nested_dict.py b/ice_validator/tests/utils/nested_dict.py index 9bc3e99..692ef5f 100644 --- a/ice_validator/tests/utils/nested_dict.py +++ b/ice_validator/tests/utils/nested_dict.py @@ -38,27 +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