U
    ^»{jk  ã                   @  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   úZ/var/www/html/bwave/python/venv/lib/python3.8/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  s   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   s    zFileReader.resource_pathc                 C  s   | j S r   ©r   ©r   r   r   r   Úfiles"   s    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              
     sD   zt ƒ  |¡W S  tk
r> } zt|jd ƒ‚W 5 d }~X Y nX d S ©Nr   )ÚsuperÚopen_resourceÚKeyErrorÚFileNotFoundErrorÚargs)r   r   Úexc©Ú	__class__r   r   r4   .   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_resource4   s    zZipReader.is_resourcec                 C  s   t | j| jƒS r   )r   r.   r*   r!   r   r   r   r"   <   s    zZipReader.files)r#   r$   r%   r   r4   r>   r"   Ú__classcell__r   r   r9   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 ƒƒsBt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>M   s     z+MultiplexedPath.__init__.<locals>.<genexpr>z)MultiplexedPath only supports directories)ÚlistÚmapÚ_ensure_traversabler   Ú_pathsr6   ÚallÚNotADirectoryError)r   ÚpathsÚmessager   r   r   r   H   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)rD   r   Úchildr   r   r   rE   Q   s     
  z*MultiplexedPath.iterdir.<locals>.<genexpr>r1   )Úkeyc                 s  s   | ]\}}|V  qd S r   r   )rD   r1   Zlocsr   r   r   rE   T   s     )rI   ÚoperatorÚ
attrgetterÚ	itertoolsÚgroupbyÚsortedrG   Ú_follow)r   ÚchildrenZby_nameÚgroupsr   r   r   rN   P   s    
zMultiplexedPath.iterdirc                 C  s   t | › d�ƒ‚d S ©Nz is not a file©r6   r!   r   r   r   Ú
read_bytesV   s    zMultiplexedPath.read_bytesc                 O  s   t | › d�ƒ‚d S rY   rZ   ©r   r7   Úkwargsr   r   r   Ú	read_textY   s    zMultiplexedPath.read_textc                 C  s   dS )NTr   r!   r   r   r   rB   \   s    zMultiplexedPath.is_dirc                 C  s   dS )NFr   r!   r   r   r   r;   _   s    zMultiplexedPath.is_filec                   s:   zt ƒ j|Ž W S  tjk
r4   | jd j|Ž  Y S X d S r2   )r3   r   r   ZTraversalErrorrI   )r   Zdescendantsr9   r   r   r   b   s    zMultiplexedPath.joinpathc                 C  sf   t  |d¡\}}}z
t|ƒW S  tk
r`   z| |Ž W  Y S  tk
rZ   t|ƒ Y  Y S X Y nX dS )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.
        é   N)rS   Úteer   Ú
ValueErrorrK   Únext)ÚclsrW   ÚsubdirsZone_dirZone_filer   r   r   rV   j   s    	
zMultiplexedPath._followc                 O  s   t | › d�ƒ‚d S rY   rZ   r\   r   r   r   Úopen}   s    zMultiplexedPath.openc                 C  s   | j d jS r2   )rI   r1   r!   r   r   r   r1   €   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   rC   r   r   r   rE   …   s     z+MultiplexedPath.__repr__.<locals>.<genexpr>zMultiplexedPath(ú))ÚjoinrI   )r   rL   r   r   r   Ú__repr__„   s    zMultiplexedPath.__repr__)r#   r$   r%   Ú__doc__r   rN   r[   r^   rB   r;   r   ÚclassmethodrV   re   Úpropertyr1   ri   r?   r   r   r9   r   r@   @   s   

r@   c                   @  s\   e Zd Zdd„ Zeddœdd„ƒZeddd	œd
d„ƒZeddœdd„ƒZdd„ Z	dd„ Z
dS )ÚNamespaceReaderc                 C  s0   dt |ƒkrtdƒ‚tttt| j|ƒƒŽ | _d S )NZNamespacePathzInvalid path)r   ra   r@   ÚfilterÚboolrG   Ú_resolver   )r   Únamespace_pathr   r   r   r   Š   s    zNamespaceReader.__init__zabc.Traversable | None)Úreturnc                 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   rA   )rD   Úcandr   r   r   rE   œ   s      z+NamespaceReader._resolve.<locals>.<genexpr>N)Ú_candidate_pathsrb   )rc   Úpath_strÚdirsr   r   r   rp   �   s    zNamespaceReader._resolver   zIterator[abc.Traversable])ru   rr   c                 c  s    t  |¡V  |  |¡E d H  d S r   )r   r   Ú_resolve_zip_path)rc   ru   r   r   r   rt   Ÿ   s    z NamespaceReader._candidate_paths)ru   c              
   c  st   t tt d| ¡ƒƒD ]Z}t tttt	¡�@ | | 
¡ d …  dd¡d }t| d | ¡ … | d¡ƒV  W 5 Q R X qd S )Nz[\\/]r'   r(   )ÚreversedrF   ÚreÚfinditerÚ
contextlibÚsuppressr6   ÚIsADirectoryErrorrK   ÚPermissionErrorÚendr+   r   ÚstartÚlstrip)ru   ÚmatchÚinnerr   r   r   rw   ¤   s    üz!NamespaceReader._resolve_zip_pathc                 C  s   t | j |¡ƒS r   r   r   r   r   r   r   °   s    zNamespaceReader.resource_pathc                 C  s   | j S r   r    r!   r   r   r   r"   ¸   s    zNamespaceReader.filesN)r#   r$   r%   r   rk   rp   rt   Ústaticmethodrw   r   r"   r   r   r   r   rm   ‰   s   rm   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.r_   )Ú
stacklevel)Ú
isinstancer   ÚwarningsÚwarnÚDeprecationWarningr   r   r    r   r   r   rH   ¼   s    
ýrH   )Ú
__future__r   r
   r{   rS   r   rQ   ry   r‡   Úcollections.abcr   Ú r   Ú
_itertoolsr   Zcompat.py39r   r   ZTraversableResourcesr   r&   ZTraversabler@   rm   rH   r   r   r   r   Ú<module>   s"   I3