'Converts python values to a form suitable for insertion into the xml
we send to solr.'

def _from_python(self, value):

    if hasattr(value, u'strftime'):
        if hasattr(value, u'hour'):
            offset = value.utcoffset()
            if offset:
                value = (value - offset)
            value = (value.replace(tzinfo=None).isoformat() + u'Z')
        else:
            value = (u'%sT00:00:00Z' % value.isoformat())
    elif isinstance(value, bool):
        if value:
            value = u'true'
        else:
            value = u'false'
    else:
        if IS_PY3:
            if isinstance(value, bytes):
                value = str(value, errors=u'replace')
        elif isinstance(value, str):
            value = unicode(value, errors=u'replace')
        value = u'{0}'.format(value)
    return clean_xml_string(value)
