Django

Code

Changeset 8016

Show
Ignore:
Timestamp:
07/21/08 06:52:11 (5 months ago)
Author:
russellm
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r7967 r8016  
    151151    Afonso Fernández Nogueira <fonzzo.django@gmail.com> 
    152152    J. Pablo Fernandez <pupeno@pupeno.com> 
     153    Maciej Fijalkowski 
    153154    Matthew Flanagan <http://wadofstuff.blogspot.com> 
    154155    Eric Floehr <eric@intellovations.com> 
  • django/trunk/django/forms/fields.py

    r7977 r8016  
    504504            trial_image = Image.open(file) 
    505505            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 
    506511        except Exception: # Python Imaging Library doesn't recognize it as an image 
    507512            raise ValidationError(self.error_messages['invalid_image']) 
  • django/trunk/tests/modeltests/model_forms/models.py

    r7998 r8016  
    7070    try: 
    7171        # 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 
    7476        image = models.ImageField(upload_to=tempfile.gettempdir()) 
    7577    except ImportError: