o
    ^i0                     @   s  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZ g d
Zdai Zi Zi Zg ddgdgdZedd Zdd Ze  e  W d   n1 sYw   Y  dd Zdd Ze
dddddd Zdd Zdd Ze  e  W d   n1 sw   Y  e
ddddd/d!d"Ze  e ZW d   n1 sw   Y  e
ddddd#d$ Ze
ddddd0d%d&Zd'd( Ze d)d* Ze
ddddd+d, Z e
ddddd-d. Z!dS )1aK  Handle image reading, writing and plotting plugins.

To improve performance, plugins are only loaded as needed. As a result, there
can be multiple states for a given plugin:

    available: Defined in an *ini file located in ``skimage.io._plugins``.
        See also :func:`skimage.io.available_plugins`.
    partial definition: Specified in an *ini file, but not defined in the
        corresponding plugin module. This will raise an error when loaded.
    available but not on this system: Defined in ``skimage.io._plugins``, but
        a dependent library (e.g. Qt, PIL) is not available on your system.
        This will raise an error when loaded.
    loaded: The real availability is determined when it's explicitly loaded,
        either because it's one of the default plugins, or because it's
        loaded explicitly by the user.

    N)ConfigParser)glob)contextmanager   )deprecate_func   )imread_collection_wrapper)
use_plugincall_pluginplugin_infoplugin_orderreset_pluginsfind_available_plugins_available_plugins)imageiopil
matplotlibr   )allimshowimshow_collectionc                   c   sH    t   t jddtdd dV  W d   dS 1 sw   Y  dS )z=Ignore warnings related to plugin infrastructure deprecation.ignorez0.*use `imageio` or other I/O packages directly.*skimage)actionmessagecategorymoduleN)warningscatch_warningsfilterwarningsFutureWarning r    r    T/var/www/html/RAG/RAG_venv/lib/python3.10/site-packages/skimage/io/manage_plugins.py!_hide_plugin_deprecation_warnings9   s   
"r"   c                   C   s   g g g g g g da dS )zHClear the plugin state to the default, i.e., where no plugins are loaded)imreadimsaver   imread_collectionr   	_app_showNplugin_storer    r    r    r!   _clear_pluginsF   s   
r)   c                  C   sN   g d} | D ]	}t |td  qdd t D }|D ]	}t |t|  qd S )N)r$   r   r%   r   r#   r   c                 s   s    | ]	}|d kr|V  qdS )r   Nr    .0pr    r    r!   	<genexpr>]   s    z*_load_preferred_plugins.<locals>.<genexpr>)_set_pluginpreferred_pluginskeys)io_typesp_typeplugin_typesr    r    r!   _load_preferred_pluginsW   s   r4   c                 C   sD   |D ]}|t vr	qz
t|| d W  d S  tttfy   Y qw d S )N)kind)r   r	   ImportErrorRuntimeErrorOSError)plugin_typeplugin_listpluginr    r    r!   r.   b   s   r.   z0.25z0.27zoThe plugin infrastructure of `skimage.io` is deprecated. Instead, use `imageio` or other I/O packages directly.)deprecated_versionremoved_versionhintc                   C   s8   t   t  t  W d    d S 1 sw   Y  d S N)r"   r)   r4   r    r    r    r!   r   m   s   "r   c                 C   sH   t  }||  | d }i }||D ]
}|||||< q||fS )z>Return plugin name and meta-data dict from plugin config file.r   )r   readsectionsoptionsget)filenameparsername	meta_dataoptr    r    r!   _parse_config_filey   s   
rI   c            	      C   s   t jt} tt j| dd}|D ]`}t|\}}d|vr(td| d q|t	|< dd |d 
dD }d	d |D }|D ]}|tvrRtd
| d| d qAd|voZd|v }|rb|d |t|< t j|dd t|< qdS )z]Scan the plugins directory for .ini files and parse them
    to gather plugin meta-data.
    _pluginsz*.iniprovideszfile z6 not recognized as a scikit-image io plugin, skipping.c                 S   s   g | ]}|  qS r    )strip)r+   sr    r    r!   
<listcomp>       z!_scan_plugins.<locals>.<listcomp>,c                 S   s   g | ]}|t v r|qS r    r'   r*   r    r    r!   rN      s    zPlugin `z!` wants to provide non-existent `z`. Ignoring.r%   r#   N)ospathdirname__file__r   joinrI   r   warnplugin_meta_datasplitr(   printappendplugin_providesbasenameplugin_module_name)	pdconfig_filesrD   rF   rG   rK   valid_providesr,   need_to_add_collectionr    r    r!   _scan_plugins   s.   

rc   Fc                 C   s`   t  }t D ]}|D ]	\}}|| qqi }tD ]}| r"||v r-dd t| D ||< q|S )a1  List available plugins.

    Parameters
    ----------
    loaded : bool
        If True, show only those plugins currently loaded.  By default,
        all plugins are shown.

    Returns
    -------
    p : dict
        Dictionary with plugin names as keys and exposed functions as
        values.

    c                 S   s   g | ]	}| d s|qS )_)
startswith)r+   fr    r    r!   rN      s    z*find_available_plugins.<locals>.<listcomp>)setr(   valuesaddr\   )loadedactive_pluginsplugin_funcr;   funcdr    r    r!   r      s   r   c              	      s   | t vrtd|  dt |  }t|dkr d|  d}t||dd  du r1|d \}}n$t  z fdd	|D d }W n tyT   td
  d|  dw ||i |S )a  Find the appropriate plugin of 'kind' and execute it.

    Parameters
    ----------
    kind : {'imshow', 'imsave', 'imread', 'imread_collection'}
        Function to look up.
    plugin : str, optional
        Plugin to load.  Defaults to None, in which case the first
        matching plugin is used.
    *args, **kwargs : arguments and keyword arguments
        Passed to the plugin function.

    zInvalid function (z) requested.r   z"No suitable plugin registered for z.

You may load I/O plugins with the `skimage.io.use_plugin` command.  A list of all available plugins are shown in the `skimage.io` docstring.r;   Nc                    s   g | ]
\}}| kr|qS r    r    )r+   r,   rf   r;   r    r!   rN      s    zcall_plugin.<locals>.<listcomp>zCould not find the plugin "z" for .)r(   
ValueErrorlenr7   pop_load
IndexError)r5   argskwargsplugin_funcsmsgrd   rm   r    ro   r!   r
      s"   
r
   c                    s   |du r	t  }n|t  vrtd  d| d|dkr#|dg}n|g}t  |D ](}|t vr:td| dt | } fd	d
|D  fdd
|D  }|t |< q,dS )a\  Set the default plugin for a specified operation.  The plugin
    will be loaded if it hasn't been already.

    Parameters
    ----------
    name : str
        Name of plugin. See ``skimage.io.available_plugins`` for a list of available
        plugins.
    kind : {'imsave', 'imread', 'imshow', 'imread_collection', 'imshow_collection'}, optional
        Set the plugin for this function.  By default,
        the plugin is set for all functions.

    Examples
    --------
    To use Matplotlib as the default image reader, you would write:

    >>> from skimage import io
    >>> io.use_plugin('matplotlib', 'imread')

    To see a list of available plugins run ``skimage.io.available_plugins``. Note
    that this lists plugins that are defined, but the full list may not be usable
    if your system does not have the required libraries installed.

    NPlugin z does not support `z`.r   r&   'z!' is not a known plugin function.c                    s    g | ]\}}| kr||fqS r    r    r+   nrf   rF   r    r!   rN   5  s     zuse_plugin.<locals>.<listcomp>c                    s    g | ]\}}| kr||fqS r    r    r|   r~   r    r!   rN   5  s    )r(   r0   r\   r7   rt   )rF   r5   kfuncsr    r~   r!   r	     s"   


r	   c                 C   s>   t | dst | drt| d}t|}t| d| dS dS dS )z9Add `imread_collection` to module if not already present.r%   r#   N)hasattrgetattrr   setattr)r   r#   rm   r    r    r!   #_inject_imread_collection_if_needed<  s
   
r   c                 C   s   | t ddv r	dS | tvrtd|  dt|  }td| |gd}t|  }|D ]2}|dkr3t| nt||sDtd|  d	| d
 q(t| }t	||}| |f|vrZ|
| |f q(dS )zLoad the given plugin.

    Parameters
    ----------
    plugin : str
        Name of plugin to load.

    See Also
    --------
    plugins : List of available plugins

    T)rj   Nrz   z not found.zskimage.io._plugins.)fromlistr%   z does not provide z as advertised.  Ignoring.)r   r^   rq   
__import__r\   r   r   rZ   r(   r   r[   )r;   modnameplugin_modulerK   r,   storerm   r    r    r!   rt   D  s&   


rt   c                 C   s*   zt |  W S  ty   td|  dw )zReturn plugin meta-data.

    Parameters
    ----------
    plugin : str
        Name of plugin.

    Returns
    -------
    m : dict
        Meta data as specified in plugin ``.ini``.

    zNo information on plugin "")rX   KeyErrorrq   ro   r    r    r!   r   h  s
   
r   c                  C   s(   i } t D ]}dd t | D | |< q| S )zReturn the currently preferred plugin order.

    Returns
    -------
    p : dict
        Dictionary of preferred plugin order, with function name as key and
        plugins (in order of preference) as value.

    c                 S   s   g | ]\}}|qS r    r    )r+   plugin_namerf   r    r    r!   rN     rO   z plugin_order.<locals>.<listcomp>r'   )r,   rm   r    r    r!   r     s   r   )Fr?   )"__doc__os.pathrR   r   configparserr   r   
contextlibr   _shared.utilsr   
collectionr   __all__r(   r\   r^   rX   r/   r"   r)   r4   r.   r   rI   rc   r   r   r
   r	   r   rt   r   r   r    r    r    r!   <module>   s    

"
(5
#
