diff options
| author | Daniel Lindsley <daniel@toastdriven.com> | 2013-05-14 19:31:16 -0700 |
|---|---|---|
| committer | Daniel Lindsley <daniel@toastdriven.com> | 2013-05-14 19:32:04 -0700 |
| commit | 33793f7c3edd8ff144ff2e9434367267c20af26a (patch) | |
| tree | 2fc05d98ee3d9c2bb9fd9a208647ad280d52b78c /django/forms | |
| parent | c792c83cad54f064b6ba13e285e95a90e2c61f09 (diff) | |
Fixed #19934 - Use of Pillow is now preferred over PIL.
This starts the deprecation period for PIL (support to end in 1.8).
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/fields.py | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 146a10d635..4ce57d34a3 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -602,13 +602,9 @@ class ImageField(FileField): if f is None: return None - # Try to import PIL in either of the two ways it can end up installed. - try: - from PIL import Image - except ImportError: - import Image + from django.utils.image import Image - # We need to get a file object for PIL. We might have a path or we might + # We need to get a file object for Pillow. We might have a path or we might # have to read the data into memory. if hasattr(data, 'temporary_file_path'): file = data.temporary_file_path() @@ -623,12 +619,8 @@ class ImageField(FileField): # image in memory, which is a DoS vector. See #3848 and #18520. # verify() must be called immediately after the constructor. Image.open(file).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 + except Exception: + # Pillow (or PIL) doesn't recognize it as an image. six.reraise(ValidationError, ValidationError(self.error_messages['invalid_image']), sys.exc_info()[2]) if hasattr(f, 'seek') and callable(f.seek): f.seek(0) |
