def to_python(self, data):
        f = super(ImageFormField, self).to_python(data)
        if f is None:
            return None

        # We need to get a file raw data to validate it.
        if hasattr(data, 'temporary_file_path'):
            with open(data.temporary_file_path(), 'rb') as fp:
                raw_data = fp.read()
        elif hasattr(data, 'read'):
            raw_data = data.read()
        else:
            raw_data = data['content']

        if not default.engine.is_valid_image(raw_data):
            raise forms.ValidationError(self.default_error_messages['invalid_image'])
        if hasattr(f, 'seek') and callable(f.seek):
            f.seek(0)

        return f
Checks that the file-upload field data contains a valid image (GIF,
dataset/ETHPy150Open mariocesar/sorl-thumbnail/sorl/thumbnail/fields.py/ImageFormField.to_python