o
    0ήc                     @   sd   d dl mZ d dlmZ ddlmZ G dd dZG dd dZdd
dZG dd dZ	dd Z
dS )    )suppress)TextIOWrapper   )abcc                   @   s(   e Zd ZdZdd fddZdd ZdS )	SpecLoaderAdapterz>
    Adapt a package spec to adapt the underlying loader.
    c                 C      | j S N)loaderspec r   Z/tmp/pip-target-vg8gfxp4/lib/python/pkg_resources/_vendor/importlib_resources/_adapters.py<lambda>   s    zSpecLoaderAdapter.<lambda>c                 C   s   || _ ||| _d S r   )r   r	   )selfr   adapterr   r   r   __init__   s   zSpecLoaderAdapter.__init__c                 C      t | j|S r   )getattrr   r   namer   r   r   __getattr__      zSpecLoaderAdapter.__getattr__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )TraversableResourcesLoaderz9
    Adapt a loader to provide TraversableResources.
    c                 C   
   || _ d S r   r
   r   r   r   r   r   r         
z#TraversableResourcesLoader.__init__c                 C   s   t | j S r   )CompatibilityFilesr   _nativer   r   r   r   get_resource_reader      z.TraversableResourcesLoader.get_resource_readerN)r   r   r   r   r   r"   r   r   r   r   r      s    r   rc                 O   s8   |dkrt | g|R i |S |dkr| S td|)Nr$   rbz8Invalid mode value '{}', only 'r' and 'rb' are supported)r   
ValueErrorformat)filemodeargskwargsr   r   r   _io_wrapper    s   r,   c                   @   sr   e Zd Zd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	e
d
d Zdd Zdd Zdd ZdS )r    zj
    Adapter for an existing or non-existent resource reader
    to provide a compatibility .files().
    c                   @   J   e Zd ZdZdd Zdd Zdd ZeZdd	 Ze	d
d Z
dddZdS )zCompatibilityFiles.SpecPathzk
        Path tied to a module spec.
        Can be read and exposes the resource reader children.
        c                 C      || _ || _d S r   )_spec_reader)r   r   readerr   r   r   r   6      
z$CompatibilityFiles.SpecPath.__init__c                    s*    j stdS t fdd j  D S )Nr   c                 3   s    | ]
}t  j|V  qd S r   )r    	ChildPathr0   ).0pathr   r   r   	<genexpr>=   s
    
z6CompatibilityFiles.SpecPath.iterdir.<locals>.<genexpr>)r0   itercontentsr6   r   r6   r   iterdir:   s
   z#CompatibilityFiles.SpecPath.iterdirc                 C      dS NFr   r6   r   r   r   is_fileB      z#CompatibilityFiles.SpecPath.is_filec                 C   s   | j st|S t| j |S r   )r0   r    
OrphanPathr3   r   otherr   r   r   joinpathG   s   
z$CompatibilityFiles.SpecPath.joinpathc                 C   s   | j jS r   )r/   r   r6   r   r   r   r   L   s   z CompatibilityFiles.SpecPath.namer$   c                 O   s    t | jd |g|R i |S r   )r,   r0   open_resourcer   r)   r*   r+   r   r   r   openP   s    z CompatibilityFiles.SpecPath.openNr$   r   r   r   r   r   r:   r=   is_dirrB   propertyr   rE   r   r   r   r   SpecPath0   s    
rJ   c                   @   sN   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dddZdS )zCompatibilityFiles.ChildPathzw
        Path tied to a resource reader child.
        Can be read but doesn't expose any meaningful children.
        c                 C   r.   r   )r0   _name)r   r1   r   r   r   r   r   Y   r2   z%CompatibilityFiles.ChildPath.__init__c                 C      t dS Nr   r8   r6   r   r   r   r:   ]      z$CompatibilityFiles.ChildPath.iterdirc                 C   s   | j | jS r   )r0   is_resourcer   r6   r   r   r   r=   `   r#   z$CompatibilityFiles.ChildPath.is_filec                 C   s
   |    S r   )r=   r6   r   r   r   rH   c   r   z#CompatibilityFiles.ChildPath.is_dirc                 C   s   t | j|S r   )r    r?   r   r@   r   r   r   rB   f   r#   z%CompatibilityFiles.ChildPath.joinpathc                 C   r   r   )rK   r6   r   r   r   r   i   s   z!CompatibilityFiles.ChildPath.namer$   c                 O   s"   t | j| j|g|R i |S r   )r,   r0   rC   r   rD   r   r   r   rE   m   s   z!CompatibilityFiles.ChildPath.openNrF   rG   r   r   r   r   r3   S   s    
r3   c                   @   r-   )zCompatibilityFiles.OrphanPathz
        Orphan path, not tied to a module spec or resource reader.
        Can't be read and doesn't expose any meaningful children.
        c                 G   s   t |dk r
td|| _d S )Nr   z/Need at least one path part to construct a path)lenr&   _path)r   
path_partsr   r   r   r   x   s   
z&CompatibilityFiles.OrphanPath.__init__c                 C   rL   rM   rN   r6   r   r   r   r:   }   rO   z%CompatibilityFiles.OrphanPath.iterdirc                 C   r;   r<   r   r6   r   r   r   r=      r>   z%CompatibilityFiles.OrphanPath.is_filec                 C   s   t jg | j|R  S r   )r    r?   rR   r@   r   r   r   rB      s   z&CompatibilityFiles.OrphanPath.joinpathc                 C   s
   | j d S )N)rR   r6   r   r   r   r      s   
z"CompatibilityFiles.OrphanPath.namer$   c                 O   s   t d)NzCan't open orphan path)FileNotFoundErrorrD   r   r   r   rE      rO   z"CompatibilityFiles.OrphanPath.openNrF   rG   r   r   r   r   r?   r   s    
r?   c                 C   r   r   r
   r   r   r   r   r      r   zCompatibilityFiles.__init__c                 C   s>   t t | jj| jjW  d    S 1 sw   Y  d S r   )r   AttributeErrorr   r	   r"   r   r6   r   r   r   r0      s   
$zCompatibilityFiles._readerc                 C   s   | j }t|dr
|S | S )zB
        Return the native reader if it supports files().
        files)r0   hasattr)r   r1   r   r   r   r!      s   zCompatibilityFiles._nativec                 C   r   r   )r   r0   )r   attrr   r   r   r      r   zCompatibilityFiles.__getattr__c                 C   s   t | j| jS r   )r    rJ   r   r0   r6   r   r   r   rW      s   zCompatibilityFiles.filesN)r   r   r   r   r   TraversablerJ   r3   r?   r   rI   r0   r!   r   rW   r   r   r   r   r    *   s    #
r    c                 C   s   t | jtS )z`
    Construct a package spec with traversable compatibility
    on the spec/loader/reader.
    )r   __spec__r   )packager   r   r   	wrap_spec   s   r]   NrF   )
contextlibr   ior    r   r   r   r,   r    r]   r   r   r   r   <module>   s    

{