
    %Vf!                     
   d dl Z 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lm	Z	 ddl
mZmZ d Z G d dej                        Z G d	 d
ej                        Z G d dej"                        Z G d dej                        Zy)    N   )abc)only)ZipPathensure_traversablec                 R    t        t        j                  j                  |             S N)itercollectionsOrderedDictfromkeys)itemss    d/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/importlib_resources/readers.pyremove_duplicatesr      s    ''00788    c                       e Zd Zd Zd Zd Zy)
FileReaderc                 `    t        j                  |j                        j                  | _        y r	   )pathlibPathpathparent)selfloaders     r   __init__zFileReader.__init__   s    LL-44	r   c                 J    t        | j                  j                  |            S z{
        Return the file system path to prevent
        `resources.path()` from creating a temporary
        copy.
        strr   joinpathr   resources     r   resource_pathzFileReader.resource_path        499%%h/00r   c                     | j                   S r	   r   r   s    r   fileszFileReader.files       yyr   N)__name__
__module____qualname__r   r#   r(    r   r   r   r      s    51r   r   c                   0     e Zd Zd Z fdZd Zd Z xZS )	ZipReaderc                     |j                  d      \  }}}|j                  j                  dd      |z   dz   | _        |j                  | _        y )N.\/)
rpartitionprefixreplacearchive)r   r   module_names        r   r   zZipReader.__init__#   sE    &&s+
1dmm++D#6=C~~r   c                 v    	 t         |   |      S # t        $ r}t        |j                  d         d }~ww xY wNr   )superopen_resourceKeyErrorFileNotFoundErrorargs)r   r"   exc	__class__s      r   r>   zZipReader.open_resource(   s;    	17(22 	1#CHHQK00	1s    	838c                     | j                         j                  |      }|j                         xr |j                         S )zf
        Workaround for `zipfile.Path.is_file` returning true
        for non-existent paths.
        )r(   r    is_fileexists)r   r   targets      r   is_resourcezZipReader.is_resource.   s2    
 &&t,~~3FMMO3r   c                 B    t        | j                  | j                        S r	   )r   r7   r5   r'   s    r   r(   zZipReader.files6   s    t||T[[11r   )r*   r+   r,   r   r>   rH   r(   __classcell__rC   s   @r   r/   r/   "   s    &
142r   r/   c                   r     e Zd ZdZd Zd Zd Zd Zd Zd Z	 fdZ
ed	        Zd
 Zed        Zd Z xZS )MultiplexedPathz
    Given a series of Traversable objects, implement a merged
    version of the interface across all objects. Useful for
    namespace packages which may be multihomed at a single
    name.
    c                     t        t        t        t        |                  | _        | j                  sd}t        |      t        d | j                  D              st        d      y )Nz.MultiplexedPath must contain at least one pathc              3   <   K   | ]  }|j                           y wr	   is_dir.0r   s     r   	<genexpr>z+MultiplexedPath.__init__.<locals>.<genexpr>G   s     9T4;;=9s   z)MultiplexedPath only supports directories)listmapr   r   _pathsr@   allNotADirectoryError)r   pathsmessages      r   r   zMultiplexedPath.__init__B   sV    313DU3KLM{{FG#G,,9T[[99$%PQQ :r   c                     d | j                   D        }t        j                  d      }t        j                  t        ||      |      }t        | j                  d |D              S )Nc              3   J   K   | ]  }|j                         D ]  }|   y wr	   )iterdir)rS   r   childs      r   rT   z*MultiplexedPath.iterdir.<locals>.<genexpr>K   s"     Ndt||~NeENENs   !#r:   )keyc              3   &   K   | ]	  \  }}|  y wr	   r-   )rS   r:   locss      r   rT   z*MultiplexedPath.iterdir.<locals>.<genexpr>N   s     !@:4$!@s   )rW   operator
attrgetter	itertoolsgroupbysortedrV   _follow)r   childrenby_namegroupss       r   r^   zMultiplexedPath.iterdirJ   sP    NdkkN%%f-""6(#@gN4<<!@!@AAr   c                     t        |  d      Nz is not a filer@   r'   s    r   
read_byteszMultiplexedPath.read_bytesP       4& 788r   c                     t        |  d      rm   rn   r   rA   kwargss      r   	read_textzMultiplexedPath.read_textS   rp   r   c                      y)NTr-   r'   s    r   rQ   zMultiplexedPath.is_dirV   s    r   c                      y)NFr-   r'   s    r   rE   zMultiplexedPath.is_fileY   s    r   c                     	 t        |   | S # t        j                  $ r  | j                  d   j                  | cY S w xY wr<   )r=   r    r   TraversalErrorrW   )r   descendantsrC   s     r   r    zMultiplexedPath.joinpath\   sJ    	97#[11!! 	9 +4;;q>**K88	9s    /A Ac                     t        j                  |d      \  }}}	 t        |      S # t        $ r% 	  | | cY S # t        $ r t        |      cY cY S w xY ww xY w)z
        Construct a MultiplexedPath if needed.

        If children contains a sole element, return it.
        Otherwise, return a MultiplexedPath of the items.
        Unless one of the items is not a Directory, then return the first.
           )re   teer   
ValueErrorrY   next)clsri   subdirsone_dirone_files        r   rh   zMultiplexedPath._followd   sa     &/]]8Q%?"(	&=  	&&G}$% &H~%&	&s)   
' 	A8AAAAAc                     t        |  d      rm   rn   rr   s      r   openzMultiplexedPath.openw   rp   r   c                 4    | j                   d   j                  S r<   )rW   r:   r'   s    r   r:   zMultiplexedPath.namez   s    {{1~"""r   c                 R    dj                  d | j                  D              }d| dS )Nz, c              3   (   K   | ]
  }d | d   yw)'Nr-   rR   s     r   rT   z+MultiplexedPath.__repr__.<locals>.<genexpr>   s     >$AdV1+>s   zMultiplexedPath())joinrW   )r   rZ   s     r   __repr__zMultiplexedPath.__repr__~   s)    		>$++>>!%**r   )r*   r+   r,   __doc__r   r^   ro   rt   rQ   rE   r    classmethodrh   r   propertyr:   r   rJ   rK   s   @r   rM   rM   :   s_    RB999 & &$9 # #+r   rM   c                   h    e Zd Zd Zedej                  fd       Zed        Ze	d        Z
d Zd Zy)	NamespaceReaderc                 v    dt        |      vrt        d      t        t        | j                  |       | _        y )NNamespacePathzInvalid path)r   r}   rM   rV   _resolver   )r   namespace_paths     r   r   zNamespaceReader.__init__   s1    #n"55^,,#S%GH	r   returnc                 :    d | j                  |      D        \  }|S )a'  
        Given an item from a namespace path, resolve it to a Traversable.

        path_str might be a directory on the filesystem or a path to a
        zipfile plus the path within the zipfile, e.g. ``/foo/bar`` or
        ``/foo/baz.zip/inner_dir`` or ``foo\baz.zip\inner_dir\sub``.
        c              3   B   K   | ]  }|j                         s|  y wr	   rP   )rS   cands     r   rT   z+NamespaceReader._resolve.<locals>.<genexpr>   s     S4T[[]$Ss   )_candidate_paths)r   path_strdirs      r   r   zNamespaceReader._resolve   s!     T3#7#7#AS
r   c              #   p   K   t        j                  |       | j                  |      E d {    y 7 wr	   )r   r   _resolve_zip_path)r   r   s     r   r   z NamespaceReader._candidate_paths   s)     ll8$$((222s   ,646c              #   ~  K   t        t        t        j                  d|                   D ]  }t	        j
                  t        t        t              5  | |j                         d  j                  dd      dz   }t        | d |j                          |j                  d             d d d         y # 1 sw Y   xY ww)Nz[\\/]r2   r3   )reversedrU   refinditer
contextlibsuppressr@   IsADirectoryErrorPermissionErrorendr6   r   startlstrip)r   matchinners      r   r   z!NamespaceReader._resolve_zip_path   s     d2;;x#BCD 	LE$$!#4o L !/77cBSHh7c9JKK	L L	LL Ls   AB=AB1&B=1B:	6B=c                 J    t        | j                  j                  |            S r   r   r!   s     r   r#   zNamespaceReader.resource_path   r$   r   c                     | j                   S r	   r&   r'   s    r   r(   zNamespaceReader.files   r)   r   N)r*   r+   r,   r   r   r   Traversabler   r   staticmethodr   r#   r(   r-   r   r   r   r      s[    I
 	3?? 	 	 3 3 L L1r   r   )r   r   re   r   rc   r    r   
_itertoolsr   _compatr   r   r   TraversableResourcesr   r/   r   rM   r   r-   r   r   <module>r      sn         	   09))  2(( 20F+coo F+R)c.. )r   