
    Ύij                       d dl mZ 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Zd dl	m
Z
 ddlmZ ddlmZ ddl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d ZdS )    )annotationsN)Iterator   )abc)only)ZipPathc                Z    t          t          j                            |                     S N)itercollectionsOrderedDictfromkeys)itemss    N/var/www/icac/venv/lib/python3.11/site-packages/importlib_resources/readers.pyremove_duplicatesr      s!    '0077888    c                       e Zd Zd Zd Zd ZdS )
FileReaderc                L    t          j        |j                  j        | _        d S r
   )pathlibPathpathparent)selfloaders     r   __init__zFileReader.__init__   s    L--4			r   c                P    t          | 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   "     49%%h//000r   c                    | j         S r
   r   r   s    r   fileszFileReader.files!   
    yr   N)__name__
__module____qualname__r   r$   r)    r   r   r   r      sA        5 5 51 1 1    r   r   c                  0     e Zd Zd Z fdZd Zd Z xZS )	ZipReaderc                    |j                             dd          | _         |                    |          r,|                    d          \  }}}| xj         |dz   z  c_         |j        | _        d S )N\/.)prefixreplace
is_package
rpartitionarchive)r   r   module_names        r   r   zZipReader.__init__&   sk    m++D#66V$$ 	&**3//JAq$KK4#:%KK~r   c                    	 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-   sS    	177((222 	1 	1 	1#CHQK000	1s    $ 
AAAc                    |                                                      |          }|                                o|                                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_resource3   s<    
 &&t,,~~3FMMOO3r   c                6    t          | j        | j                  S r
   )r   r9   r5   r(   s    r   r)   zZipReader.files;   s    t|T[111r   )r+   r,   r-   r   r@   rJ   r)   __classcell__rE   s   @r   r0   r0   %   se        & & &1 1 1 1 14 4 42 2 2 2 2 2 2r   r0   c                  ~     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          d S )Nz.MultiplexedPath must contain at least one pathc              3  >   K   | ]}|                                 V  d S r
   is_dir.0r   s     r   	<genexpr>z+MultiplexedPath.__init__.<locals>.<genexpr>L   s*      99T4;;==999999r   z)MultiplexedPath only supports directories)listmap_ensure_traversabler   _pathsrB   allNotADirectoryError)r   pathsmessages      r   r   zMultiplexedPath.__init__G   s    324Ee4L4LMMNN{ 	-FG#G,,,99T[99999 	R$%PQQQ	R 	Rr   c                    d | j         D             }t          j        d          }t          j        t          ||          |          }t          | j        d |D                       S )Nc              3  H   K   | ]}|                                 D ]}|V  d S r
   )iterdir)rU   r   childs      r   rV   z*MultiplexedPath.iterdir.<locals>.<genexpr>P   s7      NNdt||~~NNeENNNNNNNr   r<   )keyc              3      K   | ]	\  }}|V  
d S r
   r.   )rU   r<   locss      r   rV   z*MultiplexedPath.iterdir.<locals>.<genexpr>S   s&      !@!@:4$!@!@!@!@!@!@r   )rZ   operator
attrgetter	itertoolsgroupbysortedrX   _follow)r   childrenby_namegroupss       r   ra   zMultiplexedPath.iterdirO   sj    NNdkNNN%f--"6(#@#@#@gNNN4<!@!@!@!@!@AAAr   c                &    t          |  d          Nz is not a filerB   r(   s    r   
read_byteszMultiplexedPath.read_bytesU       4 7 7 7888r   c                &    t          |  d          rp   rq   r   rC   kwargss      r   	read_textzMultiplexedPath.read_textX   rs   r   c                    dS )NTr.   r(   s    r   rS   zMultiplexedPath.is_dir[   s    tr   c                    dS )NFr.   r(   s    r   rG   zMultiplexedPath.is_file^   s    ur   c                    	  t                      j        | S # t          j        $ r  | j        d         j        | cY S w xY wr>   )r?   r!   r   TraversalErrorrZ   )r   descendantsrE   s     r   r!   zMultiplexedPath.joinpatha   sX    	9#577#[11! 	9 	9 	9 +4;q>*K88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.
           )rh   teer   
ValueErrorr\   next)clsrl   subdirsone_dirone_files        r   rk   zMultiplexedPath._followi   s     &/]8Q%?%?"(	&==  	& 	& 	&&sG}$$$% & & &H~~%%%%%&	&s)   * 
A<AAAAAc                &    t          |  d          rp   rq   ru   s      r   openzMultiplexedPath.open|   rs   r   c                &    | j         d         j        S r>   )rZ   r<   r(   s    r   r<   zMultiplexedPath.name   s    {1~""r   c                V    d                     d | j        D                       }d| dS )Nz, c              3  "   K   | ]
}d | d V  dS )'Nr.   rT   s     r   rV   z+MultiplexedPath.__repr__.<locals>.<genexpr>   s*      >>$+d+++>>>>>>r   zMultiplexedPath())joinrZ   )r   r]   s     r   __repr__zMultiplexedPath.__repr__   s5    		>>$+>>>>>*%****r   )r+   r,   r-   __doc__r   ra   rr   rw   rS   rG   r!   classmethodrk   r   propertyr<   r   rL   rM   s   @r   rO   rO   ?   s         R R RB B B9 9 99 9 9    9 9 9 9 9 & & [&$9 9 9 # # X#+ + + + + + +r   rO   c                  h    e Zd Zd Zedd            Zedd            Zedd	            Zd
 Z	d Z
dS )NamespaceReaderc           	         dt          |          vrt          d          t          t          t          t          | j        |                     | _        d S )NNamespacePathzInvalid path)r    r   rO   filterboolrX   _resolver   )r   namespace_paths     r   r   zNamespaceReader.__init__   sI    #n"5"555^,,,#VD#dm^2T2T%U%UV			r   returnabc.Traversable | Nonec                `    d |                      |          D             }t          |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``.

        path_str might also be a sentinel used by editable packages to
        trigger other behaviors (see python/importlib_resources#311).
        In that case, return None.
        c              3  B   K   | ]}|                                 |V  d S r
   rR   )rU   cands     r   rV   z+NamespaceReader._resolve.<locals>.<genexpr>   s/      QQ4;;==QQQQQQQr   N)_candidate_pathsr   )r   path_strdirss      r   r   zNamespaceReader._resolve   s6     RQ!5!5h!?!?QQQD$r   r   r    Iterator[abc.Traversable]c              #  l   K   t          j        |          V  |                     |          E d {V  d S r
   )r   r   _resolve_zip_path)r   r   s     r   r   z NamespaceReader._candidate_paths   sH      l8$$$$$((22222222222r   c              #    K   t          t          t          j        d|                               D ]}t	          j        t          t          t          t                    5  | |
                                d                              dd          dz   }t          | d |                                         |                    d                    V  d d d            n# 1 swxY w Y   d S )Nz[\\/]r2   r3   )reversedrW   refinditer
contextlibsuppressrB   IsADirectoryErrorr\   PermissionErrorendr6   r   startlstrip)r   matchinners      r   r   z!NamespaceReader._resolve_zip_path   s%     d2;x#B#BCCDD 	L 	LE$!!"	  L L !/77cBBSHh7c9J9JKKKKKL L L L L L L L L L L L L L L	L 	Ls   A3CC"	%C"	c                P    t          | 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   )r   r    )r+   r,   r-   r   r   r   r   staticmethodr   r$   r)   r.   r   r   r   r      s        W W W
       [  3 3 3 [3 	L 	L 	L \	L1 1 1    r   r   c                    t          | t                    s| S t          j        dt          d           t          j        |           S )zk
    Convert deprecated string arguments to traversables (pathlib.Path).

    Remove with Python 3.15.
    z<String arguments are deprecated. Pass a Traversable instead.r~   )
stacklevel)
isinstancer    warningswarnDeprecationWarningr   r   r'   s    r   rY   rY      sO     dC   MF    <r   )
__future__r   r   r   rh   rf   r   r   r   collections.abcr    r   
_itertoolsr   compat.py39r   r   TraversableResourcesr   r0   TraversablerO   r   rY   r.   r   r   <module>r      s   " " " " " "               				  $ $ $ $ $ $                        9 9 9    )    2 2 2 2 2( 2 2 24F+ F+ F+ F+ F+co F+ F+ F+R0 0 0 0 0c. 0 0 0f    r   