All pastes #958696 Raw Edit

Mine

public text v1 · immutable
#958696 ·published 2008-03-26 21:36 UTC
rendered paste body
def __unicodify(data, encoding='utf-8'):
    '''Private function to transform strings into unicode strings.
    '''
    if isinstance(data, basestring):
        if not isinstance(data, unicode):
            data = unicode(data, encoding)
        # else we'll just return the data as it's already unicode
    elif isinstance(data, dict):
        for key in data:
            data[key] = __unicodify(data[key], encoding)
    elif isinstance(data, list):
        for key in xrange(0, len(data)):
            data[key] = __unicodify(data[key], encoding)
    elif isinstance(data, tuple):
        newTuple = []
        for key in xrange(0, len(data)):
            newTuple[key] = __unicodify(data[key], encoding)
        data[key] = tuple(newTuple)
    return data