
    1-Ph0                        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             Zd Z e            5   e             ddd           n# 1 swxY w Y   d Zd Z e
ddd          d             Zd Zd Z e            5   e             ddd           n# 1 swxY w Y    e
ddd          d!d            Z e            5   e            Zddd           n# 1 swxY w Y    e
ddd          d             Z e
ddd          d"d            Zd Z e            d             Z e
ddd          d             Z  e
ddd          d              Z!dS )#aK  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               #      K   t          j                    5  t          j        ddt          d           dV  ddd           dS # 1 swxY 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     Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/io/manage_plugins.py!_hide_plugin_deprecation_warningsr%   9   s       
	 	"	"  F"		
 	
 	
 	
 	                 s   "AA	A	c                      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$   _clear_pluginsr-   F   s&      LLLr#   c                      g d} | D ]}t          |t          d                    d t                                          D             }|D ]}t          |t          |                    d S )N)r(   r   r)   r   r'   r   c              3   &   K   | ]}|d k    |V  dS )r   Nr"   .0ps     r$   	<genexpr>z*_load_preferred_plugins.<locals>.<genexpr>]   s&      FF!1::A::::FFr#   )_set_pluginpreferred_pluginskeys)io_typesp_typeplugin_typess      r$   _load_preferred_pluginsr:   W   s    WWWH 6 6F-e45555FF05577FFFL 7 7F-f566667 7r#   c                     |D ]=}|t           vr	 t          ||             d S # t          t          t          f$ r Y :w xY wd S )N)kind)r   r
   ImportErrorRuntimeErrorOSError)plugin_typeplugin_listplugins      r$   r4   r4   b   sp      +++	vK0000EE\73 	 	 	D	 s   $>>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                      t                      5  t                       t                       d d d            d S # 1 swxY w Y   d S N)r%   r-   r:   r"   r#   r$   r   r   m   s     
+	,	, " "!!!" " " " " " " " " " " " " " " " " "s   9= =c                     t                      }|                    |            |                                d         }i }|                    |          D ]}|                    ||          ||<   ||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opts        r$   _parse_config_filerR   y   st    ^^F
KK??QDI~~d## / /D#..	#?r#   c            	         t           j                            t                    } t	          t           j                            | dd                    }|D ]}t          |          \  }}d|vrt          j        d| d           1|t          |<   d |d         
                    d          D             }d |D             }|D ]!}|t          vrt          d	| d
| d           "d|vod|v }|r|                    d           |t          |<   t           j                            |          dd         t           |<   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                 6    g | ]}|                                 S r"   )strip)r1   ss     r$   
<listcomp>z!_scan_plugins.<locals>.<listcomp>   s     HHH!AGGIIHHHr#   ,c                 $    g | ]}|t           v |S r"   r+   r0   s     r$   rY   z!_scan_plugins.<locals>.<listcomp>   s"    CCCl1B1B!1B1B1Br#   zPlugin `z!` wants to provide non-existent `z`. Ignoring.r)   r'   N)ospathdirname__file__r   joinrR   r   warnplugin_meta_datasplitr,   printappendplugin_providesbasenameplugin_module_name)	pdconfig_filesrM   rO   rP   rU   valid_providesr2   need_to_add_collections	            r$   _scan_pluginsrn      s    
	"	"BRW==>>L  C C,X66iY&&MXXXX   !*HHy'<'B'B3'G'GHHHCCXCCC 	Y 	YA$$WWWWWWXXX  ~5T(n:T 	 " 	7!!"5666 .#%7#3#3H#=#=crc#B4  1C Cr#   Fc                     t                      }t                                          D ]}|D ]\  }}|                    |            i }t          D ]"}| r||v rd t          |         D             ||<   #|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                 <    g | ]}|                     d           |S )_)
startswith)r1   fs     r$   rY   z*find_available_plugins.<locals>.<listcomp>   s*    UUUq1<<PSCTCTUUUUr#   )setr,   valuesaddrg   )loadedactive_pluginsplugin_funcrB   funcds         r$   r   r      s    , UUN#**,, ' '' 	' 	'LFDv&&&&	' 	A! V V 	V>11UUOF$;UUUAfIHr#   c                    | t           vrt          d|  d          t           |          }t          |          dk    rd|  d}t          |          |                    dd          |d         \  }}nIt                     	 fd|D             d         }n$# t          $ r t          d	 d
|  d          w xY 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.rB   Nc                 &    g | ]\  }}|k    |S r"   r"   )r1   r2   rs   rB   s      r$   rY   zcall_plugin.<locals>.<listcomp>   s"    @@@&1aAKKAKKKr#   zCould not find the plugin "z" for .)r,   
ValueErrorlenr>   pop_load
IndexError)r<   argskwargsplugin_funcsmsgrq   rz   rB   s          @r$   r   r      s"   ( <@d@@@AAA%L
<A& & & & 	 3ZZ$''F~q/44f	T@@@@L@@@CDD 	T 	T 	TRVRR4RRRSSS	T 4    s   B !B=c                 n    |t                                           }n3|t                    vrt          d  d| d          |dk    r|dg}n|g}t	                      |D ]R}|t           vrt          d| d          t           |         } fd	|D              fd
|D             z   }|t           |<   Sd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                 *    g | ]\  }}|k    ||fS r"   r"   r1   nrs   rO   s      r$   rY   zuse_plugin.<locals>.<listcomp>5  s&    999FQqDyy!Qyyyr#   c                 *    g | ]\  }}|k    ||fS r"   r"   r   s      r$   rY   zuse_plugin.<locals>.<listcomp>5  s-     =
 =
 =
1!t))QF)))r#   )r,   r6   rg   r>   r   )rO   r<   kfuncss   `   r$   r
   r
     s   > |  ""t,,,JJJ$JJJKKK8+&DD6D	$KKK    L  G1GGGHHHQ :999e999 =
 =
 =
 =
!&=
 =
 =
 
  Q   r#   c                     t          | d          sBt          | d          r4t          | 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'   rz   s      r$   #_inject_imread_collection_if_neededr   <  so    6.// 3GFH4M4M 3**(00+T222223 3 3 3r#   c                    | t          d          v rdS | t          vrt          d|  d          t          |          }t          d|z   |g          }t          |          }|D ]y}|dk    rt          |           n't          ||          st          d|  d	| d
           ?t          |         }t          ||          }| |f|vr|
                    | |f           zdS )zLoad the given plugin.

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

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

    T)rw   Nr   z not found.zskimage.io._plugins.)fromlistr)   z does not provide z as advertised.  Ignoring.)r   ri   r   
__import__rg   r   r   re   r,   r   rf   )rB   modnameplugin_modulerU   r2   storerz   s          r$   r   r   D  s    't44444'''66666777$V,"#9G#CwiXXXv&H 
) 
)###/>>>>** 	SFSSaSSSTTTQ}a((D>&&LL&$(((
) 
)r#   c                 `    	 t           |          S # t          $ r t          d|  d          w xY 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 "")rc   KeyErrorr   )rB   s    r$   r   r   h  sL    (A'' A A A?f???@@@As    -c                  R    i } t           D ]}d t           |         D             | |<   | 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                     g | ]\  }}|S r"   r"   )r1   plugin_namers   s      r$   rY   z plugin_order.<locals>.<listcomp>  s    JJJ#3K;JJJr#   r+   )r2   rz   s     r$   r   r     s=      	A K KJJ|D7IJJJ$Hr#   )FrG   )"__doc__os.pathr]   r   configparserr   r   
contextlibr   _shared.utilsr   
collectionr	   __all__r,   rg   ri   rc   r5   r%   r-   r:   r4   r   rR   rn   r   r   r   r
   r   r   r   r   r"   r#   r$   <module>r      s6   $   % % % % % %       % % % % % % * * * * * * 1 1 1 1 1 1     
 ,++n&	   	 	 	
 
 
 '&((  N              7 7 7   
=  " " "
 
 
C C CD '&((  MOOO               
=     : '&(( 2 2//112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
=  %! %! %!P 
=  2  2  2  2 j3 3 3 #"$$ )  ) %$ )F 
=  A A A( 
=      s6   A..A25A2&B==CC*DDD