
    0-Ph&                     `    d dl mZ d dlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddddd	d
ZdS )    )PathN   )known_plugins)known_extensions   )SPECIAL_READ_URISURI_FILENAMEInitializationErrorIOModeRequestF)plugin	extensionformat_hintlegacy_modec                	   t          | t                    r;|r9t          j        dt          d           | }|j        } |j        j        }||_        nt          | |||          }t          | t                    rdn| }t          t                    rK	 t                   n6# t          $ r) |                                 t          d d          dw xY wfd	}	nfd
}		  |	|fi |S # t          $ r"}
|
}|rt           nt"          }d d}Y d}
~
nPd}
~
wt$          $ r d}t$          }dj         dj         d}Y n%t*          $ r}|}t"          }d d}Y d}~nd}~ww xY w|                                  ||          ||j        t,          |         D ]R}|j        D ]H}t          |         	 j        }n# t$          $ r Y $w xY w	  ||fi |}n# t          $ r Y ?w xY w|c c S St          |j        t                    rdn|j        }t          j        d| d| d           |j        t,          v ret,          |j                 D ]R}|j        D ]H}t          |         	 j        }n# t$          $ r Y $w xY w	  ||fi |}n# t          $ r Y ?w xY w|c c S S|j        j        t4          j        k    rdt          | t                    rO|                     t:                    r5|                                 |rt          nt"          }d| d} ||          |j        t>          k    rWtA          |j                  !                                r1|                                 |rt          nt"          }d} ||          |                                 t          j"                    D ]At          | ||          }	  j        |fi |}|c S # t          $ r Y 3t$          $ r Y >w xY w|rt          nt"          }d| d| d}|j        t,          v rtG                      }t,          |j                 }d |D             }|D ]<}t          |         	 j         # t$          $ r |$                               Y 9w xY wtK          |          dk    r'd&                    d |D                       }|d| z  }|                                  ||          )a
  Open an ImageResource.

    .. warning::
        This warning is for pypy users. If you are not using a context manager,
        remember to deconstruct the returned plugin to avoid leaking the file
        handle to an unclosed file.

    Parameters
    ----------
    uri : str or pathlib.Path or bytes or file or Request
        The :doc:`ImageResource <../../user_guide/requests>` to load the
        image from.
    io_mode : str
        The mode in which the file is opened. Possible values are::

            ``r`` - open the file for reading
            ``w`` - open the file for writing

        Depreciated since v2.9:
        A second character can be added to give the reader a hint on what
        the user expects. This will be ignored by new plugins and will
        only have an effect on legacy plugins. Possible values are::

            ``i`` for a single image,
            ``I`` for multiple images,
            ``v`` for a single volume,
            ``V`` for multiple volumes,
            ``?`` for don't care

    plugin : str, Plugin, or None
        The plugin to use. If set to None imopen will perform a
        search for a matching plugin. If not None, this takes priority over
        the provided format hint.
    extension : str
        If not None, treat the provided ImageResource as if it had the given
        extension. This affects the order in which backends are considered, and
        when writing this may also influence the format used when encoding.
    format_hint : str
        Deprecated. Use `extension` instead.
    legacy_mode : bool
        If true use the v2 behavior when searching for a suitable
        plugin. This will ignore v3 plugins and will check ``plugin``
        against known extensions if no plugin with the given name can be found.
    **kwargs : Any
        Additional keyword arguments will be passed to the plugin upon
        construction.

    Notes
    -----
    Registered plugins are controlled via the ``known_plugins`` dict in
    ``imageio.config``.

    Passing a ``Request`` as the uri is only supported if ``legacy_mode``
    is ``True``. In this case ``io_mode`` is ignored.

    Using the kwarg ``format_hint`` does not enforce the given format. It merely
    provides a `hint` to the selection process and plugin. The selection
    processes uses this hint for optimization; however, a plugin's decision how
    to read a ImageResource will - typically - still be based on the content of
    the resource.


    Examples
    --------

    >>> import imageio.v3 as iio
    >>> with iio.imopen("/path/to/image.png", "r") as file:
    >>>     im = file.read()

    >>> with iio.imopen("/path/to/output.jpg", "w") as file:
    >>>     file.write(im)

    z`iio.core.Request` is a low-level object and using it directly as input to `imopen` is discouraged. This will raise an exception in ImageIO v3.r   )
stacklevel)r   r   z<bytes>N`z"` is not a registered plugin name.c                       j         | fi |S N)plugin_class)requestkwargsconfigs     S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/imageio/core/imopen.pyloaderzimopen.<locals>.loader   s    *v*7==f===    c                      | fi |S r    )r   r   r   s     r   r   zimopen.<locals>.loader   s    vg00000r   z` can not handle the given uri.zThe `z4` plugin is not installed. Use `pip install imageio[z]` to install it.z5An unknown error occurred while initializing plugin `z`.z` can not be opened as a `z` file.z` is read-only.zImageIO does not generally support reading folders. Limited support may be available via specific plugins. Specify the plugin explicitly using the `plugin` kwarg, e.g. `plugin='DICOM'`)r   z"Could not find a backend to open `z`` with iomode `c                 &    g | ]}|j         D ]}|S r   )priority).0file_formatr   s      r   
<listcomp>zimopen.<locals>.<listcomp>   s<     
 
 
"K<P
 
28F
 
 
 
r   r   
c                 4    g | ]}d |j          d|j         dS )z  z:  pip install imageio[])nameinstall_name)r!   r   s     r   r#   zimopen.<locals>.<listcomp>  sS       
 FV[ F F/5/BF F F  r   zK
Based on the extension, the following plugins might add capable backends:
)'
isinstancer   warningswarnDeprecationWarningraw_urimodeio_moder   bytesstrr   KeyErrorfinish
ValueErrorr
   RuntimeErrorIOErrorImportErrorr'   r(   	Exceptionr   r    r   r   r   write
startswithr   	_uri_typer	   r   is_dirvalueslistappendlenjoin)urir/   r   r   r   r   r   r   sourcer   class_specificerr_fromerr_typeerr_msggeneric_errorcandidate_formatplugin_namecandidate_pluginplugin_instanceresourcemissing_pluginsformatsplugin_namesr'   install_candidatesr   s     `                      @r   imopenrR      s"   h #w VK V+ 	
 	
 	
 	
 o,&)#wK9UUU$S%009YYcF fc"" 	1&v.       BBBB > > > > > >
1 1 1 1 1	Y6',,V,,," 	B 	B 	B%H'2?||HA&AAAGGGGGG 	 	 	H"HS S S,2,?S S S GG  	Y 	Y 	Y$HHXfXXXGGGGGG	Y
 	hwX- & 0 = 	X 	X/8 ' '&{3'-':$$"   H&6&6w&I&I&&I&IOO*   H '&&&&&'$ (??T		W_  MVhVV+VVVWWW ,,, 01B C 	' 	'/8 ' '&{3'-':$$"   H&6&6w&I&I&&I&IOO*   H '&&&&&'& |v|++c3 	$CNN3D$E$E 	$NN%0=zzgH1&111G(7###
 L((T'/-B-B-I-I-K-K(!,9::'\ 	
 hw NN  &(( # ##wK@@@	#1f1'DDVDDO #""" # 	 	 	H 	 	 	H	
 )5zzgHV6VV7VVVG ,,,&&"7#45
 
&-
 
 
 ! 	/ 	/D"4(F/## / / /&&v...../ !##!% 
 #2  " " (%( (G
 NN
(7

s   B& &3C(C1 1
E%;D)E%	E%E  E%5F==
G
	G
	G
G%$G%&I..
I;:I;?	J		
JJO
O+	O+*O+QQ=<Q=)pathlibr   r*   r   r   config.extensionsr   r   r   r	   r
   r   r   rR   r   r   r   <module>rU      s           " " " " " " 0 0 0 0 0 0              J J J J J J Jr   