Exclude chars in dict keys and return a clean dictionary.
962412
def clean_dictkeys(ddict, exclusions=None):
    
    exclusions = [] if exclusions is None else exclusions

    if not isinstance(ddict, dict):
        return {}

    for key in list(ddict.keys()):
        if [incl for incl in exclusions if incl in key]:
            data = ddict.pop(key)
            clean_key = exclude_chars(key, exclusions)

            if clean_key:
                if clean_key in ddict:
                    ddict[clean_key] = force_list(ddict[clean_key])
                    add_element(ddict, clean_key, data)
                else:
                    ddict[clean_key] = data

        # dict case
        if isinstance(ddict.get(key), dict):
            ddict[key] = clean_dictkeys(ddict[key], exclusions)

        # list case
        elif isinstance(ddict.get(key), list):
            for row in ddict[key]:
                if isinstance(row, dict):
                    row = clean_dictkeys(row, exclusions)

    return ddict
462176
def decode_dict_keys_to_str(src):
    '''
    
    '''
    if not six.PY3 or not isinstance(src, dict):
        return src

    output = {}
    for key, val in six.iteritems(src):
        if isinstance(key, bytes):
            try:
                key = key.decode()
            except UnicodeError:
                pass
        output[key] = val
    return output
139817
def valid_dict(d, keys=None):
    

    if keys is None:
        d_ = d
    else:
        d_ = itemfilter(lambda item: item[0] in keys, d)
        if len(d_) != len(keys):
            return False
    values = list(itervalues(d_))
    return False if None in values else True
881538
def as_dict(self):
        """"""
        return {k: unfreeze(v)
                for k, v in self.items()
                if not self.is_special(k)}
1148052
def strip_accents(s, encoding= 'utf-8'):
    """"""
    if sys.version < '3':
        if isinstance(s,unicode):
           return unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore')
        else:
           return unicodedata.normalize('NFKD', unicode(s,encoding)).encode('ASCII', 'ignore')
    else:
        if isinstance(s,bytes): s = str(s,encoding)
        return str(unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore'),'ascii')
1220573
def clean_chars(value):
    ""
    value = value.replace('\xb9', ' ')
    value = value.replace('\xf8', ' ')
    value = value.replace('\xab', ' ')
    value = value.replace('\xa7', ' ')
    value = value.replace('\xa8', ' ')
    value = value.replace('\xfb', ' ')
    value = value.replace('\xfc', ' ')
    return value
1056510
def _stable_dict_repr(strdict):
    """"""
    lines = []
    for key in sorted(strdict.keys()):
        lines.append("'%s': %s" % (key, rpr(strdict[key])))
    return "{%s}" % ", ".join(lines)
717333
def dict(self):
        """"""
        res = copy(self)
        if MATCHES in res:
            del res[MATCHES]
        if NAME in res:
            del res[NAME]
        res = {self.name: res}
        for k, v in self.matches.items():
            res[k] = v
            if NAME in res[k]:
                del res[k][NAME]
        return res
614254
def str2dict_keys(str_in):
    '''
    
    '''
    tmp_dict = str2dict(str_in)
    if tmp_dict is None:
        return None
    return sorted([k for k in tmp_dict])
495081
def filter_dict(d, keys):
    
    return {k: v for k, v in d.items() if k in keys}
1090394
def clean_query_Dict(cls, query_Dict):
    
    return {k: v for k, v in query_Dict.items() if v}
1013697
def filter_out_none_valued_keys(self, d):
        # type: (typing.Dict[K, V]) -> typing.Dict[K, V]
        """"""
        new_d = {}
        for k, v in d.items():
            if v is not None:
                new_d[k] = v
        return new_d
914470
def to_dict(self, omit=()):
        
        result = self.__dict__.copy()
        for key in omit:
            if key in result:
                del result[key]
        return result
718236
def _json_clean(d):
    
    result = {}
    compkeys = {}
    for k, v in d.items():
        if not isinstance(k, tuple):
            result[k] = v
        else:
            #v is a list of entries for instance methods/constructors on the
            #UUID of the key. Instead of using the composite tuple keys, we
            #switch them for a string using the 
            key = "c.{}".format(id(k))
            result[key] = v
            compkeys[key] = k

    return (result, compkeys)
317531
def _opts_to_dict(*opts):
	''''''
	ret = {}
	for key, val in opts:
		if key[:2] == '--':
			key = key[2:]
		elif key[:1] == '-':
			key = key[1:]
		if val == '':
			val = True
		ret[key.replace('-','_')] = val
	return ret
1012493
def make_keys_safe(dct):
    """"""
    result = {}
    for key, val in dct.items():
        key = key.replace('-', '_')
        if key in keyword.kwlist:
            key = key + '_'
        result[key] = val
    return result
132829
def _sanitize(text):
    """"""
    d = {'-LRB-': '(', '-RRB-': ')'}
    return re.sub('|'.join(d.keys()), lambda m: d[m.group(0)], text)