o
    Fôjj  ã                   @  sÐ   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d	„ ZG d
d„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZdd„ ZdS )é    )ÚannotationsN)ÚIteratoré   )Úabc)Úonly)ÚZipPathc                 C  s   t tj | ¡ƒS ©N)ÚiterÚcollectionsÚOrderedDictÚfromkeys)Úitems© r   úl/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/importlib_resources/readers.pyÚremove_duplicates   s   r   c                   @  s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú
FileReaderc                 C  s   t  |j¡j| _d S r   )ÚpathlibÚPathÚpathÚparent)ÚselfÚloaderr   r   r   Ú__init__   s   zFileReader.__init__c                 C  ó   t | j |¡ƒS ©z{
        Return the file system path to prevent
        `resources.path()` from creating a temporary
        copy.
        ©Ústrr   Újoinpath©r   Úresourcer   r   r   Úresource_path   ó   zFileReader.resource_pathc                 C  ó   | j S r   ©r   ©r   r   r   r   Úfiles!   ó   zFileReader.filesN)Ú__name__Ú
__module__Ú__qualname__r   r    r%   r   r   r   r   r      s    r   c                      s4   e Zd Zdd„ Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )	Ú	ZipReaderc                 C  sH   |j  dd¡| _ | |¡r| d¡\}}}|  j |d 7  _ |j| _d S )Nú\ú/Ú.)ÚprefixÚreplaceÚ
is_packageÚ
rpartitionÚarchive)r   r   ÚmoduleÚ_Únamer   r   r   r   &   s
   
zZipReader.__init__c              
     s6   zt ƒ  |¡W S  ty } zt|jd ƒ‚d }~ww ©Nr   )ÚsuperÚopen_resourceÚKeyErrorÚFileNotFoundErrorÚargs)r   r   Úexc©Ú	__class__r   r   r8   -   s   €ÿzZipReader.open_resourcec                 C  s   |   ¡  |¡}| ¡ o| ¡ S )zf
        Workaround for `zipfile.Path.is_file` returning true
        for non-existent paths.
        )r%   r   Úis_fileÚexists)r   r   Útargetr   r   r   Úis_resource3   s   zZipReader.is_resourcec                 C  s   t | j| jƒS r   )r   r2   r.   r$   r   r   r   r%   ;   ó   zZipReader.files)r'   r(   r)   r   r8   rB   r%   Ú__classcell__r   r   r=   r   r*   %   s
    r*   c                      sx   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	‡ fdd„Z
edd„ ƒZdd„ Zedd„ ƒZdd„ Z‡  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                 G  sF   t ttt|ƒƒƒ| _| jsd}t|ƒ‚tdd„ | jD ƒƒs!tdƒ‚d S )Nz.MultiplexedPath must contain at least one pathc                 s  s   � | ]}|  ¡ V  qd S r   ©Úis_dir©Ú.0r   r   r   r   Ú	<genexpr>L   ó   € z+MultiplexedPath.__init__.<locals>.<genexpr>z)MultiplexedPath only supports directories)ÚlistÚmapÚ_ensure_traversabler   Ú_pathsr:   ÚallÚNotADirectoryError)r   ÚpathsÚmessager   r   r   r   G   s   ÿzMultiplexedPath.__init__c                 C  sF   dd„ | j D ƒ}t d¡}tjt||d�|d�}t| jdd„ |D ƒƒS )Nc                 s  s"   � | ]}|  ¡ D ]}|V  qqd S r   )Úiterdir)rI   r   Úchildr   r   r   rJ   P   s   €  z*MultiplexedPath.iterdir.<locals>.<genexpr>r5   )Úkeyc                 s  s   � | ]\}}|V  qd S r   r   )rI   r5   Zlocsr   r   r   rJ   S   rK   )rO   ÚoperatorÚ
attrgetterÚ	itertoolsÚgroupbyÚsortedrM   Ú_follow)r   ÚchildrenZby_nameÚgroupsr   r   r   rT   O   s   
zMultiplexedPath.iterdirc                 C  ó   t | › d�ƒ‚©Nz is not a file©r:   r$   r   r   r   Ú
read_bytesU   rC   zMultiplexedPath.read_bytesc                 O  r_   r`   ra   ©r   r;   Úkwargsr   r   r   Ú	read_textX   rC   zMultiplexedPath.read_textc                 C  ó   dS )NTr   r$   r   r   r   rG   [   ó   zMultiplexedPath.is_dirc                 C  rf   )NFr   r$   r   r   r   r?   ^   rg   zMultiplexedPath.is_filec                   s4   zt ƒ j|Ž W S  tjy   | jd j|Ž  Y S w r6   )r7   r   r   ÚTraversalErrorrO   )r   Údescendantsr=   r   r   r   a   s
   ýzMultiplexedPath.joinpathc                 C  sZ   t  |d¡\}}}zt|ƒW S  ty,   z| |Ž W  Y S  ty+   t|ƒ Y  Y S w 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.
        é   )rY   Úteer   Ú
ValueErrorrQ   Únext)Úclsr]   ZsubdirsZone_dirZone_filer   r   r   r\   i   s   	
ÿýzMultiplexedPath._followc                 O  r_   r`   ra   rc   r   r   r   Úopen|   rC   zMultiplexedPath.openc                 C  s   | j d jS r6   )rO   r5   r$   r   r   r   r5      s   zMultiplexedPath.namec                 C  s"   d  dd„ | jD ƒ¡}d|› d�S )Nz, c                 s  s   � | ]	}d |› d �V  qdS )ú'Nr   rH   r   r   r   rJ   „   ó   € z+MultiplexedPath.__repr__.<locals>.<genexpr>zMultiplexedPath(ú))ÚjoinrO   )r   rR   r   r   r   Ú__repr__ƒ   s   zMultiplexedPath.__repr__)r'   r(   r)   Ú__doc__r   rT   rb   re   rG   r?   r   Úclassmethodr\   ro   Úpropertyr5   rt   rD   r   r   r=   r   rE   ?   s    

rE   c                   @  sN   e Zd Zdd„ Zeddd„ƒZedd
d„ƒZeddd„ƒZdd„ Z	dd„ Z
dS )ÚNamespaceReaderc                 C  s0   dt |ƒvr
tdƒ‚tttt| j|ƒƒŽ | _d S )NÚNamespacePathzInvalid path)r   rl   rE   ÚfilterÚboolrM   Ú_resolver   )r   Únamespace_pathr   r   r   r   ‰   s   zNamespaceReader.__init__Úreturnúabc.Traversable | Nonec                 C  s   d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                 s  s   � | ]	}|  ¡ r|V  qd S r   rF   )rI   Úcandr   r   r   rJ   ›   rq   z+NamespaceReader._resolve.<locals>.<genexpr>N)Ú_candidate_pathsrm   )rn   Úpath_strÚdirsr   r   r   r|   Ž   s   
zNamespaceReader._resolver‚   r   úIterator[abc.Traversable]c                 c  s"   � t  |¡V  |  |¡E d H  d S r   )r   r   Ú_resolve_zip_path)rn   r‚   r   r   r   r�   ž   s   €z NamespaceReader._candidate_pathsc              	   c  sŠ   � t tt d| ¡ƒƒD ]7}t tttt	¡�% | | 
¡ d …  dd¡d }t| d | ¡ … | d¡ƒV  W d   ƒ n1 s=w   Y  qd S )Nz[\\/]r+   r,   )ÚreversedrL   ÚreÚfinditerÚ
contextlibÚsuppressr:   ÚIsADirectoryErrorrQ   ÚPermissionErrorÚendr/   r   ÚstartÚlstrip)r‚   ÚmatchÚinnerr   r   r   r…   £   s   €ü ù€ÿz!NamespaceReader._resolve_zip_pathc                 C  r   r   r   r   r   r   r   r    ¯   r!   zNamespaceReader.resource_pathc                 C  r"   r   r#   r$   r   r   r   r%   ·   r&   zNamespaceReader.filesN)r~   r   )r‚   r   r~   r„   )r‚   r   )r'   r(   r)   r   rv   r|   r�   Ústaticmethodr…   r    r%   r   r   r   r   rx   ˆ   s    rx   c                 C  s(   t | tƒs| S tjdtdd� t | ¡S )zk
    Convert deprecated string arguments to traversables (pathlib.Path).

    Remove with Python 3.15.
    z<String arguments are deprecated. Pass a Traversable instead.rj   )Ú
stacklevel)Ú
isinstancer   ÚwarningsÚwarnÚDeprecationWarningr   r   r#   r   r   r   rN   »   s   
ý
rN   )Ú
__future__r   r
   r‰   rY   rW   r   r‡   r•   Úcollections.abcr   Ú r   Ú
_itertoolsr   Zcompat.py39r   r   ÚTraversableResourcesr   r*   ÚTraversablerE   rx   rN   r   r   r   r   Ú<module>   s$    I3