1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #7727 -- Improved the checks for import failure when using PIL. Under PyPy, you can import the PIL module, but when you try to use it, the underlying _imaging module will not be available. Thanks to Maciej Fijalkowski (fijal) for the report and suggested fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8016 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2008-07-21 11:52:11 +00:00
parent bfcecbffd3
commit 4016d5264a
3 changed files with 10 additions and 2 deletions

View File

@@ -503,6 +503,11 @@ class ImageField(FileField):
# but it must be called immediately after the constructor
trial_image = Image.open(file)
trial_image.verify()
except ImportError:
# Under PyPy, it is possible to import PIL. However, the underlying
# _imaging C module isn't available, so an ImportError will be
# raised. Catch and re-raise.
raise
except Exception: # Python Imaging Library doesn't recognize it as an image
raise ValidationError(self.error_messages['invalid_image'])
if hasattr(f, 'seek') and callable(f.seek):