Changeset 6175
- Timestamp:
- 09/14/07 02:18:27 (8 months ago)
- Files:
-
- django/trunk/django/core/validators.py (modified) (1 diff)
- django/trunk/django/newforms/fields.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/validators.py
r6096 r6175 182 182 raise ValidationError, _("No file was submitted. Check the encoding type on the form.") 183 183 try: 184 Image.open(StringIO(content)) 185 except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image 186 # OverflowError is due to a bug in PIL with Python 2.4+ which can cause 187 # it to gag on OLE files. 184 # load() is the only method that can spot a truncated JPEG, 185 # but it cannot be called sanely after verify() 186 trial_image = Image.open(StringIO(content)) 187 trial_image.load() 188 # verify() is the only method that can spot a corrupt PNG, 189 # but it must be called immediately after the constructor 190 trial_image = Image.open(StringIO(content)) 191 trial_image.verify() 192 except Exception: # Python Imaging Library doesn't recognize it as an image 188 193 raise ValidationError, _("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") 189 194 django/trunk/django/newforms/fields.py
r6173 r6175 394 394 from cStringIO import StringIO 395 395 try: 396 Image.open(StringIO(f.content)) 397 except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image 398 # OverflowError is due to a bug in PIL with Python 2.4+ which can cause 399 # it to gag on OLE files. 396 # load() is the only method that can spot a truncated JPEG, 397 # but it cannot be called sanely after verify() 398 trial_image = Image.open(StringIO(f.content)) 399 trial_image.load() 400 # verify() is the only method that can spot a corrupt PNG, 401 # but it must be called immediately after the constructor 402 trial_image = Image.open(StringIO(f.content)) 403 trial_image.verify() 404 except Exception: # Python Imaging Library doesn't recognize it as an image 400 405 raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) 401 406 return f
