Invert a dict. A dict is invertible if values are unique and hashable.
173541
def invert_dict(invertible_dict):
    """"""
    inverted = {}
    for k, v in six.iteritems(invertible_dict):
        if not isinstance(v, Hashable):
            raise TypeError(u'Expected an invertible dict, but value at key {} has type {}'.format(
                k, type(v).__name__))
        if v in inverted:
            raise TypeError(u'Expected an invertible dict, but keys '
                            u'{} and {} map to the same value'.format(
                                inverted[v], k))
        inverted[v] = k
    return inverted
527460
def from_dict(cls, d):
        """"""
        return cls(**{k: v for k, v in d.items() if k in cls.ENTRIES})
1214953
def is_dict_like(obj, attr=('keys', 'items')):
    """"""
    for a in attr:
        if not hasattr(obj, a):
            return False
    return True
1055320
def asDict(self, returnIntegers=True):
        
        d = {}
        for k, v in self.items():
            d[k] = v if not returnIntegers else normalizers.normalizeRounding(v)
        return d
1352903
def isdict(obj):
  '''
  
  '''
  return \
    not isstr(obj) \
    and ( isinstance(obj, dict) \
          or ( callable(getattr(obj, 'keys', None)) \
               and callable(getattr(obj, 'values', None)) \
               and callable(getattr(obj, 'items', None)) ))
1157890
def uniq(iterable):
	
	temp_dict = {}
	for e in iterable:
		if e not in temp_dict:
			yield temp_dict.setdefault(e, e)
443566
def jsonhash(obj, root=True, exclude=None, hash_func=_jsonhash_sha1):
    '''
    
    '''
    if isinstance(obj, Mapping):
        # assumption: using in against set() is faster than in against list()
        if root and exclude:
            obj = {k: v for k, v in obj.iteritems() if k not in exclude}
        # frozenset's don't guarantee order; use sorted tuples
        # which means different python interpreters can return
        # back frozensets with different hash values even when
        # the content of the object is exactly the same
        result = sorted(
            (k, jsonhash(v, False)) for k, v in obj.iteritems())
    elif isinstance(obj, list):
        # FIXME: should lists be sorted for consistent hashes?
        # when the object is the same, just different list order?
        result = tuple(jsonhash(e, False) for e in obj)
    else:
        result = obj
    if root:
        result = unicode(hash_func(result))
    return result
1260319
def deep_convert_dict(value):
    
    to_ret = value
    if isinstance(value, OrderedDict):
        to_ret = dict(value)

    try:
        for k, v in to_ret.items():
            to_ret[k] = deep_convert_dict(v)
    except AttributeError:
        pass

    return to_ret
1129277
def inverted_dict_of_lists(d):
    
    new_dict = {}
    for (old_key, old_value_list) in viewitems(dict(d)):
        for new_key in listify(old_value_list):
            new_dict[new_key] = old_key
    return new_dict
338135
def coerce(cls, key, value):
        """"""
        if not isinstance(value, MutationDict):
            if isinstance(value, dict):
                return MutationDict(value)

            # this call will raise ValueError
            return Mutable.coerce(key, value)
        else:
            return value
1279684
def hashdict(d):
    
    k = 0
    for key,val in d.items():
        k ^= hash(key) ^ hash(val)
    return k
172121
def _handle_key_value(t_dict, key, value):
    
    if key in t_dict:
        val = t_dict[key]
        if isinstance(val, str):
            val = [val]
        val.append(value)
        return val
    return value
1028915
def from_dict(cls, dictionary):
    ''''''
    query = cls(Key(dictionary['key']))

    for key, value in dictionary.items():

      if key == 'order':
        for order in value:
          query.order(order)

      elif key == 'filter':
        for filter in value:
          if not isinstance(filter, Filter):
            filter = Filter(*filter)
          query.filter(filter)

      elif key in ['limit', 'offset', 'offset_key']:
        setattr(query, key, value)
    return query
733300
def _reverse_lookup(dictionary, value):
    '''
    
    '''
    value_index = -1
    for idx, dict_value in enumerate(dictionary.values()):
        if type(dict_value) == list:
            if value in dict_value:
                value_index = idx
                break
        elif value == dict_value:
            value_index = idx
            break

    return list(dictionary)[value_index]
61683
def coerce(cls, key, value):
        """"""
        if isinstance(value, PasswordHash):
            return value
        return super(PasswordHash, cls).coerce(key, value)
419375
def hash(value):
    ''''''
    if not value:
        return
    elif len(value) == 32:
        type = 'md5'
    elif len(value) == 40:
        type = 'sha1'
    elif len(value) == 64:
        type = 'sha256'
    else:
        return None
    return {'type': type, 'value': value}
683327
def add_dict_to_hash(a_hash, a_dict):
    
    if a_dict is None:
        return
    for k, v in a_dict.items():
        a_hash.update(b'\x00' + k.encode('utf-8') + b'\x00' + v.encode('utf-8'))