Ensure all dict elements are Bunch.
517773
def _bunchify(b):
    """"""
    assert isinstance(b, dict)
    b = Bunch(b)
    for k in b:
        if isinstance(b[k], dict):
            b[k] = Bunch(b[k])
    return b
729904
def scrub(data):
    """"""
    # blanks, Nones, and empty strings can stay as is
    if not data:
        return data
    if isinstance(data, (int, float)):
        return data
    if isinstance(data, list):
        return [scrub(entry) for entry in data]
    if isinstance(data, dict):
        return {scrub(key): scrub(value) for key, value in data.items()}
    try:
        return json.encoder.encode_basestring(data)[1:-1]
    except TypeError as exc:
        raise ValidationError("Input '%s' is not a permitted type: %s" % (data,
                                                                          exc))
    except Exception as exc:
        raise ValidationError("Input '%s' not permitted: %s" % (data, exc))
1214953
def is_dict_like(obj, attr=('keys', 'items')):
    """"""
    for a in attr:
        if not hasattr(obj, a):
            return False
    return True
930574
def clean_dict(d):
    

    if not isinstance(d, (dict, list)):
        return d
    if isinstance(d, list):
        return [v for v in (clean_dict(v) for v in d) if v]
    return OrderedDict(
        [(k, v) for k, v in ((k, clean_dict(v)) for k, v in list(d.items())) if v]
    )
229041
def _filter_keys(d: dict, keys: set) -> dict:
        
        return {key: d[key] for key in keys if key in d}
1306898
function(all, begin, key, end) {
              if (key in dict) {
                return begin + dict[key] + end
              }

              return all;
            }
496510
def _ensure_array(self, key, value):
        """"""
        if key not in self._json_dict:
            self._json_dict[key] = []

            self._size += 2             # brackets
            self._ensure_field(key)

        if len(self._json_dict[key]) > 0:
            # this array already has an entry, so add comma and space
            self._size += 2

        if isinstance(value, str):
            self._size += 2  # quotes
        self._size += len(str(value))

        self._json_dict[key].append(value)
495081
def filter_dict(d, keys):
    
    return {k: v for k, v in d.items() if k in keys}
1026532
def compare(dicts):
    """"""

    common_members = {}
    common_keys = reduce(lambda x, y: x & y, map(dict.keys, dicts))
    for k in common_keys:
        common_members[k] = list(
            reduce(lambda x, y: x & y, [set(d[k]) for d in dicts]))

    return common_members
1198437
def ensure_a_list(data):
    """"""
    if not data:
        return []
    if isinstance(data, (list, tuple, set)):
        return list(data)
    if isinstance(data, str):
        data = trimmed_split(data)  # settings.toml,other.yaml
        return data
    return [data]
1085311
def _merge_unbound_var_dicts(src, dst):
  """"""
  for k, v in six.iteritems(src):
    if dst.get(k, v) != v:
      trace1 = ''.join(scopes.skip_common_stack_elements(v.stacktrace, dst[
          k].stacktrace))
      trace2 = ''.join(
          scopes.skip_common_stack_elements(dst[k].stacktrace, v.stacktrace))
      raise ValueError('Key conflict: %s\nDefined At:\n%s\nand\n%s' %
                       (k, trace1, trace2))
    else:
      dst[k] = v
1110358
def _dict_subset(keys, master_dict):
    '''
    
    '''
    return dict([(k, v) for k, v in six.iteritems(master_dict) if k in keys])
1295808
def __enforce_only_strings_dict(dictionary):
    '''
    
    '''
    ret = {}

    for key, value in iteritems(dictionary):
        ret[six.text_type(key)] = six.text_type(value)

    return ret
346329
def all(self, as_dict=False, as_ordereddict=False):
        """"""

        # By calling list it calls the __iter__ method
        rows = list(self)

        if as_dict:
            return [r.as_dict() for r in rows]
        elif as_ordereddict:
            return [r.as_dict(ordered=True) for r in rows]

        return rows
216491
def filter_dict(iterable, keys):
  
  if type(keys) is not list:
    keys = [keys]
  for i in iterable:
    try:
      d = {}
      for a in keys:
        try:
          d[a] = i[a]
        except KeyError:
          pass
      if d != {}:
        yield d
    except Exception:
      pass
612583
def dict_clip(a_dict, inlude_keys_lst=[]):
    """"""
    return dict([[i[0], i[1]] for i in list(a_dict.items()) if i[0] in inlude_keys_lst])
715881
def _cleanup(lst):
    '''
    
    '''
    clean = []
    for ele in lst:
        if ele and isinstance(ele, dict):
            clean.append(ele)
    return clean