o
    Z#a$                  
   @   s   d dl Z d dlZd dlZd dlZd dlZddlmZ dddddd	Zd
d Zdd Z	dd Z
dddddZdd Zdd Zdd Zdddddd d!d"d#d$	Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd4d2d3ZdS )5    N   )Image)PIL._imagingPILLOW_VERSION)zPIL._tkinter_finder
tk_version)PIL._imagingftfreetype2_version)zPIL._imagingcmslittlecms_version)	PIL._webpwebpdecoder_version)piltkinter	freetype2
littlecms2webpc                 C   sF   | t vrtd|  t |  \}}zt| W dS  ty"   Y dS w )z
    Checks if a module is available.

    :param feature: The module to check for.
    :returns: ``True`` if available, ``False`` otherwise.
    :raises ValueError: If the module is not defined in this version of Pillow.
    zUnknown module TF)modules
ValueError
__import__ImportErrorfeaturemodulever r   ./usr/lib/python3/dist-packages/PIL/features.pycheck_module   s   r   c                 C   s8   t | sdS t|  \}}|du rdS tt||gd|S )z
    :param feature: The module to check for.
    :returns:
        The loaded version number as a string, or ``None`` if unknown or not available.
    :raises ValueError: If the module is not defined in this version of Pillow.
    Nfromlist)r   r   getattrr   r   r   r   r   version_module'   s   r   c                   C      dd t D S )z4
    :returns: A list of all supported modules.
    c                 S      g | ]}t |r|qS r   )r   .0fr   r   r   
<listcomp>=       z)get_supported_modules.<locals>.<listcomp>)r   r   r   r   r   get_supported_modules9      r'   )jpegjpeglib)jpeg2kjp2klib)zipzlib)libtiffr/   )jpgjpg_2000r.   r/   c                 C   s4   | t vrtd|  t |  \}}|d ttjv S )z
    Checks if a codec is available.

    :param feature: The codec to check for.
    :returns: ``True`` if available, ``False`` otherwise.
    :raises ValueError: If the codec is not defined in this version of Pillow.
    zUnknown codec _encoder)codecsr   dirr   core)r   codeclibr   r   r   check_codecH   s   r8   c                 C   sL   t | sdS t|  \}}ttj|d }| dkr$|dd dd S |S )a  
    :param feature: The codec to check for.
    :returns:
        The version number as a string, or ``None`` if not available.
        Checked at compile time for ``jpg``, run-time otherwise.
    :raises ValueError: If the codec is not defined in this version of Pillow.
    N_versionr/   
r   zVersion r   )r8   r3   r   r   r5   split)r   r6   r7   versionr   r   r   version_codecX   s   r=   c                   C   r    )z3
    :returns: A list of all supported codecs.
    c                 S   r!   r   )r8   r"   r   r   r   r%   q   r&   z(get_supported_codecs.<locals>.<listcomp>)r3   r   r   r   r   get_supported_codecsm   r(   r>   )r
   HAVE_WEBPANIMN)r
   HAVE_WEBPMUXN)r
   HAVE_TRANSPARENCYN)r   	HAVE_RAQMraqm_version)r   HAVE_FRIBIDIfribidi_version)r   HAVE_HARFBUZZharfbuzz_version)r   HAVE_LIBJPEGTURBOlibjpeg_turbo_version)r   HAVE_LIBIMAGEQUANTimagequant_version)r   HAVE_XCBN)		webp_animwebp_muxtransp_webpraqmfribidiharfbuzzlibjpeg_turbolibimagequantxcbc                 C   sT   | t vrtd|  t |  \}}}zt|dgd}t||W S  ty)   Y dS w )z
    Checks if a feature is available.

    :param feature: The feature to check for.
    :returns: ``True`` if available, ``False`` if unavailable, ``None`` if unknown.
    :raises ValueError: If the feature is not defined in this version of Pillow.
    zUnknown feature PILr   N)featuresr   r   r   r   )r   r   flagr   imported_moduler   r   r   check_feature   s   rZ   c                 C   s:   t | sdS t|  \}}}|du rdS tt||gd|S )z
    :param feature: The feature to check for.
    :returns: The version number as a string, or ``None`` if not available.
    :raises ValueError: If the feature is not defined in this version of Pillow.
    Nr   )rZ   rW   r   r   )r   r   rX   r   r   r   r   version_feature   s   r[   c                   C   r    )z5
    :returns: A list of all supported features.
    c                 S   r!   r   )rZ   r"   r   r   r   r%      r&   z*get_supported_features.<locals>.<listcomp>)rW   r   r   r   r   get_supported_features   r(   r\   c                 C   sJ   | t v rt| S | tv rt| S | tv rt| S tjd|  ddd dS )z
    :param feature: A module, codec, or feature name.
    :returns:
        ``True`` if the module, codec, or feature is available,
        ``False`` or ``None`` otherwise.
    zUnknown feature 'z'.   )
stacklevelF)r   r   r3   r8   rW   rZ   warningswarnr   r   r   r   check   s   rb   c                 C   s4   | t v rt| S | tv rt| S | tv rt| S dS )z
    :param feature:
        The module, codec, or feature to check for.
    :returns:
        The version number as a string, or ``None`` if unknown or not available.
    N)r   r   r3   r=   rW   r[   ra   r   r   r   r<      s   r<   c                  C   s"   t  } | t  | t  | S )zJ
    :returns: A list of all supported modules, features, and codecs.
    )r'   extendr\   r>   )retr   r   r   get_supported   s   re   Tc              	   C   s  | du rt j} t  td| d tdtj | d t j }td|d 	  | d |dd D ]}td|	  | d q3td| d td	t
jtj | d td
t
jtjj | d td| d dD ]r\}}t|r|dkrtdrdtd }nt|}|dur|dv }|dkrtdd |dD dk }|rdnd}|dkrdD ]}t|}	|	dur|d| d|	 7 }qtd|d||| d qltd|d| d qltd|d| d qltd| d |rtt}
tj D ]\}}|
| | qttjD ]~}| }|tjv r| dtj|  }t|| d ||
v r3td dt|
| | d g }|tjv r@|d! |tj v rK|d" |tj!v rV|d# |tj"v ra|d$ |tj#v rl|d% td&d|| d td| d qdS dS )'aG  
    Prints information about this installation of Pillow.
    This function can be called with ``python3 -m PIL``.

    :param out:
        The output stream to print to. Defaults to ``sys.stdout`` if ``None``.
    :param supported_formats:
        If ``True``, a list of all supported image file formats will be printed.
    NzD--------------------------------------------------------------------)filezPillow zPython r   r   z       zPython modules loaded from zBinary modules loaded from ))r   zPIL CORE)r   TKINTER)r   	FREETYPE2)r   
LITTLECMS2)r   WEBP)rO   zWEBP Transparency)rN   WEBPMUX)rM   zWEBP Animation)r0   JPEG)r1   zOPENJPEG (JPEG2000))r.   zZLIB (PNG/ZIP))r/   LIBTIFF)rP   zRAQM (Bidirectional Text))rT   z#LIBIMAGEQUANT (Quantization method))rU   zXCB (X protocol)r0   rS   zlibjpeg-turbo )r   r0   r   c                 s   s    | ]}t |V  qd S )N)int)r#   xr   r   r   	<genexpr>  s    zpilinfo.<locals>.<genexpr>.)r]      zcompiled forloadedrP   )rQ   rR   z,  z---zsupport ok,z
support okz***zsupport not installedzExtensions: {}opensavesave_alldecodeencodezFeatures: {})$sysstdoutr   initprintrV   __version__r<   
splitlinesstripospathdirname__file__r5   rb   rZ   r[   tupler;   collectionsdefaultdictlist	EXTENSIONitemsappendsortedIDMIMEformatjoinOPENSAVESAVE_ALLDECODERSENCODERS)outsupported_formats
py_versionnamer   vversion_statictr$   v2
extensionsextilinerW   r   r   r   pilinfo   s   







r   )NT)r   r   rz   r_   rV    r   r   r   r   r'   r3   r8   r=   r>   rW   rZ   r[   r\   rb   r<   re   r   r   r   r   r   <module>   sP    	