Walks a simple data structure, converting unicode to byte string.

    Supports lists, tuples, and dictionaries.

def to_utf8(obj):
    """Walks a simple data structure, converting unicode to byte string.

    Supports lists, tuples, and dictionaries.
    """
    if isinstance(obj, unicode_type):
        return _utf8(obj)
    elif isinstance(obj, dict):
        return dict((to_utf8(k), to_utf8(v)) for (k, v) in obj.items())
    elif isinstance(obj, list):
        return list(to_utf8(i) for i in obj)
    elif isinstance(obj, tuple):
        return tuple(to_utf8(i) for i in obj)

    return obj