a
    xd                     @   s   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 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S )    N   )abc)only)ZipPathc                 C   s   t tj| S N)itercollectionsOrderedDictfromkeys)items r   S/var/www/html/Ranjet/env/lib/python3.9/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   s4   | d\}}}|jdd| d | _|j| _d S )N.\/)
rpartitionprefixreplacearchive)r   r   module_namer   r   r   r   !   s    zZipReader.__init__c              
      sF   zt  |W S  ty@ } zt|jd W Y d }~n
d }~0 0 d S Nr   )superopen_resourceKeyErrorFileNotFoundErrorargs)r   r   exc	__class__r   r   r2   &   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_resource,   s    zZipReader.is_resourcec                 C   s   t | j| jS r   )r   r,   r*   r   r   r   r   r    4   s    zZipReader.files)r"   r#   r$   r   r2   r<   r    __classcell__r   r   r7   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   sH   t ttjt|| _| js(d}t|tdd | jD sDt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>E       z+MultiplexedPath.__init__.<locals>.<genexpr>z)MultiplexedPath only supports directories)	listmapr   r   r   _pathsr4   allNotADirectoryError)r   pathsmessager   r   r   r   @   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)rA   r   childr   r   r   rB   I   rC   z*MultiplexedPath.iterdir.<locals>.<genexpr>r/   )keyc                 s   s   | ]\}}|V  qd S r   r   )rA   r/   Zlocsr   r   r   rB   L   rC   )rF   operator
attrgetter	itertoolsgroupbysortedrE   _follow)r   childrenZby_namegroupsr   r   r   rK   H   s    
zMultiplexedPath.iterdirc                 C   s   t |  dd S Nz is not a filer4   r   r   r   r   
read_bytesN   s    zMultiplexedPath.read_bytesc                 O   s   t |  dd S rV   rW   r   r5   kwargsr   r   r   	read_textQ   s    zMultiplexedPath.read_textc                 C   s   dS )NTr   r   r   r   r   r?   T   s    zMultiplexedPath.is_dirc                 C   s   dS )NFr   r   r   r   r   r9   W   s    zMultiplexedPath.is_filec                    s8   zt  j| W S  tjy2   | jd j|  Y S 0 d S r0   )r1   r   r   ZTraversalErrorrF   )r   Zdescendantsr7   r   r   r   Z   s    zMultiplexedPath.joinpathc                 C   sb   t |d\}}}z
t|W S  ty\   z| | W  Y S  tyV   t| Y  Y S 0 Y n0 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)rP   teer   
ValueErrorrH   next)clsrT   subdirsZone_dirZone_filer   r   r   rS   b   s    	
zMultiplexedPath._followc                 O   s   t |  dd S rV   rW   rY   r   r   r   openu   s    zMultiplexedPath.openc                 C   s   | j d jS r0   )rF   r/   r   r   r   r   r/   x   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   r@   r   r   r   rB   }   rC   z+MultiplexedPath.__repr__.<locals>.<genexpr>zMultiplexedPath())joinrF   )r   rI   r   r   r   __repr__|   s    zMultiplexedPath.__repr__)r"   r#   r$   __doc__r   rK   rX   r[   r?   r9   r   classmethodrS   rb   propertyr/   rf   r=   r   r   r7   r   r>   8   s   

r>   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )NamespaceReaderc                 C   s&   dt |vrtdtt| | _d S )NZNamespacePathzInvalid path)r   r^   r>   rD   r   )r   namespace_pathr   r   r   r      s    zNamespaceReader.__init__c                 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.filesNr!   r   r   r   r   rj      s   rj   )r   rP   r   rN    r   
_itertoolsr   _compatr   r   TraversableResourcesr   r%   Traversabler>   rj   r   r   r   r   <module>   s   I