2020-02-03 17:25:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from benedict.utils import type_util
|
|
|
|
|
|
|
|
|
2020-02-05 09:30:19 +00:00
|
|
|
def _clean_item(d, key, strings, collections):
|
|
|
|
value = d.get(key, None)
|
|
|
|
if not value:
|
|
|
|
del_none = (value is None)
|
|
|
|
del_string = (strings and type_util.is_string(value))
|
|
|
|
del_collection = (collections and type_util.is_collection(value))
|
|
|
|
return any([del_none, del_string, del_collection])
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2020-02-03 17:25:54 +00:00
|
|
|
def clean(d, strings=True, collections=True):
|
|
|
|
keys = list(d.keys())
|
|
|
|
for key in keys:
|
2020-02-05 09:30:19 +00:00
|
|
|
if _clean_item(d, key, strings, collections):
|
|
|
|
del d[key]
|