Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 4016d5264ab049c33c845c5337ce2a3e50754268 1 parent bfcecbf
Russell Keith-Magee authored
1  AUTHORS
@@ -150,6 +150,7 @@ answer newbie questions, and generally made Django that much better:
150 150
     Stefane Fermgier <sf@fermigier.com>
151 151
     Afonso Fernández Nogueira <fonzzo.django@gmail.com>
152 152
     J. Pablo Fernandez <pupeno@pupeno.com>
  153
+    Maciej Fijalkowski
153 154
     Matthew Flanagan <http://wadofstuff.blogspot.com>
154 155
     Eric Floehr <eric@intellovations.com>
155 156
     Vincent Foley <vfoleybourgon@yahoo.ca>
5  django/forms/fields.py
@@ -503,6 +503,11 @@ def clean(self, data, initial=None):
503 503
             #  but it must be called immediately after the constructor
504 504
             trial_image = Image.open(file)
505 505
             trial_image.verify()
  506
+        except ImportError: 
  507
+            # Under PyPy, it is possible to import PIL. However, the underlying
  508
+            # _imaging C module isn't available, so an ImportError will be 
  509
+            # raised. Catch and re-raise. 
  510
+            raise
506 511
         except Exception: # Python Imaging Library doesn't recognize it as an image
507 512
             raise ValidationError(self.error_messages['invalid_image'])
508 513
         if hasattr(f, 'seek') and callable(f.seek):
6  tests/modeltests/model_forms/models.py
@@ -69,8 +69,10 @@ class ImageFile(models.Model):
69 69
     description = models.CharField(max_length=20)
70 70
     try:
71 71
         # If PIL is available, try testing PIL.
72  
-        # Otherwise, it's equivalent to TextFile above.
73  
-        import Image
  72
+        # Checking for the existence of Image is enough for CPython, but
  73
+        # for PyPy, you need to check for the underlying modules
  74
+        # If PIL is not available, this test is equivalent to TextFile above.
  75
+        import Image, _imaging
74 76
         image = models.ImageField(upload_to=tempfile.gettempdir())
75 77
     except ImportError:
76 78
         image = models.FileField(upload_to=tempfile.gettempdir())

0 notes on commit 4016d52

Please sign in to comment.
Something went wrong with that request. Please try again.