
    |h0                     p   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       d Zd Z e
ddd      d        Zd Zd Z e       5   e        ddd        e
ddd      d d       Z e       5   e       Zddd        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!y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   wxY w)"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 ddd       y# 1 sw Y   yxY ww)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     X/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/io/manage_plugins.py!_hide_plugin_deprecation_warningsr%   9   sG      
	 	 	" F"		
 	  s   A"A	AAAc                      g g g g g g da y)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     Lr#   c                      g d} | D ]  }t        |t        d           d t        j                         D        }|D ]  }t        |t        |           y )N)r(   r   r)   r   r'   r   c              3   ,   K   | ]  }|d k7  s	|  yw)r   Nr"   ).0ps     r$   	<genexpr>z*_load_preferred_plugins.<locals>.<genexpr>]   s     F!1:AFs   
)_set_pluginpreferred_pluginskeys)io_typesp_typeplugin_typess      r$   _load_preferred_pluginsr9   W   s\    WH 6F-e456 G0557FL 7F-f567r#   c                 v    |D ]  }|t         vr	 t        ||         y  y # t        t        t        f$ r Y 4w xY w)N)kind)r   r
   ImportErrorRuntimeErrorOSError)plugin_typeplugin_listplugins      r$   r3   r3   b   sJ     ++	vK0 \73 		s   !88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                  j    t               5  t                t                d d d        y # 1 sw Y   y xY wN)r%   r-   r9   r"   r#   r$   r   r   m   s+     
+	, "!" " "s   )2c                     t               }|j                  |        |j                         d   }i }|j                  |      D ]  }|j	                  ||      ||<    ||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_filerQ   y   sc    ^F
KK??QDI~~d# /D#.	#/ ?r#   c            	         t         j                  j                  t              } t	        t         j                  j                  | dd            }|D ]  }t        |      \  }}d|vrt        j                  d| d       /|t        |<   |d   j                  d      D cg c]  }|j                          }}|D cg c]  }|t        v s| }}|D ]  }|t        vst        d| d| d	        d
|vxr d|v }	|	r|j                  d
       |t        |<   t         j                  j!                  |      dd t"        |<    yc c}w c c}w )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.,zPlugin `z!` wants to provide non-existent `z`. Ignoring.r)   r'   N)ospathdirname__file__r   joinrQ   r   warnplugin_meta_datasplitstripr,   printappendplugin_providesbasenameplugin_module_name)
pdconfig_filesrL   rN   rO   srT   r1   valid_providesneed_to_add_collections
             r$   _scan_pluginsrj      sV    
	"BRW=>L  C,X6iY&MMz!WX !*'0'<'B'B3'GH!AGGIHH%-Cl1B!CC 	YA$&Gs,WX	Y  ~5T(n:T 	 "!!"56 .#%77#3#3H#=cr#B4 1C ICs   E;E	Ec                    t               }t        j                         D ]  }|D ]  \  }}|j                  |         i }t        D ]5  }| r||v s
t        |   D cg c]  }|j                  d      r| c}||<   7 |S c c}w )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.

    _)setr,   valuesaddrb   
startswith)loadedactive_pluginsplugin_funcrA   funcdfs          r$   r   r      s    , UN#**, '' 	'LFDv&	'' 	A! V>1$3F$;Uq1<<PSCTUAfIV H Vs   B3Bc                 h   | t         vrt        d|  d      t         |    }t        |      dk(  rd|  d}t        |      |j	                  dd      }|	|d   \  }}n*t        |       	 |D 	cg c]  \  }}	||k(  s|	 c}	}d   } ||i |S c c}	}w # t        $ r t        d| d	|  d
      w xY w)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.rA   NzCould not find the plugin "z" for .)r,   
ValueErrorlenr=   pop_load
IndexError)
r;   argskwargsplugin_funcsmsgrA   rl   rt   r1   rv   s
             r$   r   r      s    ( <-dV<@AA%L
<A0 7& & 	 3ZZ$'F~q/4f	T$0@&1aAKA@CD    	 A 	T!<VHF4&PQRSS	Ts$   )B .B<B B B B1c                    |t         j                         }n*|t        |    vrt        d|  d| d      |dk(  r|dg}n|g}t	        |        |D ]f  }|t         vrt        d| d      t         |   }|D cg c]  \  }}|| k(  s||f c}}|D cg c]  \  }}|| k7  s||f c}}z   }|t         |<   h yc c}}w c c}}w )	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.)r,   r5   rb   r=   r|   )rN   r;   kfuncsnrv   s         r$   r
   r
     s    > |  "t,,.A$rJKK8+&D6D	$K  L 1#%FGHHQ ',9FQqDy!Q9!&=
1!t)QF=
 
  Q  : =
s   7B9B9B?
!B?
c                     t        | d      s2t        | d      r%t        | d      }t        |      }t        | d|       yyy)z9Add `imread_collection` to module if not already present.r)   r'   N)hasattrgetattrr	   setattr)r   r'   rt   s      r$   #_inject_imread_collection_if_neededr   <  sB    6./GFH4M*(0+T2 5N/r#   c                 b   | t        d      v ry| t        vrt        d|  d      t        |    }t        d|z   |g      }t        |    }|D ]a  }|dk(  rt        |       nt        ||      st        d|  d	| d
       3t        |   }t        ||      }| |f|vsO|j                  | |f       c y)zLoad the given plugin.

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

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

    T)rq   Nr   z not found.zskimage.io._plugins.)fromlistr)   z does not provide z as advertised.  Ignoring.)r   rd   ry   
__import__rb   r   r   r`   r,   r   ra   )rA   modnameplugin_modulerT   r1   storert   s          r$   r|   r|   D  s     't44''76(+677$V,"#9G#CwiXv&H 
)##/>*GF8#5aS8RSTQ}a(D>&LL&$(
)r#   c                 N    	 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 "")r]   KeyErrorry   )rA   s    r$   r   r   h  s9    (A'' A5fXQ?@@As    $c                  j    i } t         D ]!  }t         |   D cg c]  \  }}|	 c}}| |<   # | S c c}}w )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.

    r+   )r1   rt   plugin_namerv   s       r$   r   r     sC      	A K7CD7IJ#3K;J$KH Ks   /)FrF   )"__doc__os.pathrW   r   configparserr   r   
contextlibr   _shared.utilsr   
collectionr	   __all__r,   rb   rd   r]   r4   r%   r-   r9   r3   r   rQ   rj   r   r   r   r
   r   r|   r   r   r"   r#   r$   <module>r      s  $   %  % * 1   
 ,n&	  	 	
 '( 7 
=""
CD '( O 
=: '( 2/12 
=%!%!P 
=2 2 j3 #$ ) % )F 
=AA( 
=k	 j N2 2s$   DD .D,D D),D5