Author: jacob
Date: 2010-02-14 12:33:01 -0600 (Sun, 14 Feb 2010)
New Revision: 12430
Modified:
django/branches/releases/1.1.X/django/core/files/images.py
django/branches/releases/1.1.X/django/core/management/validation.py
django/branches/releases/1.1.X/django/forms/fields.py
django/branches/releases/1.1.X/tests/modeltests/model_forms/models.py
django/branches/releases/1.1.X/tests/regressiontests/file_storage/tests.py
django/branches/releases/1.1.X/tests/regressiontests/model_fields/models.py
Log:
[1.1.X] Fixed #6054: work around PIL's installation brokeness by detecting
either of the two ways it can end up being installed.
Backport of [12429] from trunk.
Modified: django/branches/releases/1.1.X/django/core/files/images.py
===================================================================
--- django/branches/releases/1.1.X/django/core/files/images.py 2010-02-14
18:28:28 UTC (rev 12429)
+++ django/branches/releases/1.1.X/django/core/files/images.py 2010-02-14
18:33:01 UTC (rev 12430)
@@ -30,7 +30,12 @@
def get_image_dimensions(file_or_path):
"""Returns the (width, height) of an image, given an open file or a
path."""
- from PIL import ImageFile as PILImageFile
+ # Try to import PIL in either of the two ways it can end up installed.
+ try:
+ from PIL import ImageFile as PILImageFile
+ except ImportError:
+ import ImageFile as PILImageFile
+
p = PILImageFile.Parser()
close = False
if hasattr(file_or_path, 'read'):
Modified: django/branches/releases/1.1.X/django/core/management/validation.py
===================================================================
--- django/branches/releases/1.1.X/django/core/management/validation.py
2010-02-14 18:28:28 UTC (rev 12429)
+++ django/branches/releases/1.1.X/django/core/management/validation.py
2010-02-14 18:33:01 UTC (rev 12430)
@@ -47,10 +47,14 @@
if isinstance(f, models.FileField) and not f.upload_to:
e.add(opts, '"%s": FileFields require an "upload_to"
attribute.' % f.name)
if isinstance(f, models.ImageField):
+ # Try to import PIL in either of the two ways it can end up
installed.
try:
from PIL import Image
except ImportError:
- e.add(opts, '"%s": To use ImageFields, you need to install
the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/
.' % f.name)
+ try:
+ import Image
+ except ImportError:
+ e.add(opts, '"%s": To use ImageFields, you need to
install the Python Imaging Library. Get it at
http://www.pythonware.com/products/pil/ .' % f.name)
if isinstance(f, models.BooleanField) and getattr(f, 'null',
False):
e.add(opts, '"%s": BooleanFields do not accept null values.
Use a NullBooleanField instead.' % f.name)
if f.choices:
Modified: django/branches/releases/1.1.X/django/forms/fields.py
===================================================================
--- django/branches/releases/1.1.X/django/forms/fields.py 2010-02-14
18:28:28 UTC (rev 12429)
+++ django/branches/releases/1.1.X/django/forms/fields.py 2010-02-14
18:33:01 UTC (rev 12430)
@@ -483,7 +483,12 @@
return None
elif not data and initial:
return initial
- from PIL import Image
+
+ # Try to import PIL in either of the two ways it can end up installed.
+ try:
+ from PIL import Image
+ except ImportError:
+ import Image
# We need to get a file object for PIL. We might have a path or we
might
# have to read the data into memory.
Modified: django/branches/releases/1.1.X/tests/modeltests/model_forms/models.py
===================================================================
--- django/branches/releases/1.1.X/tests/modeltests/model_forms/models.py
2010-02-14 18:28:28 UTC (rev 12429)
+++ django/branches/releases/1.1.X/tests/modeltests/model_forms/models.py
2010-02-14 18:33:01 UTC (rev 12430)
@@ -99,11 +99,15 @@
return self.description
try:
- # If PIL is available, try testing ImageFields.
- # Checking for the existence of Image is enough for CPython, but
- # for PyPy, you need to check for the underlying modules
- # If PIL is not available, ImageField tests are omitted.
- from PIL import Image, _imaging
+ # If PIL is available, try testing ImageFields. Checking for the existence
+ # of Image is enough for CPython, but for PyPy, you need to check for the
+ # underlying modules If PIL is not available, ImageField tests are omitted.
+ # Try to import PIL in either of the two ways it can end up installed.
+ try:
+ from PIL import Image, _imaging
+ except ImportError:
+ import Image, _imaging
+
test_images = True
class ImageFile(models.Model):
Modified:
django/branches/releases/1.1.X/tests/regressiontests/file_storage/tests.py
===================================================================
--- django/branches/releases/1.1.X/tests/regressiontests/file_storage/tests.py
2010-02-14 18:28:28 UTC (rev 12429)
+++ django/branches/releases/1.1.X/tests/regressiontests/file_storage/tests.py
2010-02-14 18:33:01 UTC (rev 12430)
@@ -18,12 +18,16 @@
except ImportError:
import dummy_threading as threading
+# Try to import PIL in either of the two ways it can end up installed.
+# Checking for the existence of Image is enough for CPython, but
+# for PyPy, you need to check for the underlying modules
try:
- # Checking for the existence of Image is enough for CPython, but
- # for PyPy, you need to check for the underlying modules
from PIL import Image, _imaging
except ImportError:
- Image = None
+ try:
+ import Image, _imaging
+ except ImportError:
+ Image = None
class FileStorageTests(unittest.TestCase):
storage_class = FileSystemStorage
Modified:
django/branches/releases/1.1.X/tests/regressiontests/model_fields/models.py
===================================================================
--- django/branches/releases/1.1.X/tests/regressiontests/model_fields/models.py
2010-02-14 18:28:28 UTC (rev 12429)
+++ django/branches/releases/1.1.X/tests/regressiontests/model_fields/models.py
2010-02-14 18:33:01 UTC (rev 12430)
@@ -6,12 +6,17 @@
except ImportError:
from django.utils import _decimal as decimal # Python 2.3 fallback
+# Try to import PIL in either of the two ways it can end up installed.
+# Checking for the existence of Image is enough for CPython, but for PyPy,
+# you need to check for the underlying modules.
+
try:
- # Checking for the existence of Image is enough for CPython, but for PyPy,
- # you need to check for the underlying modules.
from PIL import Image, _imaging
except ImportError:
- Image = None
+ try:
+ import Image, _imaging
+ except ImportError:
+ Image = None
from django.core.files.storage import FileSystemStorage
from django.db import models
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.