'Converts values from Solr to native Python values.'

def _to_python(self, value):

    if isinstance(value, (int, float, long, complex)):
        return value
    if isinstance(value, (list, tuple)):
        value = value[0]
    if (value == u'true'):
        return True
    elif (value == u'false'):
        return False
    is_string = False
    if IS_PY3:
        if isinstance(value, bytes):
            value = force_unicode(value)
        if isinstance(value, str):
            is_string = True
    else:
        if isinstance(value, str):
            value = force_unicode(value)
        if isinstance(value, basestring):
            is_string = True
    if is_string:
        possible_datetime = DATETIME_REGEX.search(value)
        if possible_datetime:
            date_values = possible_datetime.groupdict()
            for (dk, dv) in date_values.items():
                date_values[dk] = int(dv)
            return datetime.datetime(date_values[u'year'], date_values[u'month'], date_values[u'day'], date_values[u'hour'], date_values[u'minute'], date_values[u'second'])
    try:
        return ast.literal_eval(value)
    except (ValueError, SyntaxError):
        pass
    return value
