def isValidImage(field_data, all_data):
    from PIL import Image
    from cStringIO import StringIO
    try:
        content = field_data['content']
    except TypeError:
        raise ValidationError, gettext("No file was submitted. Check the encoding type on the form.")
    try:
        Image.open(StringIO(content))
    except IOError: # Python Imaging Library doesn't recognize it as an image
        raise ValidationError, gettext("Upload a valid image. The file you uploaded was either not an image or a corrupted image.")
Checks that the file-upload field data contains a valid image (GIF, JPG,
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-0.96/django/core/validators.py/isValidImage