|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /usr/lib64/python2.7/site-packages/django/utils/ |
Upload File : |
�
r�\c @ ss d Z d d l m Z d d l Z d d l m Z d d l m Z d a
d a d a d � Z
e
� \ a
a a d S( u�
To provide a shim layer over Pillow/PIL situation until the PIL support is
removed.
Combinations To Account For
===========================
* Pillow:
* never has ``_imaging`` under any Python
* has the ``Image.alpha_composite``, which may aid in detection
* PIL
* CPython 2.x may have _imaging (& work)
* CPython 2.x may *NOT* have _imaging (broken & needs a error message)
* CPython 3.x doesn't work
* PyPy will *NOT* have _imaging (but works?)
* On some platforms (Homebrew and RHEL6 reported) _imaging isn't available,
the needed import is from PIL import _imaging (refs #21355)
Restated, that looks like:
* If we're on Python 2.x, it could be either Pillow or PIL:
* If ``import _imaging`` results in ``ImportError``, either they have a
working Pillow installation or a broken PIL installation, so we need to
detect further:
* To detect, we first ``import Image``.
* If ``Image`` has a ``alpha_composite`` attribute present, only Pillow
has this, so we assume it's working.
* If ``Image`` DOES NOT have a ``alpha_composite``attribute, it must be
PIL & is a broken (likely C compiler-less) install, which we need to
warn the user about.
* If ``import _imaging`` works, it must be PIL & is a working install.
* Python 3.x
* If ``import Image`` works, it must be Pillow, since PIL isn't Python 3.x
compatible.
* PyPy
* If ``import _imaging`` results in ``ImportError``, it could be either
Pillow or PIL, both of which work without it on PyPy, so we're fine.
Approach
========
* Attempt to import ``Image``
* ``ImportError`` - nothing is installed, toss an exception
* Either Pillow or the PIL is installed, so continue detecting
* Attempt to ``hasattr(Image, 'alpha_composite')``
* If it works, it's Pillow & working
* If it fails, we've got a PIL install, continue detecting
* The only option here is that we're on Python 2.x or PyPy, of which
we only care about if we're on CPython.
* If we're on CPython, attempt to ``from PIL import _imaging`` and
``import _imaging``
* ``ImportError`` - Bad install, toss an exception
i����( t unicode_literalsN( t ImproperlyConfigured( t
ugettext_lazyc C s� t d k r t t t f St } y d d l m } WnO t k
r� } y d d l } Wq� t k
r� } t t d � | � � q� Xn Xt | d � r� t } n� d d l
} | j � j � d k r(y d d l m } Wq(t k
r$y d d l } Wq%t k
r } t t d � | � � q%Xq(Xn y d d l m } Wn t k
r[d d l } n X| t k rt
j d d
t � n | | | f S( Ni����( t Imageu, Neither Pillow nor PIL could be imported: %su alpha_compositeu cpython( t _imagingu; The '_imaging' module for the PIL could not be imported: %s( t ImageFileu: Support for the PIL will be removed in Django 1.8. Please u&