Force key in dict or list to a string.
    Fixes: https://github.com/cameronmaske/celery-once/issues/11
559720
def force_string(kwargs):
    
    if isinstance(kwargs, dict):
        # Context: https://github.com/cameronmaske/celery-once/issues/58
        # Keep equivalent to string of dict for backwards compatibility.
        return order_dict_to_string(OrderedDict(
            (force_string(key), force_string(value))
            for key, value in items_sorted_by_key(kwargs)
        ))
    elif isinstance(kwargs, list):
        return [force_string(element) for element in kwargs]
    elif six.PY2 and isinstance(kwargs, unicode):
        return kwargs.encode('utf-8')
    return kwargs
263297
def first_key(res):
    
    if not isinstance(res, dict):
        raise ValueError('Value should be of dict type')

    if len(res.keys()) != 1:
        raise RedisClusterException("More then 1 result from command")

    return list(res.values())[0]
409873
def getlist(self, key, delimiter=',', **kwargs):
        

        value = self.get(key, **kwargs)
        if value is None: return value
        if isinstance(value, str):
            value = value.strip()
            if value.startswith('[') and value.endswith(']'):
                return self.getserialized(key)

            return [p.strip(' ') for p in value.split(delimiter)]
        #end if

        return list(value)
803700
def serialize(dictionary):
    

    data = []
    for key, value in dictionary.items():
        data.append('{0}="{1}"'.format(key, value))
    return ', '.join(data)
283750
def _dict_to_string(dictionary):
    '''
    
    '''
    ret = ''
    for key, val in sorted(dictionary.items()):
        if isinstance(val, dict):
            for line in _dict_to_string(val):
                ret += six.text_type(key) + '-' + line + '\n'
        elif isinstance(val, list):
            text = ' '.join([six.text_type(item) for item in val])
            ret += six.text_type(key) + ': ' + text + '\n'
        else:
            ret += six.text_type(key) + ': ' + six.text_type(val) + '\n'
    return ret.splitlines()
1271079
def pretty_dict_string(d, indent=0):
    
    s = ''
    for key, value in sorted(d.items()):
        s += '    ' * indent + str(key)
        if isinstance(value, dict):
             s += '\n' + pretty_dict_string(value, indent+1)
        else:
             s += '=' + str(value) + '\n'
    return s
5991
def make_key(*criteria):
    """"""
    criteria = [stringify(c) for c in criteria]
    criteria = [c for c in criteria if c is not None]
    if len(criteria):
        return ':'.join(criteria)
1116057
def transform_list_to_dict(list):
    

    ret = {}

    for value in list:
        if isinstance(value, dict):
            ret.update(value)
        else:
            ret[str(value)] = True

    return ret
312118
def _make_key(self):
        """"""
        value = (self._opener,
                 self._args,
                 'a' if self._mode == 'w' else self._mode,
                 tuple(sorted(self._kwargs.items())))
        return _HashedSequence(value)
860125
def _stringifyKeys(d):
    
    return dict((k.encode('ascii'), v)  for (k, v) in d.iteritems())
1029519
def _id_or_key(list_item):
    '''
    
    '''
    if isinstance(list_item, dict):
        if 'id' in list_item:
            return list_item['id']
        if 'key' in list_item:
            return list_item['key']
    return list_item
1134084
def get_as_string(self, key):
        
        value = self.get(key)
        return StringConverter.to_string(value)
727031
def __respond_with_dict(self, data):
        
        response = {}
        if isinstance(data, list):
            temp_data, data = data, {}
            for key, value in enumerate(temp_data):
                data[key] = value

        data.pop('seq', None)
        for index, item in data.items():
            values = item
            if isinstance(item, list) or isinstance(item, dict):
                values = self.__respond_with_dict(item)

            if isinstance(values, dict) and len(values) == 1:
                (key, values), = values.items()
            response[index] = values

        return response
1156584
def dict_keys_without_hyphens(a_dict):
    """"""
    return dict(
        (key.replace('-', '_'), val) for key, val in a_dict.items())
611530
def _iter_keys_as_str(key):
    
    for i in range(winreg.QueryInfoKey(key)[0]):
        yield winreg.EnumKey(key, i)
694729
def convert_to_str(d):
    
    d2 = {}
    for k, v in d.items():
        k = str(k)
        if type(v) in [list, tuple]:
            d2[k] = [str(a) for a in v]
        elif type(v) is dict:
            d2[k] = convert_to_str(v)
        else:
            d2[k] = str(v)
    return d2
849923
def base_dict_to_string(base_dict):
    
    outstr = ''
    # First, sort base_dict so that major allele always comes first - makes output report nicer to look at.
    base_list = sorted(base_dict.items(), key=lambda kv: kv[1], reverse=True)
    for base in base_list:
        outstr += '{}:{};'.format(base[0], base[1])
    return outstr[:-1]