U
    -º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   s   | j S ©N)Úloader©Úspec© r   úW/tmp/pip-unpacked-wheel-izj_87as/pkg_resources/_vendor/importlib_resources/_adapters.pyÚ<lambda>   ó    zSpecLoaderAdapter.<lambda>c                 C   s   || _ ||ƒ| _d S r   )r
   r   )Úselfr
   Úadapterr   r   r   Ú__init__   s    zSpecLoaderAdapter.__init__c                 C   s   t | j|ƒS r   )Úgetattrr
   ©r   Únamer   r   r   Ú__getattr__   s    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   s
   || _ d S r   r	   ©r   r
   r   r   r   r      s    z#TraversableResourcesLoader.__init__c                 C   s   t | jƒ ¡ S r   )ÚCompatibilityFilesr
   Ú_nativer   r   r   r   Úget_resource_reader   s    z.TraversableResourcesLoader.get_resource_readerN)r   r   r   r   r   r   r   r   r   r   r      s   r   Úrc                 O   s6   |dkrt | f|ž|ŽS |dkr$| S td |¡ƒ‚d S )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                   @   sJ   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   s   || _ || _d S r   )Ú_specÚ_reader)r   r
   Úreaderr   r   r   r   6   s    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   Ú	ChildPathr)   )Ú.0Úpath©r   r   r   Ú	<genexpr>=   s   ÿz6CompatibilityFiles.SpecPath.iterdir.<locals>.<genexpr>)r)   ÚiterÚcontentsr.   r   r.   r   Úiterdir:   s
    þz#CompatibilityFiles.SpecPath.iterdirc                 C   s   dS ©NFr   r.   r   r   r   Úis_fileB   s    z#CompatibilityFiles.SpecPath.is_filec                 C   s   | j st |¡S t | j |¡S r   )r)   r   Ú
OrphanPathr+   ©r   Úotherr   r   r   ÚjoinpathG   s    
z$CompatibilityFiles.SpecPath.joinpathc                 C   s   | j jS r   )r(   r   r.   r   r   r   r   L   s    z CompatibilityFiles.SpecPath.namer   c                 O   s   t | j d ¡|f|ž|ŽS r   )r'   r)   Úopen_resource©r   r$   r%   r&   r   r   r   ÚopenP   s    z CompatibilityFiles.SpecPath.openN)r   ©r   r   r   r   r   r2   r4   Úis_dirr8   Úpropertyr   r;   r   r   r   r   ÚSpecPath0   s   
r?   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   s   || _ || _d S r   )r)   Ú_name)r   r*   r   r   r   r   r   Y   s    z%CompatibilityFiles.ChildPath.__init__c                 C   s   t dƒS ©Nr   ©r0   r.   r   r   r   r2   ]   s    z$CompatibilityFiles.ChildPath.iterdirc                 C   s   | j  | j¡S r   )r)   Úis_resourcer   r.   r   r   r   r4   `   s    z$CompatibilityFiles.ChildPath.is_filec                 C   s
   |   ¡  S r   )r4   r.   r   r   r   r=   c   s    z#CompatibilityFiles.ChildPath.is_dirc                 C   s   t  | j|¡S r   )r   r5   r   r6   r   r   r   r8   f   s    z%CompatibilityFiles.ChildPath.joinpathc                 C   s   | j S r   )r@   r.   r   r   r   r   i   s    z!CompatibilityFiles.ChildPath.namer   c                 O   s   t | j | j¡|f|ž|ŽS r   )r'   r)   r9   r   r:   r   r   r   r;   m   s     ÿÿÿz!CompatibilityFiles.ChildPath.openN)r   r<   r   r   r   r   r+   S   s   
r+   c                   @   sJ   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.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   s   t dƒS rA   rB   r.   r   r   r   r2   }   s    z%CompatibilityFiles.OrphanPath.iterdirc                 C   s   dS r3   r   r.   r   r   r   r4   €   s    z%CompatibilityFiles.OrphanPath.is_filec                 C   s   t j| j|fžŽ S r   )r   r5   rE   r6   r   r   r   r8   …   s    z&CompatibilityFiles.OrphanPath.joinpathc                 C   s
   | j d S )Néÿÿÿÿ)rE   r.   r   r   r   r   ˆ   s    z"CompatibilityFiles.OrphanPath.namer   c                 O   s   t dƒ‚d S )NzCan't open orphan path)ÚFileNotFoundErrorr:   r   r   r   r;   Œ   s    z"CompatibilityFiles.OrphanPath.openN)r   r<   r   r   r   r   r5   r   s   
r5   c                 C   s
   || _ d S r   r	   r   r   r   r   r      s    zCompatibilityFiles.__init__c              
   C   s2   t tƒ  | jj | jj¡W  5 Q R £ S Q R X d S r   )r   ÚAttributeErrorr
   r   r   r   r.   r   r   r   r)   ’   s    
zCompatibilityFiles._readerc                 C   s   | j }t|dƒr|S | S )zB
        Return the native reader if it supports files().
        Úfiles)r)   Úhasattr)r   r*   r   r   r   r   —   s    zCompatibilityFiles._nativec                 C   s   t | j|ƒS r   )r   r)   )r   Úattrr   r   r   r   ž   s    zCompatibilityFiles.__getattr__c                 C   s   t  | j| j¡S r   )r   r?   r
   r)   r.   r   r   r   rJ   ¡   s    zCompatibilityFiles.filesN)r   r   r   r   r   ZTraversabler?   r+   r5   r   r>   r)   r   r   rJ   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    rO   N)r   )Ú
contextlibr   Úior   Ú r   r   r   r'   r   rO   r   r   r   r   Ú<module>   s   

{