def _set_attribute(self, obj, attr, value):
        field = obj._meta.get_field_by_name(attr)
        if len(value) > field[0].max_length:
            cleaned_value = value[:field[0].max_length]
            logger.warn('The attribute "%s" was trimmed from "%s" to "%s"' %
                        (attr, value, cleaned_value))
        else:
            cleaned_value = value

        old_value = getattr(obj, attr)
        if cleaned_value != old_value:
            setattr(obj, attr, cleaned_value)
            return True

        return False
Set an attribute of an object to a specific value.
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/djangosaml2-0.13.0/djangosaml2/backends.py/Saml2Backend._set_attribute