def simplify_value(value):
    if hasattr(value, 'simplify_for_render'):
        return value.simplify_for_render(simplify_value, simplify_model)
    elif isinstance(value, dict):
        out = {}
        for key in value:
            new_key = key if isinstance(key, (basestring, int)) else str(key)
            try:
                out[new_key] = simplify_value(value[key])
            except __HOLE__:
                logger.info('Could not simplify field %s of type %s',
                            key, type(value[key]), exc_info=True)
                pass
        return out
    elif isinstance(value, tuple) and hasattr(value, '_asdict'):
        # Handle named tuples as dicts
        return simplify_value(value._asdict())
    elif isinstance(value, (list, tuple, set, frozenset)):
        out = []
        for subvalue in value:
            try:
                out.append(simplify_value(subvalue))
            except NotImplementedError:
                logger.info('Could not simplify a value of type %s',
                            type(subvalue), exc_info=True)
        if isinstance(value, tuple):
            return tuple(out)
        else:
            return out
    elif isinstance(value, (basestring, int, float)):
        return value
    elif isinstance(value, lazy_translation):
        return unicode(value)
    elif isinstance(value, datetime.datetime):
        return DateTimeUnicode(value.isoformat(' '))
    elif isinstance(value, datetime.date):
        return DateUnicode(value.isoformat())
    elif hasattr(type(value), '__mro__') and models.Model in type(value).__mro__:
        return simplify_model(value)
    elif isinstance(value, Page):
        return {
            'has_next': value.has_next(),
            'has_previous': value.has_next(),
            'next_page_number': value.has_next(),
            'previous_page_number': value.has_next(),
            'number': value.number,
            'objects': simplify_value(value.object_list),
            'num_pages': value.paginator.num_pages,
            'num_objects': value.paginator.count,
        }
    elif value is None:
        return None
    elif isinstance(value, Point):
        return simplify_value(list(value))
    elif isinstance(value, Distance):
        # This is here to avoid a circular import
        from molly.utils.templatetags.molly_utils import humanise_distance
        return simplify_value(humanise_distance(value.m))
    elif hasattr(value, '__iter__'):
        # Iterators may be unbounded; silently ignore elements once we've already had 1000.
        return [simplify_value(item) for item in itertools.islice(value, 1000)]
    else:
        raise NotImplementedError
dataset/ETHPy150Open mollyproject/mollyproject/molly/utils/simplify.py/simplify_value