From 86296ad2cd5702a66b05aae79ec9196b62e41e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 7 Feb 2016 08:13:04 +0600 Subject: [utils] Add ability to control skipping false values in dict_get --- youtube_dl/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'youtube_dl/utils.py') diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 652dba59d..f3b0180ab 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1717,11 +1717,12 @@ def encode_dict(d, encoding='utf-8'): return dict((encode(k), encode(v)) for k, v in d.items()) -def dict_get(d, key_or_keys, default=None): +def dict_get(d, key_or_keys, default=None, skip_false_values=True): if isinstance(key_or_keys, (list, tuple)): for key in key_or_keys: - if d.get(key): - return d[key] + if key not in d or d[key] is None or skip_false_values and not d[key]: + continue + return d[key] return default return d.get(key_or_keys, default) -- cgit v1.2.3