def to_python(self, data):
f = super(ImageFormField, self).to_python(data)<EOL>if f is None:<EOL><INDENT>return None<EOL><DEDENT>if hasattr(data, '<STR_LIT>'):<EOL><INDENT>with open(data.temporary_file_path(), '<STR_LIT:rb>') as fp:<EOL><INDENT>raw_data = fp.read()<EOL><DEDENT><DEDENT>elif hasattr(data, '<STR_LIT>'):<EOL><INDENT>raw_data = data.read()<EOL><DEDENT>else:<EOL><INDENT>raw_data = data['<STR_LIT:content>']<EOL><DEDENT>if not default.engine.is_valid_image(raw_data):<EOL><INDENT>raise forms.ValidationError(self.default_error_messages['<STR_LIT>'])<EOL><DEDENT>if hasattr(f, '<STR_LIT>') and callable(f.seek):<EOL><INDENT>f.seek(<NUM_LIT:0>)<EOL><DEDENT>return f<EOL>
Checks that the file-upload field data contains a valid image (GIF,
JPG, PNG, possibly others -- whatever the engine supports).